@Override public void setSocketTimeout(final Timeout timeout) { final SocketHolder socketHolder = this.socketHolderRef.get(); if (socketHolder != null) { try { socketHolder.getSocket().setSoTimeout(Timeout.defaultsToDisabled(timeout).toMillisIntBound()); } catch (final SocketException ignore) { // It is not quite clear from the Sun's documentation if there are any // other legitimate cases for a socket exception to be thrown when setting // SO_TIMEOUT besides the socket being already closed } } }
@Override public void setSocketTimeout(final Timeout timeout) { final SocketHolder socketHolder = this.socketHolderRef.get(); if (socketHolder != null) { try { socketHolder.getSocket().setSoTimeout(Timeout.defaultsToDisabled(timeout).toMillisIntBound()); } catch (final SocketException ignore) { // It is not quite clear from the Sun's documentation if there are any // other legitimate cases for a socket exception to be thrown when setting // SO_TIMEOUT besides the socket being already closed } } }
private Socket createSocket(final HttpHost targetHost) throws IOException { final Socket sock = new Socket(); sock.setSoTimeout(socketConfig.getSoTimeout().toMillisIntBound()); sock.setReuseAddress(socketConfig.isSoReuseAddress()); sock.setTcpNoDelay(socketConfig.isTcpNoDelay()); sock.setKeepAlive(socketConfig.isSoKeepAlive()); if (socketConfig.getRcvBufSize() > 0) { sock.setReceiveBufferSize(socketConfig.getRcvBufSize()); } if (socketConfig.getSndBufSize() > 0) { sock.setSendBufferSize(socketConfig.getSndBufSize()); } final int linger = socketConfig.getSoLinger().toMillisIntBound(); if (linger >= 0) { sock.setSoLinger(true, linger); } final InetSocketAddress targetAddress = addressResolver.resolve(targetHost); sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound()); if (URIScheme.HTTPS.same(targetHost.getSchemeName())) { return sslSocketFactory.createSocket(sock, targetHost.getHostName(), targetAddress.getPort(), true); } return sock; }
private Socket createSocket(final HttpHost targetHost) throws IOException { final Socket sock = new Socket(); sock.setSoTimeout(socketConfig.getSoTimeout().toMillisIntBound()); sock.setReuseAddress(socketConfig.isSoReuseAddress()); sock.setTcpNoDelay(socketConfig.isTcpNoDelay()); sock.setKeepAlive(socketConfig.isSoKeepAlive()); if (socketConfig.getRcvBufSize() > 0) { sock.setReceiveBufferSize(socketConfig.getRcvBufSize()); } if (socketConfig.getSndBufSize() > 0) { sock.setSendBufferSize(socketConfig.getSndBufSize()); } final int linger = socketConfig.getSoLinger().toMillisIntBound(); if (linger >= 0) { sock.setSoLinger(true, linger); } final InetSocketAddress targetAddress = addressResolver.resolve(targetHost); sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound()); if (URIScheme.HTTPS.same(targetHost.getSchemeName())) { return sslSocketFactory.createSocket(sock, targetHost.getHostName(), targetAddress.getPort(), true); } return sock; }
@Override public void run() { try { while (!isTerminated() && !Thread.interrupted()) { final Socket socket = this.serverSocket.accept(); socket.setSoTimeout(this.socketConfig.getSoTimeout().toMillisIntBound()); socket.setKeepAlive(this.socketConfig.isSoKeepAlive()); socket.setTcpNoDelay(this.socketConfig.isTcpNoDelay()); if (this.socketConfig.getRcvBufSize() > 0) { socket.setReceiveBufferSize(this.socketConfig.getRcvBufSize()); } if (this.socketConfig.getSndBufSize() > 0) { socket.setSendBufferSize(this.socketConfig.getSndBufSize()); } if (this.socketConfig.getSoLinger().toSeconds() >= 0) { socket.setSoLinger(true, this.socketConfig.getSoLinger().toSecondsIntBound()); } final HttpServerConnection conn = this.connectionFactory.createConnection(socket); final Worker worker = new Worker(this.httpService, conn, this.exceptionListener); this.executorService.execute(worker); } } catch (final Exception ex) { this.exceptionListener.onError(ex); } }
@Override public void run() { try { while (!isTerminated() && !Thread.interrupted()) { final Socket socket = this.serverSocket.accept(); socket.setSoTimeout(this.socketConfig.getSoTimeout().toMillisIntBound()); socket.setKeepAlive(this.socketConfig.isSoKeepAlive()); socket.setTcpNoDelay(this.socketConfig.isTcpNoDelay()); if (this.socketConfig.getRcvBufSize() > 0) { socket.setReceiveBufferSize(this.socketConfig.getRcvBufSize()); } if (this.socketConfig.getSndBufSize() > 0) { socket.setSendBufferSize(this.socketConfig.getSndBufSize()); } if (this.socketConfig.getSoLinger().toSeconds() >= 0) { socket.setSoLinger(true, this.socketConfig.getSoLinger().toSecondsIntBound()); } final HttpServerConnection conn = this.connectionFactory.createConnection(socket); final Worker worker = new Worker(this.httpService, conn, this.exceptionListener); this.executorService.execute(worker); } } catch (final Exception ex) { this.exceptionListener.onError(ex); } }
clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); final InputStream inputStream = clientSocket.getInputStream(); Assert.assertEquals('H', inputStream.read());
sock.setSoTimeout(socketConfig.getSoTimeout().toMillisIntBound()); sock.setReuseAddress(socketConfig.isSoReuseAddress()); sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
final int localPort = serverSocket.getLocalPort(); try (final SSLSocket clientSocket = (SSLSocket) clientSslContext.getSocketFactory().createSocket()) { clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake();
clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); final InputStream inputStream = clientSocket.getInputStream(); Assert.assertEquals('H', inputStream.read());
Assert.assertTrue(supportedClientProtocols.contains("SSLv3")); clientSocket.setEnabledProtocols(new String[] {"SSLv3"} ); clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake();
final int localPort = serverSocket.getLocalPort(); try (final SSLSocket clientSocket = (SSLSocket) clientSslContext.getSocketFactory().createSocket()) { clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake(); final InputStream inputStream = clientSocket.getInputStream();
clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake(); final InputStream inputStream = clientSocket.getInputStream();
clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake(); final InputStream inputStream = clientSocket.getInputStream();
final int localPort = serverSocket.getLocalPort(); try (final SSLSocket clientSocket = (SSLSocket) clientSslContext.getSocketFactory().createSocket()) { clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake(); final InputStream inputStream = clientSocket.getInputStream();
Assert.assertTrue(supportedClientProtocols.contains("TLSv1")); clientSocket.setEnabledProtocols(new String[] { "TLSv1" }); clientSocket.connect(new InetSocketAddress("localhost", localPort), TIMEOUT.toMillisIntBound()); clientSocket.setSoTimeout(TIMEOUT.toMillisIntBound()); clientSocket.startHandshake(); final InputStream inputStream = clientSocket.getInputStream();