141 super(addr, client); |
141 super(addr, client); |
142 try { |
142 try { |
143 this.chan = SocketChannel.open(); |
143 this.chan = SocketChannel.open(); |
144 chan.configureBlocking(false); |
144 chan.configureBlocking(false); |
145 int bufsize = client.getReceiveBufferSize(); |
145 int bufsize = client.getReceiveBufferSize(); |
146 chan.setOption(StandardSocketOptions.SO_RCVBUF, bufsize); |
146 if (!trySetReceiveBufferSize(bufsize)) { |
|
147 trySetReceiveBufferSize(256*1024); |
|
148 } |
147 chan.setOption(StandardSocketOptions.TCP_NODELAY, true); |
149 chan.setOption(StandardSocketOptions.TCP_NODELAY, true); |
148 // wrap the connected channel in a Tube for async reading and writing |
150 // wrap the connected channel in a Tube for async reading and writing |
149 tube = new SocketTube(client(), chan, Utils::getBuffer); |
151 tube = new SocketTube(client(), chan, Utils::getBuffer); |
150 } catch (IOException e) { |
152 } catch (IOException e) { |
151 throw new InternalError(e); |
153 throw new InternalError(e); |
152 } |
154 } |
|
155 } |
|
156 |
|
157 private boolean trySetReceiveBufferSize(int bufsize) { |
|
158 try { |
|
159 chan.setOption(StandardSocketOptions.SO_RCVBUF, bufsize); |
|
160 return true; |
|
161 } catch(IOException x) { |
|
162 debug.log(Level.DEBUG, |
|
163 "Failed to set receive buffer size to %d on %s", |
|
164 bufsize, chan); |
|
165 } |
|
166 return false; |
153 } |
167 } |
154 |
168 |
155 @Override |
169 @Override |
156 HttpPublisher publisher() { return writePublisher; } |
170 HttpPublisher publisher() { return writePublisher; } |
157 |
171 |