Fixed concurrent send/close bug in TCPServer

This commit is contained in:
Obique PSWG
2016-01-13 12:29:47 -06:00
parent ab67aaac39
commit 9b43d8f2e4
+12 -10
View File
@@ -129,17 +129,19 @@ public class TCPServer {
}
public boolean send(InetSocketAddress sock, byte [] data) {
SocketChannel sc = sockets.get(sock);
try {
if (sc != null && sc.isConnected()) {
ByteBuffer bb = ByteBuffer.wrap(data);
while (bb.hasRemaining())
sc.write(bb);
return true;
synchronized (sockets) {
SocketChannel sc = sockets.get(sock);
try {
if (sc != null && sc.isConnected()) {
ByteBuffer bb = ByteBuffer.wrap(data);
while (bb.hasRemaining())
sc.write(bb);
return true;
}
} catch (IOException e) {
e.printStackTrace();
disconnect(sc);
}
} catch (IOException e) {
e.printStackTrace();
disconnect(sc);
}
return false;
}