public void registerForUse(Selector selector, Pipe<NetPayloadSchema>[] handshakeBegin, boolean isTLS) throws IOException { SocketChannel socket = getSocketChannel(); assert(null==socket || socket.finishConnect()); if (null==socket) { return;//not valid; } //logger.trace("now finished connection to : {} ",getSocketChannel().getRemoteAddress().toString()); //logger.info("is now valid connection {} ",this.id); SelectionKey tempkey = getSocketChannel().register(selector, SelectionKey.OP_READ, this); if (isTLS) { beginHandshakeNow(handshakeBegin); } isValid = true; //must be last, this connection can not be used until this key is not null; this.key = tempkey; }
public boolean isValid() { SocketChannel socketChannel = getSocketChannel(); if (null==socketChannel || (!socketChannel.isConnected()) ) { if (logDisconnects) { logger.info("{}:{} session {} is no longer connected. It was opened {} ago.", host,port,sessionId, Appendables.appendNearestTimeUnit(new StringBuilder(), System.nanoTime()-creationTimeNS).toString() ); } return false; } return isValid; }
private ClientConnection checkBuffers(int i, Pipe<NetPayloadSchema> pipe, ClientConnection cc) { if (!bufferChecked[i]) { if (null!=cc) { SocketChannel sc = cc.getSocketChannel(); if (null!=sc) { try { int minBufSize = Math.max(pipe.sizeOfBlobRing/4, //buffer should be as large as the full pipe so more can accumulate sc.getOption(StandardSocketOptions.SO_SNDBUF)); if (null!=buffers[i]) { logger.trace("buffer is {} and must be at least {}",buffers[i].capacity(), minBufSize); } if (null==buffers[i] || buffers[i].capacity()<minBufSize) { //logger.info("new direct buffer of size {} created old one was too small.",minBufSize); buffers[i] = ByteBuffer.allocateDirect(minBufSize); } bufferChecked[i] = true; } catch (IOException e) { return null; } } } } return cc; }
initSocket(this.getSocketChannel()); this.recBufferSize = this.getSocketChannel().getOption(StandardSocketOptions.SO_RCVBUF);
try { SocketChannel socketChannel = getSocketChannel(); if (socketChannel!=null) { boolean finishConnect = socketChannel.finishConnect();
ByteBuffer mappedByteBuffer = buffers[i]; if (cc!=null && cc.isValid() && !cc.isDisconnecting()) { SocketChannel sc = cc.getSocketChannel(); if (sc!=null) { if (connections[i].getSocketChannel().write(mappedByteBuffer)<=0) { break;//can't write now, try later. };
SocketChannel socketChannel = (SocketChannel)cc.getSocketChannel(); if (null != socketChannel) { try {