合并IO线程管理类
This commit is contained in:
@@ -10,12 +10,15 @@ import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.*;
|
||||
public class KLALBServerProtocol {
|
||||
private List<TCPConnection>tls=new Vector<>();
|
||||
|
||||
private KLALBCore klc=new KLALBCore(100);
|
||||
private List<TCPConnection>tcps=new Vector<>();
|
||||
|
||||
|
||||
private InputStream in;
|
||||
private OutputStream out;
|
||||
|
||||
|
||||
private volatile boolean closed=true;
|
||||
public void startLocal() {
|
||||
|
||||
Thread upo=ThreadTool.makeVThreadIfSupport("本地接收线程",()->{
|
||||
@@ -55,7 +58,7 @@ public class KLALBServerProtocol {
|
||||
downo.start();
|
||||
}
|
||||
public void handleSocket(TCPConnection s) throws IOException {
|
||||
tls.add(s);
|
||||
tcps.add(s);
|
||||
Thread up=ThreadTool.makeVThreadIfSupport("远程发送线程",()->{
|
||||
try{
|
||||
while(true) {
|
||||
@@ -86,8 +89,8 @@ public class KLALBServerProtocol {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tls.remove(s);
|
||||
int n=tls.size();
|
||||
tcps.remove(s);
|
||||
int n=tcps.size();
|
||||
if(n<=0) {
|
||||
closeALL();
|
||||
System.out.println("连接已关闭");
|
||||
@@ -109,6 +112,7 @@ public class KLALBServerProtocol {
|
||||
this.out = out;
|
||||
}
|
||||
public void closeALL() {
|
||||
closed=false;
|
||||
try {
|
||||
in.close();
|
||||
|
||||
@@ -120,10 +124,17 @@ public class KLALBServerProtocol {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int i = 0; i < tls.size(); i++) {
|
||||
TCPConnection tll=tls.get(i);
|
||||
for (int i = 0; i < tcps.size(); i++) {
|
||||
TCPConnection tll=tcps.get(i);
|
||||
tll.close();
|
||||
}
|
||||
klc.close();
|
||||
}
|
||||
public List<TCPConnection> getTcps() {
|
||||
return tcps;
|
||||
}
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user