use of okhttp3.DelegatingServerSocketFactory in project okhttp by square.
the class DisconnectTest method setUp.
@Before
public void setUp() throws Exception {
// Sockets on some platforms can have large buffers that mean writes do not block when
// required. These socket factories explicitly set the buffer sizes on sockets created.
server = new MockWebServer();
server.setServerSocketFactory(new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
@Override
protected ServerSocket configureServerSocket(ServerSocket serverSocket) throws IOException {
serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return serverSocket;
}
});
client = defaultClient().newBuilder().socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
@Override
protected Socket configureSocket(Socket socket) throws IOException {
socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return socket;
}
}).build();
}
use of okhttp3.DelegatingServerSocketFactory in project okhttp by square.
the class URLConnectionTest method writeTimeouts.
/** Confirm that an unacknowledged write times out. */
@Test
public void writeTimeouts() throws IOException {
MockWebServer server = new MockWebServer();
// Sockets on some platforms can have large buffers that mean writes do not block when
// required. These socket factories explicitly set the buffer sizes on sockets created.
final int SOCKET_BUFFER_SIZE = 4 * 1024;
server.setServerSocketFactory(new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
@Override
protected ServerSocket configureServerSocket(ServerSocket serverSocket) throws IOException {
serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return serverSocket;
}
});
urlFactory.setClient(urlFactory.client().newBuilder().socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
@Override
protected Socket configureSocket(Socket socket) throws IOException {
socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
return socket;
}
}).writeTimeout(500, TimeUnit.MILLISECONDS).build());
server.start();
server.enqueue(new MockResponse().throttleBody(1, 1, // Prevent the server from reading!
TimeUnit.SECONDS));
connection = urlFactory.open(server.url("/").url());
connection.setDoOutput(true);
connection.setChunkedStreamingMode(0);
OutputStream out = connection.getOutputStream();
try {
// 2 MiB.
byte[] data = new byte[2 * 1024 * 1024];
out.write(data);
fail();
} catch (SocketTimeoutException expected) {
}
}
use of okhttp3.DelegatingServerSocketFactory in project okhttp by square.
the class ThreadInterruptTest method setUp.
@Before
public void setUp() throws Exception {
// Sockets on some platforms can have large buffers that mean writes do not block when
// required. These socket factories explicitly set the buffer sizes on sockets created.
server = new MockWebServer();
server.setServerSocketFactory(new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
@Override
protected ServerSocket configureServerSocket(ServerSocket serverSocket) throws IOException {
serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return serverSocket;
}
});
client = defaultClient().newBuilder().socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
@Override
protected Socket configureSocket(Socket socket) throws IOException {
socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return socket;
}
}).build();
}
Aggregations