Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/ChannelEndPoint.java @ 873:220ad4853cda
remove StreamEndPoint
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 03 Oct 2016 20:03:50 -0600 |
parents | 8e9db0bbf4f9 |
children | fc521d2f098e |
comparison
equal
deleted
inserted
replaced
872:1c0b6841cd32 | 873:220ad4853cda |
---|---|
39 * <p>Holds the channel and socket for an NIO endpoint. | 39 * <p>Holds the channel and socket for an NIO endpoint. |
40 * | 40 * |
41 */ | 41 */ |
42 public class ChannelEndPoint implements EndPoint | 42 public class ChannelEndPoint implements EndPoint |
43 { | 43 { |
44 private static final Logger LOG = LoggerFactory.getLogger(ChannelEndPoint.class); | 44 private static final Logger LOG = LoggerFactory.getLogger(ChannelEndPoint.class); |
45 | 45 |
46 protected final ByteChannel _channel; | 46 protected final ByteChannel _channel; |
47 protected final ByteBuffer[] _gather2=new ByteBuffer[2]; | 47 protected final ByteBuffer[] _gather2=new ByteBuffer[2]; |
48 protected final Socket _socket; | 48 protected final Socket _socket; |
49 protected final InetSocketAddress _local; | 49 protected final InetSocketAddress _local; |
50 protected final InetSocketAddress _remote; | 50 protected final InetSocketAddress _remote; |
51 protected volatile int _maxIdleTime; | 51 protected volatile int _maxIdleTime; |
52 private volatile boolean _ishut; | 52 private volatile boolean _ishut; |
53 private volatile boolean _oshut; | 53 private volatile boolean _oshut; |
54 | 54 |
55 public ChannelEndPoint(ByteChannel channel) throws IOException | 55 public ChannelEndPoint(ByteChannel channel) throws IOException |
56 { | 56 { |
57 super(); | 57 super(); |
58 this._channel = channel; | 58 this._channel = channel; |
59 _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; | 59 _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; |
60 if (_socket!=null) | 60 if (_socket!=null) |
61 { | 61 { |
62 _local=(InetSocketAddress)_socket.getLocalSocketAddress(); | 62 _local=(InetSocketAddress)_socket.getLocalSocketAddress(); |
63 _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); | 63 _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); |
64 _maxIdleTime=_socket.getSoTimeout(); | 64 _maxIdleTime=_socket.getSoTimeout(); |
65 } | 65 } |
66 else | 66 else |
67 { | 67 { |
68 _local=_remote=null; | 68 _local=_remote=null; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 protected ChannelEndPoint(ByteChannel channel, int maxIdleTime) throws IOException | 72 protected ChannelEndPoint(ByteChannel channel, int maxIdleTime) throws IOException |
73 { | 73 { |
74 this._channel = channel; | 74 this._channel = channel; |
75 _maxIdleTime=maxIdleTime; | 75 _maxIdleTime=maxIdleTime; |
76 _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; | 76 _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; |
77 if (_socket!=null) | 77 if (_socket!=null) |
78 { | 78 { |
79 _local=(InetSocketAddress)_socket.getLocalSocketAddress(); | 79 _local=(InetSocketAddress)_socket.getLocalSocketAddress(); |
80 _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); | 80 _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); |
81 _socket.setSoTimeout(_maxIdleTime); | 81 _socket.setSoTimeout(_maxIdleTime); |
82 } | 82 } |
83 else | 83 else |
84 { | 84 { |
85 _local=_remote=null; | 85 _local=_remote=null; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 public boolean isBlocking() | 89 public boolean isBlocking() |
90 { | 90 { |
91 return !(_channel instanceof SelectableChannel) || ((SelectableChannel)_channel).isBlocking(); | 91 return !(_channel instanceof SelectableChannel) || ((SelectableChannel)_channel).isBlocking(); |
92 } | 92 } |
93 | 93 |
94 public boolean blockReadable(long millisecs) throws IOException | 94 public boolean blockReadable(long millisecs) throws IOException |
95 { | 95 { |
96 return true; | 96 return true; |
97 } | 97 } |
98 | 98 |
99 public boolean blockWritable(long millisecs) throws IOException | 99 public boolean blockWritable(long millisecs) throws IOException |
100 { | 100 { |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 /* | 104 /* |
105 * @see org.eclipse.io.EndPoint#isOpen() | 105 * @see org.eclipse.io.EndPoint#isOpen() |
106 */ | 106 */ |
107 public boolean isOpen() | 107 public boolean isOpen() |
108 { | 108 { |
109 return _channel.isOpen(); | 109 return _channel.isOpen(); |
110 } | 110 } |
111 | 111 |
112 /** Shutdown the channel Input. | 112 /** Shutdown the channel Input. |
113 * Cannot be overridden. To override, see {@link #shutdownInput()} | 113 * Cannot be overridden. To override, see {@link #shutdownInput()} |
114 * @throws IOException | 114 * @throws IOException |
115 */ | 115 */ |
116 protected final void shutdownChannelInput() throws IOException | 116 protected final void shutdownChannelInput() throws IOException |
117 { | 117 { |
118 LOG.debug("ishut {}", this); | 118 LOG.debug("ishut {}", this); |
119 _ishut = true; | 119 _ishut = true; |
120 if (_channel.isOpen()) | 120 if (_channel.isOpen()) |
121 { | 121 { |
122 if (_socket != null) | 122 if (_socket != null) |
123 { | 123 { |
124 try | 124 try |
125 { | 125 { |
126 if (!_socket.isInputShutdown()) | 126 if (!_socket.isInputShutdown()) |
127 { | 127 { |
128 _socket.shutdownInput(); | 128 _socket.shutdownInput(); |
129 } | 129 } |
130 } | 130 } |
131 catch (SocketException e) | 131 catch (SocketException e) |
132 { | 132 { |
133 LOG.debug(e.toString()); | 133 LOG.debug(e.toString()); |
134 LOG.trace("",e); | 134 LOG.trace("",e); |
135 } | 135 } |
136 finally | 136 finally |
137 { | 137 { |
138 if (_oshut) | 138 if (_oshut) |
139 { | 139 { |
140 close(); | 140 close(); |
141 } | 141 } |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 /* (non-Javadoc) | 147 /* (non-Javadoc) |
148 * @see org.eclipse.io.EndPoint#close() | 148 * @see org.eclipse.io.EndPoint#close() |
149 */ | 149 */ |
150 public void shutdownInput() throws IOException | 150 public void shutdownInput() throws IOException |
151 { | 151 { |
152 shutdownChannelInput(); | 152 shutdownChannelInput(); |
153 } | 153 } |
154 | 154 |
155 protected final void shutdownChannelOutput() throws IOException | 155 protected final void shutdownChannelOutput() throws IOException |
156 { | 156 { |
157 LOG.debug("oshut {}",this); | 157 LOG.debug("oshut {}",this); |
158 _oshut = true; | 158 _oshut = true; |
159 if (_channel.isOpen()) | 159 if (_channel.isOpen()) |
160 { | 160 { |
161 if (_socket != null) | 161 if (_socket != null) |
162 { | 162 { |
163 try | 163 try |
164 { | 164 { |
165 if (!_socket.isOutputShutdown()) | 165 if (!_socket.isOutputShutdown()) |
166 { | 166 { |
167 _socket.shutdownOutput(); | 167 _socket.shutdownOutput(); |
168 } | 168 } |
169 } | 169 } |
170 catch (SocketException e) | 170 catch (SocketException e) |
171 { | 171 { |
172 LOG.debug(e.toString()); | 172 LOG.debug(e.toString()); |
173 LOG.trace("",e); | 173 LOG.trace("",e); |
174 } | 174 } |
175 finally | 175 finally |
176 { | 176 { |
177 if (_ishut) | 177 if (_ishut) |
178 { | 178 { |
179 close(); | 179 close(); |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 /* (non-Javadoc) | 186 /* (non-Javadoc) |
187 * @see org.eclipse.io.EndPoint#close() | 187 * @see org.eclipse.io.EndPoint#close() |
188 */ | 188 */ |
189 public void shutdownOutput() throws IOException | 189 public void shutdownOutput() throws IOException |
190 { | 190 { |
191 shutdownChannelOutput(); | 191 shutdownChannelOutput(); |
192 } | 192 } |
193 | 193 |
194 public boolean isOutputShutdown() | 194 public boolean isOutputShutdown() |
195 { | 195 { |
196 return _oshut || !_channel.isOpen() || _socket != null && _socket.isOutputShutdown(); | 196 return _oshut || !_channel.isOpen() || _socket != null && _socket.isOutputShutdown(); |
197 } | 197 } |
198 | 198 |
199 public boolean isInputShutdown() | 199 public boolean isInputShutdown() |
200 { | 200 { |
201 return _ishut || !_channel.isOpen() || _socket != null && _socket.isInputShutdown(); | 201 return _ishut || !_channel.isOpen() || _socket != null && _socket.isInputShutdown(); |
202 } | 202 } |
203 | 203 |
204 /* (non-Javadoc) | 204 /* (non-Javadoc) |
205 * @see org.eclipse.io.EndPoint#close() | 205 * @see org.eclipse.io.EndPoint#close() |
206 */ | 206 */ |
207 public void close() throws IOException | 207 public void close() throws IOException |
208 { | 208 { |
209 LOG.debug("close {}",this); | 209 LOG.debug("close {}",this); |
210 _channel.close(); | 210 _channel.close(); |
211 } | 211 } |
212 | 212 |
213 /* (non-Javadoc) | 213 /* (non-Javadoc) |
214 * @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer) | 214 * @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer) |
215 */ | 215 */ |
216 public int fill(Buffer buffer) throws IOException | 216 public int fill(Buffer buffer) throws IOException |
217 { | 217 { |
218 if (_ishut) | 218 if (_ishut) |
219 return -1; | 219 return -1; |
220 Buffer buf = buffer.buffer(); | 220 Buffer buf = buffer.buffer(); |
221 int len=0; | 221 int len=0; |
222 if (buf instanceof NIOBuffer) | 222 if (buf instanceof NIOBuffer) |
223 { | 223 { |
224 final NIOBuffer nbuf = (NIOBuffer)buf; | 224 final NIOBuffer nbuf = (NIOBuffer)buf; |
225 final ByteBuffer bbuf=nbuf.getByteBuffer(); | 225 final ByteBuffer bbuf=nbuf.getByteBuffer(); |
226 | 226 |
227 //noinspection SynchronizationOnLocalVariableOrMethodParameter | 227 //noinspection SynchronizationOnLocalVariableOrMethodParameter |
228 try | 228 try |
229 { | 229 { |
230 synchronized(bbuf) | 230 synchronized(bbuf) |
231 { | 231 { |
232 try | 232 try |
233 { | 233 { |
234 bbuf.position(buffer.putIndex()); | 234 bbuf.position(buffer.putIndex()); |
235 len=_channel.read(bbuf); | 235 len=_channel.read(bbuf); |
236 } | 236 } |
237 finally | 237 finally |
238 { | 238 { |
239 buffer.setPutIndex(bbuf.position()); | 239 buffer.setPutIndex(bbuf.position()); |
240 bbuf.position(0); | 240 bbuf.position(0); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 if (len<0 && isOpen()) | 244 if (len<0 && isOpen()) |
245 { | 245 { |
246 if (!isInputShutdown()) | 246 if (!isInputShutdown()) |
247 shutdownInput(); | 247 shutdownInput(); |
248 if (isOutputShutdown()) | 248 if (isOutputShutdown()) |
249 _channel.close(); | 249 _channel.close(); |
250 } | 250 } |
251 } | 251 } |
252 catch (IOException x) | 252 catch (IOException x) |
253 { | 253 { |
254 LOG.debug("Exception while filling", x); | 254 LOG.debug("Exception while filling", x); |
255 try | 255 try |
256 { | 256 { |
257 if (_channel.isOpen()) | 257 if (_channel.isOpen()) |
258 _channel.close(); | 258 _channel.close(); |
259 } | 259 } |
260 catch (Exception xx) | 260 catch (Exception xx) |
261 { | 261 { |
262 LOG.trace("",xx); | 262 LOG.trace("",xx); |
263 } | 263 } |
264 | 264 |
265 if (len>0) | 265 if (len>0) |
266 throw x; | 266 throw x; |
267 len=-1; | 267 len=-1; |
268 } | 268 } |
269 } | 269 } |
270 else | 270 else |
271 { | 271 { |
272 throw new IOException("Not Implemented"); | 272 throw new IOException("Not Implemented"); |
273 } | 273 } |
274 | 274 |
275 return len; | 275 return len; |
276 } | 276 } |
277 | 277 |
278 /* (non-Javadoc) | 278 /* (non-Javadoc) |
279 * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer) | 279 * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer) |
280 */ | 280 */ |
281 public int flush(Buffer buffer) throws IOException | 281 public int flush(Buffer buffer) throws IOException |
282 { | 282 { |
283 Buffer buf = buffer.buffer(); | 283 Buffer buf = buffer.buffer(); |
284 int len=0; | 284 int len=0; |
285 if (buf instanceof NIOBuffer) | 285 if (buf instanceof NIOBuffer) |
286 { | 286 { |
287 final NIOBuffer nbuf = (NIOBuffer)buf; | 287 final NIOBuffer nbuf = (NIOBuffer)buf; |
288 final ByteBuffer bbuf=nbuf.getByteBuffer().asReadOnlyBuffer(); | 288 final ByteBuffer bbuf=nbuf.getByteBuffer().asReadOnlyBuffer(); |
289 try | 289 try |
290 { | 290 { |
291 bbuf.position(buffer.getIndex()); | 291 bbuf.position(buffer.getIndex()); |
292 bbuf.limit(buffer.putIndex()); | 292 bbuf.limit(buffer.putIndex()); |
293 len=_channel.write(bbuf); | 293 len=_channel.write(bbuf); |
294 } | 294 } |
295 finally | 295 finally |
296 { | 296 { |
297 if (len>0) | 297 if (len>0) |
298 buffer.skip(len); | 298 buffer.skip(len); |
299 } | 299 } |
300 } | 300 } |
301 else if (buf instanceof RandomAccessFileBuffer) | 301 else if (buf instanceof RandomAccessFileBuffer) |
302 { | 302 { |
303 len = ((RandomAccessFileBuffer)buf).writeTo(_channel,buffer.getIndex(),buffer.length()); | 303 len = ((RandomAccessFileBuffer)buf).writeTo(_channel,buffer.getIndex(),buffer.length()); |
304 if (len>0) | 304 if (len>0) |
305 buffer.skip(len); | 305 buffer.skip(len); |
306 } | 306 } |
307 else if (buffer.array()!=null) | 307 else if (buffer.array()!=null) |
308 { | 308 { |
309 ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.length()); | 309 ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.length()); |
310 len=_channel.write(b); | 310 len=_channel.write(b); |
311 if (len>0) | 311 if (len>0) |
312 buffer.skip(len); | 312 buffer.skip(len); |
313 } | 313 } |
314 else | 314 else |
315 { | 315 { |
316 throw new IOException("Not Implemented"); | 316 throw new IOException("Not Implemented"); |
317 } | 317 } |
318 return len; | 318 return len; |
319 } | 319 } |
320 | 320 |
321 /* (non-Javadoc) | 321 /* (non-Javadoc) |
322 * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer) | 322 * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer) |
323 */ | 323 */ |
324 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException | 324 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException |
325 { | 325 { |
326 int length=0; | 326 int length=0; |
327 | 327 |
328 Buffer buf0 = header==null?null:header.buffer(); | 328 Buffer buf0 = header==null?null:header.buffer(); |
329 Buffer buf1 = buffer==null?null:buffer.buffer(); | 329 Buffer buf1 = buffer==null?null:buffer.buffer(); |
330 | 330 |
331 if (_channel instanceof GatheringByteChannel && | 331 if (_channel instanceof GatheringByteChannel && |
332 header!=null && header.length()!=0 && buf0 instanceof NIOBuffer && | 332 header!=null && header.length()!=0 && buf0 instanceof NIOBuffer && |
333 buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer) | 333 buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer) |
334 { | 334 { |
335 length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer()); | 335 length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer()); |
336 } | 336 } |
337 else | 337 else |
338 { | 338 { |
339 // flush header | 339 // flush header |
340 if (header!=null && header.length()>0) | 340 if (header!=null && header.length()>0) |
341 length=flush(header); | 341 length=flush(header); |
342 | 342 |
343 // flush buffer | 343 // flush buffer |
344 if ((header==null || header.length()==0) && | 344 if ((header==null || header.length()==0) && |
345 buffer!=null && buffer.length()>0) | 345 buffer!=null && buffer.length()>0) |
346 length+=flush(buffer); | 346 length+=flush(buffer); |
347 | 347 |
348 // flush trailer | 348 // flush trailer |
349 if ((header==null || header.length()==0) && | 349 if ((header==null || header.length()==0) && |
350 (buffer==null || buffer.length()==0) && | 350 (buffer==null || buffer.length()==0) && |
351 trailer!=null && trailer.length()>0) | 351 trailer!=null && trailer.length()>0) |
352 length+=flush(trailer); | 352 length+=flush(trailer); |
353 } | 353 } |
354 | 354 |
355 return length; | 355 return length; |
356 } | 356 } |
357 | 357 |
358 protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException | 358 protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException |
359 { | 359 { |
360 int length; | 360 int length; |
361 | 361 |
362 synchronized(this) | 362 synchronized(this) |
363 { | 363 { |
364 // Adjust position indexs of buf0 and buf1 | 364 // Adjust position indexs of buf0 and buf1 |
365 bbuf0=bbuf0.asReadOnlyBuffer(); | 365 bbuf0=bbuf0.asReadOnlyBuffer(); |
366 bbuf0.position(header.getIndex()); | 366 bbuf0.position(header.getIndex()); |
367 bbuf0.limit(header.putIndex()); | 367 bbuf0.limit(header.putIndex()); |
368 bbuf1=bbuf1.asReadOnlyBuffer(); | 368 bbuf1=bbuf1.asReadOnlyBuffer(); |
369 bbuf1.position(buffer.getIndex()); | 369 bbuf1.position(buffer.getIndex()); |
370 bbuf1.limit(buffer.putIndex()); | 370 bbuf1.limit(buffer.putIndex()); |
371 | 371 |
372 _gather2[0]=bbuf0; | 372 _gather2[0]=bbuf0; |
373 _gather2[1]=bbuf1; | 373 _gather2[1]=bbuf1; |
374 | 374 |
375 // do the gathering write. | 375 // do the gathering write. |
376 length=(int)((GatheringByteChannel)_channel).write(_gather2); | 376 length=(int)((GatheringByteChannel)_channel).write(_gather2); |
377 | 377 |
378 int hl=header.length(); | 378 int hl=header.length(); |
379 if (length>hl) | 379 if (length>hl) |
380 { | 380 { |
381 header.clear(); | 381 header.clear(); |
382 buffer.skip(length-hl); | 382 buffer.skip(length-hl); |
383 } | 383 } |
384 else if (length>0) | 384 else if (length>0) |
385 { | 385 { |
386 header.skip(length); | 386 header.skip(length); |
387 } | 387 } |
388 } | 388 } |
389 return length; | 389 return length; |
390 } | 390 } |
391 | 391 |
392 /* ------------------------------------------------------------ */ | 392 /* ------------------------------------------------------------ */ |
393 /** | 393 /** |
394 * @return Returns the channel. | 394 * @return Returns the channel. |
395 */ | 395 */ |
396 public ByteChannel getChannel() | 396 public ByteChannel getChannel() |
397 { | 397 { |
398 return _channel; | 398 return _channel; |
399 } | 399 } |
400 | 400 |
401 | 401 |
402 /* ------------------------------------------------------------ */ | 402 /* ------------------------------------------------------------ */ |
403 /* | 403 /* |
404 * @see org.eclipse.io.EndPoint#getLocalAddr() | 404 * @see org.eclipse.io.EndPoint#getLocalAddr() |
405 */ | 405 */ |
406 public String getLocalAddr() | 406 public String getLocalAddr() |
407 { | 407 { |
408 if (_socket==null) | 408 if (_socket==null) |
409 return null; | 409 return null; |
410 if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) | 410 if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) |
411 return StringUtil.ALL_INTERFACES; | 411 return StringUtil.ALL_INTERFACES; |
412 return _local.getAddress().getHostAddress(); | 412 return _local.getAddress().getHostAddress(); |
413 } | 413 } |
414 | 414 |
415 /* ------------------------------------------------------------ */ | 415 /* ------------------------------------------------------------ */ |
416 /* | 416 /* |
417 * @see org.eclipse.io.EndPoint#getLocalHost() | 417 * @see org.eclipse.io.EndPoint#getLocalHost() |
418 */ | 418 */ |
419 public String getLocalHost() | 419 public String getLocalHost() |
420 { | 420 { |
421 if (_socket==null) | 421 if (_socket==null) |
422 return null; | 422 return null; |
423 if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) | 423 if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) |
424 return StringUtil.ALL_INTERFACES; | 424 return StringUtil.ALL_INTERFACES; |
425 return _local.getAddress().getCanonicalHostName(); | 425 return _local.getAddress().getCanonicalHostName(); |
426 } | 426 } |
427 | 427 |
428 /* ------------------------------------------------------------ */ | 428 /* ------------------------------------------------------------ */ |
429 /* | 429 /* |
430 * @see org.eclipse.io.EndPoint#getLocalPort() | 430 * @see org.eclipse.io.EndPoint#getLocalPort() |
431 */ | 431 */ |
432 public int getLocalPort() | 432 public int getLocalPort() |
433 { | 433 { |
434 if (_socket==null) | 434 if (_socket==null) |
435 return 0; | 435 return 0; |
436 if (_local==null) | 436 if (_local==null) |
437 return -1; | 437 return -1; |
438 return _local.getPort(); | 438 return _local.getPort(); |
439 } | 439 } |
440 | 440 |
441 /* ------------------------------------------------------------ */ | 441 /* ------------------------------------------------------------ */ |
442 /* | 442 /* |
443 * @see org.eclipse.io.EndPoint#getRemoteAddr() | 443 * @see org.eclipse.io.EndPoint#getRemoteAddr() |
444 */ | 444 */ |
445 public String getRemoteAddr() | 445 public String getRemoteAddr() |
446 { | 446 { |
447 if (_socket==null) | 447 if (_socket==null) |
448 return null; | 448 return null; |
449 if (_remote==null) | 449 if (_remote==null) |
450 return null; | 450 return null; |
451 return _remote.getAddress().getHostAddress(); | 451 return _remote.getAddress().getHostAddress(); |
452 } | 452 } |
453 | 453 |
454 /* ------------------------------------------------------------ */ | 454 /* ------------------------------------------------------------ */ |
455 /* | 455 /* |
456 * @see org.eclipse.io.EndPoint#getRemoteHost() | 456 * @see org.eclipse.io.EndPoint#getRemoteHost() |
457 */ | 457 */ |
458 public String getRemoteHost() | 458 public String getRemoteHost() |
459 { | 459 { |
460 if (_socket==null) | 460 if (_socket==null) |
461 return null; | 461 return null; |
462 if (_remote==null) | 462 if (_remote==null) |
463 return null; | 463 return null; |
464 return _remote.getAddress().getCanonicalHostName(); | 464 return _remote.getAddress().getCanonicalHostName(); |
465 } | 465 } |
466 | 466 |
467 /* ------------------------------------------------------------ */ | 467 /* ------------------------------------------------------------ */ |
468 /* | 468 /* |
469 * @see org.eclipse.io.EndPoint#getRemotePort() | 469 * @see org.eclipse.io.EndPoint#getRemotePort() |
470 */ | 470 */ |
471 public int getRemotePort() | 471 public int getRemotePort() |
472 { | 472 { |
473 if (_socket==null) | 473 if (_socket==null) |
474 return 0; | 474 return 0; |
475 return _remote==null?-1:_remote.getPort(); | 475 return _remote==null?-1:_remote.getPort(); |
476 } | 476 } |
477 | 477 |
478 /* ------------------------------------------------------------ */ | 478 /* ------------------------------------------------------------ */ |
479 /* | 479 /* |
480 * @see org.eclipse.io.EndPoint#getConnection() | 480 * @see org.eclipse.io.EndPoint#getConnection() |
481 */ | 481 */ |
482 public Object getTransport() | 482 public Object getTransport() |
483 { | 483 { |
484 return _channel; | 484 return _channel; |
485 } | 485 } |
486 | 486 |
487 /* ------------------------------------------------------------ */ | 487 /* ------------------------------------------------------------ */ |
488 public void flush() | 488 public void flush() |
489 throws IOException | 489 throws IOException |
490 { | 490 { |
491 } | 491 } |
492 | 492 |
493 /* ------------------------------------------------------------ */ | 493 /* ------------------------------------------------------------ */ |
494 public int getMaxIdleTime() | 494 public int getMaxIdleTime() |
495 { | 495 { |
496 return _maxIdleTime; | 496 return _maxIdleTime; |
497 } | 497 } |
498 | 498 |
499 /* ------------------------------------------------------------ */ | 499 /* ------------------------------------------------------------ */ |
500 /** | 500 public void setMaxIdleTime(int timeMs) throws IOException |
501 * @see org.eclipse.jetty.io.bio.StreamEndPoint#setMaxIdleTime(int) | 501 { |
502 */ | 502 if (_socket!=null && timeMs!=_maxIdleTime) |
503 public void setMaxIdleTime(int timeMs) throws IOException | 503 _socket.setSoTimeout(timeMs>0?timeMs:0); |
504 { | 504 _maxIdleTime=timeMs; |
505 if (_socket!=null && timeMs!=_maxIdleTime) | 505 } |
506 _socket.setSoTimeout(timeMs>0?timeMs:0); | |
507 _maxIdleTime=timeMs; | |
508 } | |
509 } | 506 } |