Refine search
while(!serverSocket.isClosed()) { try { Socket newClient = serverSocket.accept(); PrintWriter pw = new PrintWriter(newClient.getOutputStream()); if(connections.size() < MAX_CONNECTIONS) { Thread.currentThread().interrupt(); if (!serverSocket.isClosed()) { LogLog.error("Encountered error while in SocketHandler loop.", e);
@Override protected int doReadMessages(List<Object> buf) throws Exception { if (socket.isClosed()) { return -1; } try { Socket s = socket.accept(); try { buf.add(new OioSocketChannel(this, s)); return 1; } catch (Throwable t) { logger.warn("Failed to create a new channel from an accepted socket.", t); try { s.close(); } catch (Throwable t2) { logger.warn("Failed to close a socket.", t2); } } } catch (SocketTimeoutException e) { // Expected } return 0; }
/** * Start listening for incoming connections and forward to remote host as a channel and ensure that the thread is registered. * This is useful if for instance {@link #close() is called from another thread} * * @throws IOException */ public void listen(Thread runningThread) throws IOException { this.runningThread = runningThread; log.info("Listening on {}", serverSocket.getLocalSocketAddress()); while (!runningThread.isInterrupted()) { try { final Socket socket = serverSocket.accept(); log.debug("Got connection from {}", socket.getRemoteSocketAddress()); startChannel(socket); } catch (SocketException e) { if (!serverSocket.isClosed()) { throw e; } } } if (serverSocket.isClosed()) { log.debug("LocalPortForwarder closed"); } else { log.debug("LocalPortForwarder interrupted!"); } }
public void run() { while(!srv_sock.isClosed()) { Socket client_sock=null; DataInputStream in=null; try { client_sock=srv_sock.accept(); client_sock.setTcpNoDelay(TCP_NODELAY); client_sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); client_sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); in=new DataInputStream(new BufferedInputStream(client_sock.getInputStream())); while(!client_sock.isClosed()) handleRequest(in); } catch(Exception e) { Util.close(client_sock); Util.close(in); } } }
public void run() { while(!srv_sock.isClosed()) { Socket client_sock=null; DataInputStream in=null; try { client_sock=srv_sock.accept(); client_sock.setTcpNoDelay(TCP_NODELAY); client_sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); client_sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); in=new DataInputStream(new BufferedInputStream(client_sock.getInputStream())); while(!client_sock.isClosed()) handleRequest(in); } catch(Exception e) { Util.close(client_sock); Util.close(in); } } }
@Override protected int doReadMessages(List<Object> buf) throws Exception { if (socket.isClosed()) { return -1; } try { Socket s = socket.accept(); try { buf.add(new OioSocketChannel(this, s)); return 1; } catch (Throwable t) { logger.warn("Failed to create a new channel from an accepted socket.", t); try { s.close(); } catch (Throwable t2) { logger.warn("Failed to close a socket.", t2); } } } catch (SocketTimeoutException e) { // Expected } return 0; }
/** * Acceptor thread. Continuously accept new connections. Create a new thread for each new connection and put * it in conns. When the thread should stop, it is interrupted by the thread creator. */ public void run() { while(!srv_sock.isClosed() && !Thread.currentThread().isInterrupted()) { Socket client_sock=null; try { client_sock=srv_sock.accept(); handleAccept(client_sock); } catch(Exception ex) { if(ex instanceof SocketException && srv_sock.isClosed() || Thread.currentThread().isInterrupted()) break; log.warn(Util.getMessage("AcceptError"), ex); Util.close(client_sock); } } }
@Override public void run() { try { httpd.getMyServerSocket().bind(httpd.hostname != null ? new InetSocketAddress(httpd.hostname, httpd.myPort) : new InetSocketAddress(httpd.myPort)); hasBinded = true; } catch (IOException e) { this.bindException = e; return; } do { try { final Socket finalAccept = httpd.getMyServerSocket().accept(); if (this.timeout > 0) { finalAccept.setSoTimeout(this.timeout); } final InputStream inputStream = finalAccept.getInputStream(); httpd.asyncRunner.exec(httpd.createClientHandler(finalAccept, inputStream)); } catch (IOException e) { NanoHTTPD.LOG.log(Level.FINE, "Communication with the client broken", e); } } while (!httpd.getMyServerSocket().isClosed()); }
@Override public void run() { while (true) { Socket socket = null; try { if (Socks5Proxy.this.serverSocket == null || Socks5Proxy.this.serverSocket.isClosed() || Thread.currentThread().isInterrupted()) { return; } // accept connection socket = Socks5Proxy.this.serverSocket.accept(); // initialize connection establishConnection(socket); } catch (SocketException e) { /* * do nothing, if caused by closing the server socket, thread will terminate in * next loop */ } catch (Exception e) { CloseableUtil.maybeClose(socket, LOGGER); } } }
@Override protected int doReadMessages(List<Object> buf) throws Exception { if (socket.isClosed()) { return -1; } try { Socket s = socket.accept(); try { buf.add(new OioSocketChannel(this, s)); return 1; } catch (Throwable t) { logger.warn("Failed to create a new channel from an accepted socket.", t); try { s.close(); } catch (Throwable t2) { logger.warn("Failed to close a socket.", t2); } } } catch (SocketTimeoutException e) { // Expected } return 0; }
public void run() { if(log.isDebugEnabled()) log.debug(local_addr + ": StateProviderAcceptor listening at " + getServerSocketAddress()); while(running) { try { final Socket socket=serverSocket.accept(); try { pool.execute(() -> process(socket)); } catch(RejectedExecutionException rejected) { Util.close(socket); } } catch(Throwable e) { if(serverSocket.isClosed()) running=false; } } }
public void run() { try { while(!socket.isClosed()) { pause.get().await(); try { Socket source = socket.accept(); pause.get().await(); if (receiveBufferSize > 0) { source.setReceiveBufferSize(receiveBufferSize); } LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize()); synchronized(connections) { connections.add(new Bridge(source, target)); } } catch (SocketTimeoutException expected) { } } } catch (Exception e) { LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage()); } }