/** * Process given socket. */ protected boolean processSocket(NioChannel socket) { return processSocket(socket,null); }
/** * Process given socket for an event. */ protected boolean processSocket(NioChannel socket, SocketStatus status) { return processSocket(socket,status,true); }
public boolean dispatchForEvent(NioChannel socket, SocketStatus status, boolean dispatch) { if (dispatch && status == SocketStatus.OPEN_READ) { socket.getPoller().add(socket, OP_CALLBACK); } else { processSocket(socket,status,dispatch); } return true; }
public void add(final NioChannel socket, final int interestOps) { PollerEvent r = eventCache.poll(); if ( r==null) r = new PollerEvent(socket,null,interestOps); else r.reset(socket,null,interestOps); addEvent(r); if (close) { processSocket(socket, SocketStatus.STOP, false); } }
/** * Send an action to the connector. * * @param actionCode Type of the action * @param param Action parameter */ @Override protected void actionInternal(ActionCode actionCode, Object param) { if (actionCode == ActionCode.ASYNC_COMPLETE) { if (asyncStateMachine.asyncComplete()) { ((NioEndpoint)endpoint).processSocket(this.socket, SocketStatus.OPEN, false); } } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) { if (param == null) return; long timeout = ((Long)param).longValue(); final KeyAttachment ka = (KeyAttachment)socket.getAttachment(false); if (keepAliveTimeout > 0) { ka.setTimeout(timeout); } } else if (actionCode == ActionCode.ASYNC_DISPATCH) { if (asyncStateMachine.asyncDispatch()) { ((NioEndpoint)endpoint).processSocket(this.socket, SocketStatus.OPEN, true); } } }
/** * Send an action to the connector. * * @param actionCode Type of the action * @param param Action parameter */ @Override protected void actionInternal(ActionCode actionCode, Object param) { if (actionCode == ActionCode.ASYNC_COMPLETE) { if (asyncStateMachine.asyncComplete()) { ((NioEndpoint)endpoint).processSocket(this.socket, SocketStatus.OPEN, false); } } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) { if (param == null) return; long timeout = ((Long)param).longValue(); final KeyAttachment ka = (KeyAttachment)socket.getAttachment(false); if (keepAliveTimeout > 0) { ka.setTimeout(timeout); } } else if (actionCode == ActionCode.ASYNC_DISPATCH) { if (asyncStateMachine.asyncDispatch()) { ((NioEndpoint)endpoint).processSocket(this.socket, SocketStatus.OPEN, true); } } }
public void add(final NioChannel socket, final int interestOps) { PollerEvent r = eventCache.pop(); if ( r==null) r = new PollerEvent(socket,null,interestOps); else r.reset(socket,null,interestOps); if ( (interestOps&OP_CALLBACK) == OP_CALLBACK ) { nextExpiration = 0; //force the check for faster callback } addEvent(r); if (close) { processSocket(socket, SocketStatus.STOP, false); } }
if (!processSocket(channel, SocketStatus.OPEN)) processSocket(channel, SocketStatus.DISCONNECT); } else { if (!processSocket(channel, SocketStatus.OPEN)) processSocket(channel, SocketStatus.DISCONNECT); boolean close = (!processSocket(channel)); if (close) { cancelledKey(sk,SocketStatus.DISCONNECT,false);
if (!processSocket(channel, SocketStatus.OPEN, true)) processSocket(channel, SocketStatus.DISCONNECT, true); } else { if (!processSocket(channel, SocketStatus.OPEN, true)) processSocket(channel, SocketStatus.DISCONNECT, true); boolean close = (!processSocket(channel, null, true)); if (close) { cancelledKey(sk,SocketStatus.DISCONNECT,false);
if (!processSocket(attachment, SocketEvent.OPEN_READ, true)) { closeSocket = true; if (!processSocket(attachment, SocketEvent.OPEN_WRITE, true)) { closeSocket = true;
if (!processSocket(channel, SocketStatus.OPEN, true)) processSocket(channel, SocketStatus.DISCONNECT, true); } else { if (!processSocket(channel, SocketStatus.OPEN, true)) processSocket(channel, SocketStatus.DISCONNECT, true); boolean close = (!processSocket(channel, null, true)); if (close) { cancelledKey(sk,SocketStatus.DISCONNECT,false);
if (!processSocket(channel, SocketStatus.OPEN, true)) processSocket(channel, SocketStatus.DISCONNECT, true); } else { if (!processSocket(channel, SocketStatus.OPEN, true)) processSocket(channel, SocketStatus.DISCONNECT, true); boolean close = (!processSocket(channel, null, true)); if (close) { cancelledKey(sk,SocketStatus.DISCONNECT,false);
public void cancelledKey(SelectionKey key, SocketStatus status, boolean dispatch) { try { if ( key == null ) return;//nothing to do KeyAttachment ka = (KeyAttachment) key.attachment(); if (ka != null && ka.getComet() && status != null) { //the comet event takes care of clean up //processSocket(ka.getChannel(), status, dispatch); ka.setComet(false);//to avoid a loop if (status == SocketStatus.TIMEOUT ) { processSocket(ka.getChannel(), status, true); return; // don't close on comet timeout } else { processSocket(ka.getChannel(), status, false); //don't dispatch if the lines below are cancelling the key } } key.attach(null); if (ka!=null) handler.release(ka.getChannel()); if (key.isValid()) key.cancel(); if (key.channel().isOpen()) try {key.channel().close();}catch (Exception ignore){} try {if (ka!=null) ka.channel.close(true);}catch (Exception ignore){} try {if (ka!=null && ka.getSendfileData()!=null && ka.getSendfileData().fchannel!=null && ka.getSendfileData().fchannel.isOpen()) ka.getSendfileData().fchannel.close();}catch (Exception ignore){} if (ka!=null) ka.reset(); } catch (Throwable e) { if ( log.isDebugEnabled() ) log.error("",e); // Ignore } } /**
if (!processSocket(channel, SocketStatus.OPEN_READ, true)) { closeSocket = true; if (!processSocket(channel, SocketStatus.OPEN_WRITE, true)) { closeSocket = true;
/** * Add specified socket and associated pool to the poller. The socket will * be added to a temporary array, and polled first after a maximum amount * of time equal to pollTime (in most cases, latency will be much lower, * however). * * @param socket to add to the poller * @param interestOps Operations for which to register this socket with * the Poller */ public void add(final NioChannel socket, final int interestOps) { PollerEvent r = eventCache.pop(); if ( r==null) r = new PollerEvent(socket,null,interestOps); else r.reset(socket,null,interestOps); addEvent(r); if (close) { NioEndpoint.NioSocketWrapper ka = (NioEndpoint.NioSocketWrapper)socket.getAttachment(); processSocket(ka, SocketEvent.STOP, false); } }
if (processSocket(ka.getChannel(), status, true)) { return; // don't close on comet timeout processSocket(ka.getChannel(), status, false); //don't dispatch if the lines below are cancelling the key
reg(key,ka,0);//avoid multiple calls, this gets reregistered after invokation if (!processSocket(ka.getChannel(), SocketStatus.OPEN)) processSocket(ka.getChannel(), SocketStatus.DISCONNECT); }else if ((ka.interestOps()&SelectionKey.OP_READ) == SelectionKey.OP_READ || (ka.interestOps()&SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
if (processSocket(ka.getChannel(), status, true)) { return; // don't close on comet timeout processSocket(ka.getChannel(), status, false); //don't dispatch if the lines below are cancelling the key
ka.setComet(false);//to avoid a loop if (status == SocketStatus.TIMEOUT ) { if (processSocket(ka.getChannel(), status, true)) { return; // don't close on comet timeout processSocket(ka.getChannel(), status, false);
if (processSocket(ka.getChannel(), status, true)) { return; // don't close on comet timeout processSocket(ka.getChannel(), status, false); //don't dispatch if the lines below are cancelling the key