forked from KNEMC/KLALB
修复内存泄露
This commit is contained in:
@@ -22,7 +22,7 @@ import org.kne.cloud.network.mport.ThreadTool;
|
||||
|
||||
public class KLALBServer {
|
||||
|
||||
Map<UUID, IOThreadManager> whm=new WeakHashMap<UUID, IOThreadManager>();
|
||||
Map<UUID, IOThreadManager> whm=Collections.synchronizedMap( new WeakHashMap<UUID, IOThreadManager>());
|
||||
public KLALBServer(int port,Supplier<String> gjso) throws IOException {
|
||||
TCPListener tcpl=new TCPListener(port);
|
||||
tcpl.setCon((s)->{
|
||||
@@ -50,9 +50,34 @@ public class KLALBServer {
|
||||
|
||||
tcc.handshake(10);
|
||||
|
||||
IOThreadManager nx = null;
|
||||
synchronized (tcpl) {
|
||||
if(whm.containsKey(uid)) {
|
||||
IOThreadManager nx=whm.computeIfAbsent(uid, (kuid)->{
|
||||
IOThreadManager iom=new IOThreadManager();
|
||||
iom.getCore().setAcceptSYN((b)->{
|
||||
try {
|
||||
STJson stj=new STJson(gjso.get());
|
||||
if(!stj.checkSafety(b.lipport)) {
|
||||
System.out.println("未授权的请求:"+b.lipport);
|
||||
return false;
|
||||
}
|
||||
Socket soc=new Socket(b.lipport.getIp(),b.lipport.getPort());
|
||||
LocalTCPConnection ltc=new LocalTCPConnection(soc, b.cuid);
|
||||
ThreadTool.makeVThreadIfSupport("局域网连接监视线程", ()->{
|
||||
try {
|
||||
iom.handleLocal(ltc, false);
|
||||
}finally {
|
||||
ltc.close();
|
||||
}
|
||||
}).start();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("连接本地服务"+b.lipport+"失败,请检查你的本地服务");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return iom;
|
||||
});
|
||||
/*if(whm.containsKey(uid)) {
|
||||
nx=whm.get(uid);
|
||||
}else {
|
||||
nx=new IOThreadManager();
|
||||
@@ -81,8 +106,7 @@ public class KLALBServer {
|
||||
return false;
|
||||
});
|
||||
whm.put(uid, nx);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
nx.handleRemote(tcc);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user