/** * Performs a blocking write using the bytebuffer for data to be written and a selector to block. * If the <code>selector</code> parameter is null, then it will perform a busy write that could * take up a lot of CPU cycles. * @param buf ByteBuffer - the buffer containing the data, we will write as long as <code>(buf.hasRemaining()==true)</code> * @param socket SocketChannel - the socket to write data to * @param selector Selector - the selector to use for blocking, if null then a busy write will be initiated * @param writeTimeout long - the timeout for this write operation in milliseconds, -1 means no timeout * @return int - returns the number of bytes written * @throws EOFException if write returns -1 * @throws SocketTimeoutException if the write times out * @throws IOException if an IO Exception occurs in the underlying socket logic */ public int write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout) throws IOException { return write(buf,socket,selector,writeTimeout,true,null); }
/** * Performs a blocking write using the bytebuffer for data to be written and a selector to block. * If the <code>selector</code> parameter is null, then it will perform a busy write that could * take up a lot of CPU cycles. * @param buf ByteBuffer - the buffer containing the data, we will write as long as <code>(buf.hasRemaining()==true)</code> * @param socket SocketChannel - the socket to write data to * @param selector Selector - the selector to use for blocking, if null then a busy write will be initiated * @param writeTimeout long - the timeout for this write operation in milliseconds, -1 means no timeout * @return int - returns the number of bytes written * @throws EOFException if write returns -1 * @throws SocketTimeoutException if the write times out * @throws IOException if an IO Exception occurs in the underlying socket logic */ public int write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout) throws IOException { return write(buf,socket,selector,writeTimeout,true); }
/** * Performs a blocking write using the bytebuffer for data to be written and a selector to block. * If the <code>selector</code> parameter is null, then it will perform a busy write that could * take up a lot of CPU cycles. * @param buf ByteBuffer - the buffer containing the data, we will write as long as <code>(buf.hasRemaining()==true)</code> * @param socket SocketChannel - the socket to write data to * @param selector Selector - the selector to use for blocking, if null then a busy write will be initiated * @param writeTimeout long - the timeout for this write operation in milliseconds, -1 means no timeout * @return int - returns the number of bytes written * @throws EOFException if write returns -1 * @throws SocketTimeoutException if the write times out * @throws IOException if an IO Exception occurs in the underlying socket logic */ public int write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout) throws IOException { return write(buf,socket,selector,writeTimeout,true,null); }
/** * Performs a blocking write using the bytebuffer for data to be written and a selector to block. * If the <code>selector</code> parameter is null, then it will perform a busy write that could * take up a lot of CPU cycles. * @param buf ByteBuffer - the buffer containing the data, we will write as long as <code>(buf.hasRemaining()==true)</code> * @param socket SocketChannel - the socket to write data to * @param selector Selector - the selector to use for blocking, if null then a busy write will be initiated * @param writeTimeout long - the timeout for this write operation in milliseconds, -1 means no timeout * @return int - returns the number of bytes written * @throws EOFException if write returns -1 * @throws SocketTimeoutException if the write times out * @throws IOException if an IO Exception occurs in the underlying socket logic */ public int write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout) throws IOException { return write(buf,socket,selector,writeTimeout,true,null); }
/** * returns true if the network buffer has * been flushed out and is empty * @return boolean */ public boolean flush(boolean block, Selector s, long timeout,MutableInteger lastWrite) throws IOException { if (!block) { flush(netOutBuffer); } else { pool.write(netOutBuffer, this, s, timeout,block,lastWrite); } return !netOutBuffer.hasRemaining(); }
/** * returns true if the network buffer has * been flushed out and is empty * @return boolean */ @Override public boolean flush(boolean block, Selector s, long timeout,MutableInteger lastWrite) throws IOException { if (!block) { flush(netOutBuffer); } else { pool.write(netOutBuffer, this, s, timeout,block,lastWrite); } return !netOutBuffer.hasRemaining(); }
/** * Flush the channel. * * @param block Should a blocking write be used? * @param s * @param timeout * @return <code>true</code> if the network buffer has been flushed out and * is empty else <code>false</code> * @throws IOException */ @Override public boolean flush(boolean block, Selector s, long timeout) throws IOException { if (!block) { flush(netOutBuffer); } else { pool.write(netOutBuffer, this, s, timeout,block); } return !netOutBuffer.hasRemaining(); }
/** * Flush the channel. * * @param block Should a blocking write be used? * @param s * @param timeout * @return <code>true</code> if the network buffer has been flushed out and * is empty else <code>false</code> * @throws IOException */ @Override public boolean flush(boolean block, Selector s, long timeout) throws IOException { if (!block) { flush(netOutBuffer); } else { pool.write(netOutBuffer, this, s, timeout,block); } return !netOutBuffer.hasRemaining(); }
/** * Flush the channel. * * @param block Should a blocking write be used? * @param s * @param timeout * @param lastWrite * @return <code>true</code> if the network buffer has been flushed out and * is empty else <code>false</code> * @throws IOException */ @Override public boolean flush(boolean block, Selector s, long timeout,MutableInteger lastWrite) throws IOException { if (!block) { flush(netOutBuffer); } else { pool.write(netOutBuffer, this, s, timeout,block,lastWrite); } return !netOutBuffer.hasRemaining(); }
/** * Flush the channel. * * @param block Should a blocking write be used? * @param s The selector to use for blocking, if null then a busy * write will be initiated * @param timeout The timeout for this write operation in milliseconds, * -1 means no timeout * @return <code>true</code> if the network buffer has been flushed out and * is empty else <code>false</code> * @throws IOException If an I/O error occurs during the operation */ @Override public boolean flush(boolean block, Selector s, long timeout) throws IOException { if (!block) { flush(netOutBuffer); } else { pool.write(netOutBuffer, this, s, timeout, block); } return !netOutBuffer.hasRemaining(); }
@Override protected void output(byte[] src, int offset, int length) throws IOException { ByteBuffer writeBuffer = socket.getBufHandler() .getWriteBuffer(); writeBuffer.put(src, offset, length); writeBuffer.flip(); NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false); if ( att == null ) throw new IOException("Key must be cancelled"); long writeTimeout = att.getTimeout(); Selector selector = null; try { selector = pool.get(); } catch ( IOException x ) { //ignore } try { pool.write(writeBuffer, socket, selector, writeTimeout, true); }finally { if ( selector != null ) pool.put(selector); } writeBuffer.clear(); }
@Override protected void output(byte[] src, int offset, int length) throws IOException { ByteBuffer writeBuffer = socket.getBufHandler() .getWriteBuffer(); writeBuffer.put(src, offset, length); writeBuffer.flip(); NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false); if ( att == null ) throw new IOException("Key must be cancelled"); long writeTimeout = att.getTimeout(); Selector selector = null; try { selector = pool.get(); } catch ( IOException x ) { //ignore } try { pool.write(writeBuffer, socket, selector, writeTimeout, true, null); }finally { if ( selector != null ) pool.put(selector); } writeBuffer.clear(); }
written = pool.write(bytebuffer, socket, selector, writeTimeout, block,lastWrite);
written = pool.write(bytebuffer, socket, selector, writeTimeout, block);
@Override protected int output(byte[] src, int offset, int length, boolean block) throws IOException { NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment) socketWrapper.getSocket().getAttachment(false); if ( att == null ) throw new IOException("Key must be cancelled"); ByteBuffer writeBuffer = socketWrapper.getSocket().getBufHandler().getWriteBuffer(); writeBuffer.put(src, offset, length); writeBuffer.flip(); long writeTimeout = att.getWriteTimeout(); Selector selector = null; try { selector = pool.get(); } catch (IOException x) { //ignore } try { return pool.write(writeBuffer, socketWrapper.getSocket(), selector, writeTimeout, block); } finally { writeBuffer.clear(); if (selector != null) { pool.put(selector); } } }
written = getSelectorPool().write(bytebuffer, socket, selector, writeTimeout, block,lastWrite);
written = getSelectorPool().write(bytebuffer, socket, selector, writeTimeout, block,lastWrite);
written = pool.write(nioChannel.getBufHandler().getWriteBuffer(), nioChannel, selector, writeTimeout, true); } finally {
written = pool.write(channel.getBufHandler().getWriteBuffer(), channel, selector, writeTimeout, block); } finally {
@Override protected void doWrite(boolean block, ByteBuffer from) throws IOException { long writeTimeout = getWriteTimeout(); Selector selector = null; try { selector = pool.get(); } catch (IOException x) { // Ignore } try { pool.write(from, getSocket(), selector, writeTimeout, block); if (block) { // Make sure we are flushed do { if (getSocket().flush(true, selector, writeTimeout)) { break; } } while (true); } updateLastWrite(); } finally { if (selector != null) { pool.put(selector); } } // If there is data left in the buffer the socket will be registered for // write further up the stack. This is to ensure the socket is only // registered for write once as both container and user code can trigger // write registration. }