1 17 package org.alfresco.filesys.smb.server.win32; 18 19 import java.io.IOException ; 20 21 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 22 import org.alfresco.filesys.netbios.win32.NetBIOSSocket; 23 import org.alfresco.filesys.netbios.win32.WinsockError; 24 import org.alfresco.filesys.netbios.win32.WinsockNetBIOSException; 25 import org.alfresco.filesys.smb.server.PacketHandler; 26 import org.alfresco.filesys.smb.server.SMBSrvPacket; 27 28 36 public class WinsockNetBIOSPacketHandler extends PacketHandler 37 { 38 42 private static final int ReceiveBufferSizeError = 0x80000000; 43 44 46 private int m_lana; 47 48 50 private NetBIOSSocket m_sessSock; 51 52 58 public WinsockNetBIOSPacketHandler(int lana, NetBIOSSocket sock) 59 { 60 super(SMBSrvPacket.PROTOCOL_WIN32NETBIOS, "WinsockNB", "WSNB", sock.getName().getName()); 61 62 m_lana = lana; 63 m_sessSock = sock; 64 } 65 66 71 public final int getLANA() 72 { 73 return m_lana; 74 } 75 76 81 public final NetBIOSSocket getSocket() 82 { 83 return m_sessSock; 84 } 85 86 93 public int readPacket(SMBSrvPacket pkt) throws IOException 94 { 95 97 int rxlen = 0; 98 99 try { 100 101 103 rxlen = m_sessSock.read(pkt.getBuffer(), 4, pkt.getBufferLength() - 4); 104 105 108 if (rxlen == ReceiveBufferSizeError) 109 { 110 111 114 if (pkt.getBuffer().length < RFCNetBIOSProtocol.MaxPacketSize) 115 { 116 118 rxlen = pkt.getBufferLength() - 4; 119 120 122 byte[] newbuf = new byte[RFCNetBIOSProtocol.MaxPacketSize]; 123 System.arraycopy(pkt.getBuffer(), 4, newbuf, 4, rxlen); 124 pkt.setBuffer( newbuf); 125 126 128 int rxlen2 = m_sessSock.read(pkt.getBuffer(), rxlen + 4, pkt.getBufferLength() - (rxlen + 4)); 129 130 if ( rxlen2 == ReceiveBufferSizeError) 131 throw new WinsockNetBIOSException(WinsockError.WsaEMsgSize); 132 133 rxlen += rxlen2; 134 } 135 else 136 throw new WinsockNetBIOSException(WinsockError.WsaEMsgSize); 137 } 138 } 139 catch ( WinsockNetBIOSException ex) 140 { 141 143 if ( ex.getErrorCode() == WinsockError.WsaEConnReset) 144 { 145 147 rxlen = -1; 148 } 149 else 150 { 151 153 throw ex; 154 } 155 } 156 157 159 return rxlen; 160 } 161 162 169 public void writePacket(SMBSrvPacket pkt, int len) throws IOException 170 { 171 176 int txlen = m_sessSock.write(pkt.getBuffer(), 4, len); 177 178 } 180 181 184 public void closeHandler() 185 { 186 super.closeHandler(); 187 188 190 if ( m_sessSock != null) 191 m_sessSock.closeSocket(); 192 } 193 } 194 | Popular Tags |