public void register(final NioChannel socket) { socket.setPoller(this); KeyAttachment key = keyCache.poll(); final KeyAttachment ka = key!=null?key:new KeyAttachment(); ka.reset(this,socket,getSocketProperties().getSoTimeout()); PollerEvent r = eventCache.poll(); ka.interestOps(SelectionKey.OP_READ);//this is what OP_REGISTER turns into. if ( r==null) r = new PollerEvent(socket,ka,OP_REGISTER); else r.reset(socket,ka,OP_REGISTER); addEvent(r); } public void cancelledKey(SelectionKey key, SocketStatus status, boolean dispatch) {
iterator.remove(); } else { attachment.access(); iterator.remove(); processKey(sk, attachment);
if ( att.getReadLatch()==null || att.getReadLatch().getCount()==0) att.startReadLatch(1); poller.add(att,SelectionKey.OP_READ, reference); if (readTimeout < 0) { att.awaitReadLatch(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } else { att.awaitReadLatch(readTimeout, TimeUnit.MILLISECONDS); if ( att.getReadLatch()!=null && att.getReadLatch().getCount()> 0) { att.resetReadLatch();
if (ka!=null) ka.setComet(false); socket.getPoller().cancelledKey(key, SocketStatus.ERROR); if (running && !paused) { log.error("",x); } else if (state == SocketState.LONG && ka != null && ka.isAsync() && ka.interestOps() > 0) { ka.getPoller().add(socket, ka.interestOps()); ka.getPoller().add(socket,handshake);
iterator.remove(); } else { attachment.access(); iterator.remove(); processKey(sk, attachment);
iterator.remove(); } else { attachment.access(); iterator.remove(); processKey(sk, attachment);
iterator.remove(); } else { attachment.access(); iterator.remove(); processKey(sk, attachment);
iterator.remove(); } else { attachment.access(); iterator.remove(); processKey(sk, attachment);
try { unreg(sk, attachment, sk.readyOps()); SendfileData sd = attachment.getSendfileData(); sc = attachment.getChannel(); sc.setSendFile(true); attachment.access(); sd.pos += written; sd.length -= written; attachment.access(); } else { log.debug("Send file complete for: "+sd.fileName); attachment.setSendfileData(null); try { sd.fchannel.close(); this.add(attachment.getChannel(),SelectionKey.OP_READ); } else { reg(sk,attachment,SelectionKey.OP_READ); add(attachment.getChannel(),SelectionKey.OP_WRITE); } else { reg(sk,attachment,SelectionKey.OP_WRITE);
SendfileData sd = attachment.getSendfileData(); if ( sd.fchannel == null ) { File f = new File(sd.fileName); sc = attachment.getChannel(); sc.setSendFile(true); WritableByteChannel wc = ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel()); attachment.access(); sd.pos += written; sd.length -= written; attachment.access(); } else { attachment.setSendfileData(null); try { sd.fchannel.close(); this.add(attachment.getChannel(),SelectionKey.OP_READ); } else { reg(sk,attachment,SelectionKey.OP_READ); } else if ( attachment.interestOps() == 0 && reg ) { if (log.isDebugEnabled()) { log.debug("OP_WRITE for sendilfe:"+sd.fileName); add(attachment.getChannel(),SelectionKey.OP_WRITE); } else {
try { unreg(sk, attachment, sk.readyOps()); SendfileData sd = attachment.getSendfileData(); sc = attachment.getChannel(); sc.setSendFile(true); attachment.access(); sd.pos += written; sd.length -= written; attachment.access(); } else { log.debug("Send file complete for: "+sd.fileName); attachment.setSendfileData(null); try { sd.fchannel.close(); this.add(attachment.getChannel(),SelectionKey.OP_READ); } else { reg(sk,attachment,SelectionKey.OP_READ); add(attachment.getChannel(),SelectionKey.OP_WRITE); } else { reg(sk,attachment,SelectionKey.OP_WRITE);
SendfileData sd = attachment.getSendfileData(); if ( sd.fchannel == null ) { File f = new File(sd.fileName); sc = attachment.getChannel(); sc.setSendFile(true); WritableByteChannel wc =(WritableByteChannel) ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel()); attachment.access(); sd.pos += written; sd.length -= written; attachment.access(); attachment.setSendfileData(null); try {sd.fchannel.close();}catch(Exception ignore){} if ( sd.keepAlive ) { this.add(attachment.getChannel(),SelectionKey.OP_READ); } else { reg(sk,attachment,SelectionKey.OP_READ); } else if ( attachment.interestOps() == 0 && reg ) { if (log.isDebugEnabled()) { log.debug("OP_WRITE for sendilfe:"+sd.fileName); add(attachment.getChannel(),SelectionKey.OP_WRITE); } else { reg(sk,attachment,SelectionKey.OP_WRITE);
SendfileData sd = attachment.getSendfileData(); if ( sd.fchannel == null ) { File f = new File(sd.fileName); sc = attachment.getChannel(); sc.setSendFile(true); WritableByteChannel wc = ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel()); attachment.access(); sd.pos += written; sd.length -= written; attachment.access(); attachment.setSendfileData(null); try {sd.fchannel.close();}catch(Exception ignore){} if ( sd.keepAlive ) { this.add(attachment.getChannel(),SelectionKey.OP_READ); } else { reg(sk,attachment,SelectionKey.OP_READ); } else if ( attachment.interestOps() == 0 && reg ) { if (log.isDebugEnabled()) { log.debug("OP_WRITE for sendilfe:"+sd.fileName); add(attachment.getChannel(),SelectionKey.OP_WRITE); } else { reg(sk,attachment,SelectionKey.OP_WRITE);
if ( ka == null ) { cancelledKey(key, SocketStatus.ERROR,false); //we don't support any keys without attachments } else if ( ka.getError() ) { cancelledKey(key, SocketStatus.ERROR,true);//TODO this is not yet being used } else if (ka.getComet() && ka.getCometNotify() ) { ka.setCometNotify(false); reg(key,ka,0);//avoid multiple calls, this gets reregistered after invocation if (!processSocket(ka.getChannel(), SocketStatus.OPEN, true)) processSocket(ka.getChannel(), SocketStatus.DISCONNECT, true); } else if ((ka.interestOps()&SelectionKey.OP_READ) == SelectionKey.OP_READ || (ka.interestOps()&SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) { long delta = now - ka.getLastAccess(); long timeout = ka.getTimeout(); boolean isTimedout = timeout > 0 && delta > timeout; if ( close ) { key.interestOps(0); ka.interestOps(0); //avoid duplicate stop calls processKey(key,ka); } else if (isTimedout) { key.interestOps(0); ka.interestOps(0); //avoid duplicate timeout calls cancelledKey(key, SocketStatus.TIMEOUT,true); } else if (ka.isAsync() || ka.getComet()) { if (close) { key.interestOps(0); ka.interestOps(0); //avoid duplicate stop calls processKey(key,ka);
KeyAttachment attachment = (KeyAttachment)sk.attachment(); try { attachment.access(); iterator.remove(); ; sk.interestOps(sk.interestOps() & (~sk.readyOps())); if ( sk.isReadable() ) { countDown(attachment.getReadLatch()); countDown(attachment.getWriteLatch()); countDown(attachment.getReadLatch()); countDown(attachment.getWriteLatch());
if ( att.getWriteLatch()==null || att.getWriteLatch().getCount()==0) att.startWriteLatch(1); poller.add(att,SelectionKey.OP_WRITE,reference); att.awaitWriteLatch(writeTimeout,TimeUnit.MILLISECONDS); }catch (InterruptedException ignore) { Thread.interrupted(); if ( att.getWriteLatch()!=null && att.getWriteLatch().getCount()> 0) { att.resetWriteLatch();