Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 962:94498d6daf5b
remove SelectChannelEndPoint._interestOps
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Oct 2016 22:56:15 -0600 |
parents | 790c01734386 |
children | 4b6216fa9cec |
comparison
equal
deleted
inserted
replaced
961:790c01734386 | 962:94498d6daf5b |
---|---|
51 private final Runnable _handler = new Runnable() | 51 private final Runnable _handler = new Runnable() |
52 { | 52 { |
53 public void run() { handle(); } | 53 public void run() { handle(); } |
54 }; | 54 }; |
55 | 55 |
56 /** The desired value for {@link SelectionKey#interestOps()} */ | |
57 private int _interestOps; | |
58 | |
59 /** | 56 /** |
60 * The connection instance is the handler for any IO activity on the endpoint. | 57 * The connection instance is the handler for any IO activity on the endpoint. |
61 * There is a different type of connection for HTTP, AJP, WebSocket and | 58 * There is a different type of connection for HTTP, AJP, WebSocket and |
62 * ProxyConnect. The connection may change for an SCEP as it is upgraded | 59 * ProxyConnect. The connection may change for an SCEP as it is upgraded |
63 * from HTTP to proxy connect or websocket. | 60 * from HTTP to proxy connect or websocket. |
139 | 136 |
140 // Remove writeable op | 137 // Remove writeable op |
141 if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) | 138 if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) |
142 { | 139 { |
143 // Remove writeable op | 140 // Remove writeable op |
144 _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; | 141 int interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; |
145 _key.interestOps(_interestOps); | 142 _key.interestOps(interestOps); |
146 _writable = true; // Once writable is in ops, only removed with dispatch. | 143 _writable = true; // Once writable is in ops, only removed with dispatch. |
147 } | 144 } |
148 | 145 |
149 // If dispatched, then deregister interest | 146 // If dispatched, then deregister interest |
150 if (_state>=STATE_DISPATCHED) | 147 if (_state>=STATE_DISPATCHED) |
323 /** | 320 /** |
324 * Updates selection key. Adds operations types to the selection key as needed. No operations | 321 * Updates selection key. Adds operations types to the selection key as needed. No operations |
325 * are removed as this is only done during dispatch. This method records the new key and | 322 * are removed as this is only done during dispatch. This method records the new key and |
326 * schedules a call to doUpdateKey to do the keyChange | 323 * schedules a call to doUpdateKey to do the keyChange |
327 */ | 324 */ |
328 private void updateKey() | 325 private synchronized void updateKey() |
329 { | 326 { |
330 final boolean changed; | 327 if( getChannel().isOpen() && _key.isValid()) |
331 synchronized (this) | 328 { |
332 { | 329 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended()); |
333 int current_ops=-1; | 330 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable); |
334 if (getChannel().isOpen()) | 331 |
335 { | 332 int interestOps = |
336 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended()); | 333 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) |
337 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable); | 334 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); |
338 | 335 if( _key.interestOps() != interestOps ) { |
339 _interestOps = | 336 _key.interestOps(interestOps); |
340 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) | 337 _selectSet.getSelector().update(); |
341 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); | 338 } |
342 try | 339 } else { |
343 { | |
344 current_ops = ((_key.isValid())?_key.interestOps():-1); | |
345 } | |
346 catch(Exception e) | |
347 { | |
348 _key.cancel(); | |
349 LOG.trace("",e); | |
350 } | |
351 } | |
352 changed = _interestOps!=current_ops; | |
353 } | |
354 | |
355 if(changed) | |
356 { | |
357 doUpdateKey(); | |
358 _selectSet.getSelector().update(); | |
359 } | |
360 } | |
361 | |
362 | |
363 /* ------------------------------------------------------------ */ | |
364 /** | |
365 * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey | |
366 */ | |
367 synchronized void doUpdateKey() | |
368 { | |
369 if (getChannel().isOpen()) | |
370 { | |
371 _key.interestOps(_interestOps); | |
372 } | |
373 else | |
374 { | |
375 _key.cancel(); | 340 _key.cancel(); |
376 } | 341 // update needed? |
377 } | 342 } |
343 } | |
344 | |
378 | 345 |
379 private void handle() | 346 private void handle() |
380 { | 347 { |
381 try | 348 try |
382 { | 349 { |
476 } | 443 } |
477 else | 444 else |
478 { | 445 { |
479 keyString += "!"; | 446 keyString += "!"; |
480 } | 447 } |
481 return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}", | 448 return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%s}-{%s}", |
482 hashCode(), | 449 hashCode(), |
483 _socket.getRemoteSocketAddress(), | 450 _socket.getRemoteSocketAddress(), |
484 _socket.getLocalSocketAddress(), | 451 _socket.getLocalSocketAddress(), |
485 _state, | 452 _state, |
486 isOpen(), | 453 isOpen(), |
487 isInputShutdown(), | 454 isInputShutdown(), |
488 isOutputShutdown(), | 455 isOutputShutdown(), |
489 _readBlocked, | 456 _readBlocked, |
490 _writeBlocked, | 457 _writeBlocked, |
491 _writable, | 458 _writable, |
492 _interestOps, | |
493 keyString, | 459 keyString, |
494 _connection); | 460 _connection); |
495 } | 461 } |
496 | 462 |
497 /* ------------------------------------------------------------ */ | 463 /* ------------------------------------------------------------ */ |