/** Only accepts 1 client connection at a time (saving threads) */ public void run() { Socket client_sock; while(acceptor != null && srv_sock != null) { try { client_sock=srv_sock.accept(); log.trace("%s: accepted connection from %s:%s", local_addr, client_sock.getInetAddress(), client_sock.getPort()); client_sock.setKeepAlive(keep_alive); ClientConnectionHandler client_conn_handler=new ClientConnectionHandler(client_sock, clients); Thread t = getThreadFactory().newThread(client_conn_handler, "FD_SOCK conn-handler"); t.setDaemon(true); synchronized(clients) { clients.add(client_conn_handler); } t.start(); } catch(IOException io_ex2) { break; } } acceptor=null; } }
protected void stop(boolean graceful) { if(acceptor != null && acceptor.isAlive()) Util.close(srv_sock); // this will terminate thread, peer will receive SocketException (socket close) synchronized(clients) { clients.forEach(client -> client.stopThread(graceful)); clients.clear(); } acceptor=null; }
public void run() { try { synchronized(mutex) { if(client_sock == null) return; in=client_sock.getInputStream(); } int b=0; do { b=in.read(); } while(b != ABNORMAL_TERMINATION && b != NORMAL_TERMINATION); } catch(IOException ex) { } finally { Socket sock=client_sock; // PATCH: avoid race condition causing NPE if (sock != null && !sock.isClosed()) closeClientSocket(); synchronized(clients) { clients.remove(this); } } } }
/** Only accepts 1 client connection at a time (saving threads) */ public void run() { Socket client_sock; while(acceptor != null && srv_sock != null) { try { client_sock=srv_sock.accept(); log.trace("%s: accepted connection from %s:%s", local_addr, client_sock.getInetAddress(), client_sock.getPort()); client_sock.setKeepAlive(keep_alive); ClientConnectionHandler client_conn_handler=new ClientConnectionHandler(client_sock, clients); Thread t = getThreadFactory().newThread(client_conn_handler, "FD_SOCK conn-handler"); t.setDaemon(true); synchronized(clients) { clients.add(client_conn_handler); } t.start(); } catch(IOException io_ex2) { break; } } acceptor=null; } }
/** Only accepts 1 client connection at a time (saving threads) */ public void run() { Socket client_sock; while(acceptor != null && srv_sock != null) { try { if(log.isTraceEnabled()) // +++ remove log.trace("waiting for client connections on " + srv_sock.getInetAddress() + ":" + srv_sock.getLocalPort()); client_sock=srv_sock.accept(); if(log.isTraceEnabled()) // +++ remove log.trace("accepted connection from " + client_sock.getInetAddress() + ':' + client_sock.getPort()); ClientConnectionHandler client_conn_handler=new ClientConnectionHandler(client_sock, clients); synchronized(clients) { clients.add(client_conn_handler); } client_conn_handler.start(); } catch(IOException io_ex2) { break; } } acceptor=null; } }
final void stop(boolean graceful) { if(acceptor != null && acceptor.isAlive()) { try { srv_sock.close(); // this will terminate thread, peer will receive SocketException (socket close) } catch(Exception ex) { } } synchronized(clients) { for(Iterator it=clients.iterator(); it.hasNext();) { ClientConnectionHandler handler=(ClientConnectionHandler)it.next(); handler.stopThread(graceful); } clients.clear(); } acceptor=null; }
void stopThread(boolean graceful) { synchronized(mutex) { if(client_sock != null) { try { if(graceful) { OutputStream out=client_sock.getOutputStream(); out.write(NORMAL_TERMINATION); out.flush(); } closeClientSocket(); } catch(Throwable t) { } } } }
protected void stop(boolean graceful) { if(acceptor != null && acceptor.isAlive()) Util.close(srv_sock); // this will terminate thread, peer will receive SocketException (socket close) synchronized(clients) { clients.forEach(client -> client.stopThread(graceful)); clients.clear(); } acceptor=null; }