Lines 392-429
Link Here
|
392 |
* @todo Implement this java.nio.channels.WritableByteChannel method |
392 |
* @todo Implement this java.nio.channels.WritableByteChannel method |
393 |
*/ |
393 |
*/ |
394 |
public int write(ByteBuffer src) throws IOException { |
394 |
public int write(ByteBuffer src) throws IOException { |
395 |
//make sure we can handle expand, and that we only use on buffer |
395 |
if ( src == this.netOutBuffer ) { |
396 |
if ( src != bufHandler.getWriteBuffer() ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler."); |
396 |
//we can get here through a recursive call |
397 |
//are we closing or closed? |
397 |
//by using the NioBlockingSelector |
398 |
if ( closing || closed) throw new IOException("Channel is in closing state."); |
398 |
int written = sc.write(src); |
399 |
|
|
|
400 |
//the number of bytes written |
401 |
int written = 0; |
402 |
|
403 |
if (!flush(netOutBuffer)) { |
404 |
//we haven't emptied out the buffer yet |
405 |
return written; |
399 |
return written; |
|
|
400 |
} else { |
401 |
//make sure we can handle expand, and that we only use on buffer |
402 |
if ( src != bufHandler.getWriteBuffer() ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler."); |
403 |
//are we closing or closed? |
404 |
if ( closing || closed) throw new IOException("Channel is in closing state."); |
405 |
|
406 |
//the number of bytes written |
407 |
int written = 0; |
408 |
|
409 |
if (!flush(netOutBuffer)) { |
410 |
//we haven't emptied out the buffer yet |
411 |
return written; |
412 |
} |
413 |
|
414 |
/* |
415 |
* The data buffer is empty, we can reuse the entire buffer. |
416 |
*/ |
417 |
netOutBuffer.clear(); |
418 |
|
419 |
SSLEngineResult result = sslEngine.wrap(src, netOutBuffer); |
420 |
written = result.bytesConsumed(); |
421 |
netOutBuffer.flip(); |
422 |
|
423 |
if (result.getStatus() == Status.OK) { |
424 |
if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); |
425 |
} else { |
426 |
throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()); |
427 |
} |
428 |
|
429 |
//force a flush |
430 |
flush(netOutBuffer); |
431 |
return written; |
406 |
} |
432 |
} |
407 |
|
|
|
408 |
/* |
409 |
* The data buffer is empty, we can reuse the entire buffer. |
410 |
*/ |
411 |
netOutBuffer.clear(); |
412 |
|
413 |
SSLEngineResult result = sslEngine.wrap(src, netOutBuffer); |
414 |
written = result.bytesConsumed(); |
415 |
netOutBuffer.flip(); |
416 |
|
417 |
if (result.getStatus() == Status.OK) { |
418 |
if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); |
419 |
} else { |
420 |
throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()); |
421 |
} |
422 |
|
423 |
//force a flush |
424 |
flush(netOutBuffer); |
425 |
|
426 |
return written; |
427 |
} |
433 |
} |
428 |
|
434 |
|
429 |
/** |
435 |
/** |