1 17 package org.alfresco.filesys.smb.server; 18 19 import java.net.InetAddress ; 20 import java.net.Socket ; 21 import java.net.SocketException ; 22 23 import org.alfresco.filesys.server.config.ServerConfiguration; 24 import org.alfresco.filesys.smb.TcpipSMB; 25 26 29 public class TcpipSMBSessionSocketHandler extends SessionSocketHandler 30 { 31 32 40 public TcpipSMBSessionSocketHandler(SMBServer srv, int port, InetAddress bindAddr, boolean debug) 41 { 42 super("TCP-SMB", srv, port, bindAddr, debug); 43 } 44 45 48 public void run() 49 { 50 51 try 52 { 53 54 56 clearShutdown(); 57 58 60 while (hasShutdown() == false) 61 { 62 63 65 if (logger.isDebugEnabled() && hasDebug()) 66 logger.debug("[SMB] Waiting for TCP-SMB session request ..."); 67 68 70 Socket sessSock = getSocket().accept(); 71 72 74 if (logger.isDebugEnabled() && hasDebug()) 75 logger.debug("[SMB] TCP-SMB session request received from " 76 + sessSock.getInetAddress().getHostAddress()); 77 78 try 79 { 80 81 83 PacketHandler pktHandler = new TcpipSMBPacketHandler(sessSock); 84 85 87 SMBSrvSession srvSess = new SMBSrvSession(pktHandler, getServer()); 88 srvSess.setSessionId(getNextSessionId()); 89 srvSess.setUniqueId(pktHandler.getShortName() + srvSess.getSessionId()); 90 srvSess.setDebugPrefix("[" + pktHandler.getShortName() + srvSess.getSessionId() + "] "); 91 92 94 getServer().addSession(srvSess); 95 96 98 Thread srvThread = new Thread (srvSess); 99 srvThread.setDaemon(true); 100 srvThread.setName("Sess_T" + srvSess.getSessionId() + "_" 101 + sessSock.getInetAddress().getHostAddress()); 102 srvThread.start(); 103 } 104 catch (Exception ex) 105 { 106 107 109 logger.error("[SMB] TCP-SMB Failed to create session, ", ex); 110 } 111 } 112 } 113 catch (SocketException ex) 114 { 115 116 119 if (hasShutdown() == false) 120 logger.error("[SMB] TCP-SMB Socket error : ", ex); 121 } 122 catch (Exception ex) 123 { 124 125 128 if (hasShutdown() == false) 129 logger.error("[SMB] TCP-SMB Server error : ", ex); 130 } 131 132 134 if (logger.isDebugEnabled() && hasDebug()) 135 logger.debug("[SMB] TCP-SMB session handler closed"); 136 } 137 138 145 public final static void createSessionHandlers(SMBServer server, boolean sockDbg) throws Exception 146 { 147 148 150 ServerConfiguration config = server.getConfiguration(); 151 152 154 SessionSocketHandler sessHandler = new TcpipSMBSessionSocketHandler(server, TcpipSMB.PORT, config 155 .getSMBBindAddress(), sockDbg); 156 157 sessHandler.initialize(); 158 server.addSessionHandler(sessHandler); 159 160 162 Thread tcpThread = new Thread (sessHandler); 163 tcpThread.setName("TcpipSMB_Handler"); 164 tcpThread.start(); 165 166 168 if (logger.isDebugEnabled() && sockDbg) 169 logger.debug("[SMB] Native SMB TCP session handler created"); 170 } 171 } 172 | Popular Tags |