Package com.firefly.net.buffer.SocketSendBufferPool

Examples of com.firefly.net.buffer.SocketSendBufferPool.SendBuffer


        final int writeSpinCount = config.getWriteSpinCount();
        synchronized (session.getWriteLock()) {
            session.setInWriteNowLoop(true);
            while (true) {
                Object obj = session.getCurrentWrite();
                SendBuffer buf = null;
                if (obj == null) {
                    obj = writeBuffer.poll();
                    session.setCurrentWrite(obj);
                    if (session.getCurrentWrite() == null) {
                        removeOpWrite = true;
                        session.setWriteSuspended(false);
                        break;
                    }
                    if (obj == Session.CLOSE_FLAG) {
                        open = false;
                    } else {
                        buf = sendBufferPool.acquire(obj);
                        session.setCurrentWriteBuffer(buf);
                    }
                } else {
                    if (obj == Session.CLOSE_FLAG)
                        open = false;
                    else
                        buf = session.getCurrentWriteBuffer();
                }

                try {
                    log.debug("0> session is open: {}", open);
                    if (!open) {
                        log.debug("receive close flag");
                        assert buf == null;

                        session.resetCurrentWriteAndWriteBuffer();
//                        buf = null;
//                        obj = null;
                        clearOpWrite(session);
                        close(session.getSelectionKey());
                        break;
                    }

                    long localWrittenBytes;
                    for (int i = writeSpinCount; i > 0; i--) {
                        localWrittenBytes = buf.transferTo(ch);
                        if (localWrittenBytes != 0) {
                            writtenBytes += localWrittenBytes;
                            break;
                        }
                        if (buf.finished()) {
                            break;
                        }
                    }

                    if (buf.finished()) {
                        // Successful write - proceed to the next message.
                        buf.release();
                        session.resetCurrentWriteAndWriteBuffer();
//                        obj = null;
//                        buf = null;
                    } else {
                        // Not written fully - perhaps the kernel buffer is
                        // full.
                        addOpWrite = true;
                        session.setWriteSuspended(true);
                        break;
                    }
                } catch (AsynchronousCloseException e) {
                    // Doesn't need a user attention - ignore.
                } catch (Throwable t) {
                    buf.release();
                    session.resetCurrentWriteAndWriteBuffer();
//                    buf = null;
//                    obj = null;
                    eventManager.executeExceptionTask(session, t);
                    if (t instanceof IOException) {
View Full Code Here


    final int writeSpinCount = WRITE_SPIN_COUNT;
    synchronized (session.getWriteLock()) {
      session.setInWriteNowLoop(true);
      while (true) {
        Object obj = session.getCurrentWrite();
        SendBuffer buf = null;
        if (obj == null) {
          obj = writeBuffer.poll();
          session.setCurrentWrite(obj);
          if (session.getCurrentWrite() == null) {
            removeOpWrite = true;
            session.setWriteSuspended(false);
            break;
          }
          if (obj == Session.CLOSE_FLAG) {
            open = false;
          } else {
            buf = sendBufferPool.acquire(obj);
            session.setCurrentWriteBuffer(buf);
          }
        } else {
          if (obj == Session.CLOSE_FLAG)
            open = false;
          else
            buf = session.getCurrentWriteBuffer();
        }

        try {
          log.debug("0> session is open: {}", open);
          if (!open) {
            log.debug("receive close flag");
            assert buf == null;

            session.resetCurrentWriteAndWriteBuffer();
            // buf = null;
            // obj = null;
            clearOpWrite(session);
            close(session.getSelectionKey());
            break;
          }

          long localWrittenBytes;
          for (int i = writeSpinCount; i > 0; i--) {
            localWrittenBytes = buf.transferTo(ch);
            if (localWrittenBytes != 0) {
              writtenBytes += localWrittenBytes;
              break;
            }
            if (buf.finished()) {
              break;
            }
          }

          if (buf.finished()) {
            // Successful write - proceed to the next message.
            buf.release();
            session.resetCurrentWriteAndWriteBuffer();
            // obj = null;
            // buf = null;
          } else {
            // Not written fully - perhaps the kernel buffer is
            // full.
            addOpWrite = true;
            session.setWriteSuspended(true);
            break;
          }
        } catch (AsynchronousCloseException e) {
          // Doesn't need a user attention - ignore.
        } catch (Throwable t) {
          buf.release();
          session.resetCurrentWriteAndWriteBuffer();
          // buf = null;
          // obj = null;
          eventManager.executeExceptionTask(session, t);
          if (t instanceof IOException) {
View Full Code Here

    final int writeSpinCount = WRITE_SPIN_COUNT;

    session.inWriteNowLoop = true;
    while (true) {
      Object obj = session.currentWrite;
      SendBuffer buf = null;
      if (obj == null) {
        obj = writeBuffer.poll();
        session.currentWrite = obj;
        if (session.currentWrite == null) {
          removeOpWrite = true;
          session.writeSuspended = false;
          break;
        }
        if (obj == Session.CLOSE_FLAG) {
          open = false;
        } else {
          buf = sendBufferPool.acquire(obj);
          session.currentWriteBuffer = buf;
        }
      } else {
        if (obj == Session.CLOSE_FLAG)
          open = false;
        else
          buf = session.currentWriteBuffer;
      }

      try {
        log.debug("0> session is open: {}", open);
        if (!open) {
          log.debug("receive close flag");
          assert buf == null;

          session.resetCurrentWriteAndWriteBuffer();
          buf = null;
          obj = null;
          clearOpWrite(session);
          close0(session.selectionKey);
          break;
        }

        long localWrittenBytes;
        for (int i = writeSpinCount; i > 0; i--) {
          localWrittenBytes = buf.transferTo(ch);
          if (localWrittenBytes != 0) {
            writtenBytes += localWrittenBytes;
            break;
          }
          if (buf.finished()) {
            break;
          }
        }

        if (buf.finished()) {
          // Successful write - proceed to the next message.
          buf.release();
          session.resetCurrentWriteAndWriteBuffer();
          obj = null;
          buf = null;
        } else {
          // Not written fully - perhaps the kernel buffer is
          // full.
          addOpWrite = true;
          session.writeSuspended = true;
          break;
        }
      } catch (AsynchronousCloseException e) {
        // Doesn't need a user attention - ignore.
      } catch (Throwable t) {
        if(buf != null)
          buf.release();
       
        session.resetCurrentWriteAndWriteBuffer();
        buf = null;
        obj = null;
        eventManager.executeExceptionTask(session, t);
View Full Code Here

TOP

Related Classes of com.firefly.net.buffer.SocketSendBufferPool.SendBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.