feature: add socket connection pool

dev
tanyawen 2019-12-28 00:08:45 +08:00
parent 145d80c6ac
commit 3c61ba0e7a
2 changed files with 16 additions and 8 deletions

View File

@ -86,12 +86,20 @@ public class TrackerServer {
if (ClientGlobal.g_connection_pool_enabled) { if (ClientGlobal.g_connection_pool_enabled) {
ConnectionPool.freeConnection(this); ConnectionPool.freeConnection(this);
} else { } else {
if (this.sock != null) { this.closeDirect();
try { }
ProtoCommon.closeSocket(this.sock); }
} finally {
this.sock = null; /**
} * close direct if not create from pool or not open pool
* @throws IOException
*/
public void closeDirect() throws IOException {
if (this.sock != null) {
try {
ProtoCommon.closeSocket(this.sock);
} finally {
this.sock = null;
} }
} }
} }

View File

@ -38,7 +38,7 @@ public class ConnectionPool {
ConnectionManager connectionManager = CP.get(key); ConnectionManager connectionManager = CP.get(key);
connectionManager.closeConnection(new ConnectionInfo(trackerServer.getSocket(), trackerServer.getInetSocketAddress(),trackerServer.getLastAccessTime(),true)); connectionManager.closeConnection(new ConnectionInfo(trackerServer.getSocket(), trackerServer.getInetSocketAddress(),trackerServer.getLastAccessTime(),true));
} else { } else {
trackerServer.close(); trackerServer.closeDirect();
} }
} }
@ -51,7 +51,7 @@ public class ConnectionPool {
ConnectionManager connectionManager = CP.get(key); ConnectionManager connectionManager = CP.get(key);
connectionManager.freeConnection(trackerServer); connectionManager.freeConnection(trackerServer);
} else { } else {
trackerServer.close(); trackerServer.closeDirect();
} }
} }