Package java.nio.channels

Examples of java.nio.channels.SocketChannel.finishConnect()


        // Why we just have to do this once, here
        updateNow();
        for (SelectionKey k : selected) {
            SocketChannel sc = ((SocketChannel) k.channel());
            if ((k.readyOps() & SelectionKey.OP_CONNECT) != 0) {
                if (sc.finishConnect()) {
                    updateLastSendAndHeard();
                    sendThread.primeConnection();
                }
            } else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) {
                doIO(pendingQueue, outgoingQueue);
View Full Code Here


                    // Why we just have to do this once, here
                    now = System.currentTimeMillis();
                    for (SelectionKey k : selected) {
                        SocketChannel sc = ((SocketChannel) k.channel());
                        if ((k.readyOps() & SelectionKey.OP_CONNECT) != 0) {
                            if (sc.finishConnect()) {
                                lastHeard = now;
                                lastSend = now;
                                primeConnection(k);
                                LOG.info("Server connection successful");
                            }
View Full Code Here

            SocketChannel ch = ( SocketChannel ) key.channel();
            ConnectionRequest entry = ( ConnectionRequest ) key.attachment();

            try
            {
                ch.finishConnect();
                SocketSession session = newSession( ch, entry.handler );
                entry.session = session;
            }
            catch( Throwable e )
            {
View Full Code Here

            if (!key.isConnectable()) {
              return;
            }
   
            try {
              channel.finishConnect();
              final SelectionKey selectionKey = channel.register(selector, 0);
             
              final LinkedList<ByteBuffer> toWriteQueue = new LinkedList<ByteBuffer>();
 
              selectionKey.attach(new SelectionKeyVisitor() {
View Full Code Here

              outboundChannel.configureBlocking(false);
              // not so useful because it's 2 hours timeout :(
              outboundChannel.socket().setKeepAlive(true);
              final Address clientAddress = new Address(outboundChannel.socket().getInetAddress().getHostAddress(), outboundChannel.socket().getPort());
              //%% System.out.println("Client connected: " + clientAddress); //T ODO rm
              outboundChannel.finishConnect();
              final SelectionKey selectionKey = outboundChannel.register(selector, 0);
             
              final LinkedList<ByteBuffer> toWriteQueue = new LinkedList<ByteBuffer>();
             
              final CloseableByteBufferHandler read = listening.connected(clientAddress, new CloseableByteBufferHandler() {
View Full Code Here

            try {
                // Do this nonblocking so we can be interrupted
                channel.configureBlocking(false);
                channel.connect( new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort) );
                context.getThread().select(channel, this, SelectionKey.OP_CONNECT);
                channel.finishConnect();

                // only try to set blocking back if we succeeded to finish connecting
                channel.configureBlocking(true);

                initSocket(newChannelFD(runtime, channel));
View Full Code Here

                } else {
                    SocketChannel connected = getServerSocketChannel().accept();
                    if (connected == null) continue;

                    connected.finishConnect();

                    // Force the client socket to be blocking
                    synchronized (connected.blockingLock()) {
                        connected.configureBlocking(false);
                        connected.configureBlocking(true);
View Full Code Here

                SocketChannel socket = (SocketChannel)channel;
                boolean result;
               
                if (socket.isConnectionPending()) {
                    // connection initiated but not finished
                    result = socket.finishConnect();
                } else {
                    result = socket.connect(addr);
                }

                if(!result) {
View Full Code Here

          if (selKey.isValid() && selKey.isConnectable()) {
            // if this socket throws an exception (e.g., connection refused),
            // print error msg and skip it.
            try {
              SocketChannel sChannel = (SocketChannel)selKey.channel();
              sChannel.finishConnect();
            } catch (Exception e) {
              stats.incNumConnectErrorServers();
              String err = String.format("socket %d connects to server %s " +
                "error: %s",
                index, servers.get(index).toString(), e.toString());
View Full Code Here

      final SocketChannel forwarderChannel = SocketChannel.open(address.getAddress());
      if (forwarderChannel == null)
        throw new IOException("Unable to create channel.");
      synchronized(forwarderChannel)
      {
        if(!forwarderChannel.finishConnect())
          throw new HTTPException(HTTPStatus.S500_INTERNAL_ERROR);
        final HTTPForwarder forwarder=new HTTPForwarder(this, server, forwarderChannel);
        forwarderChannel.configureBlocking (false);
        final String webContext=address.getContext();
        final StringBuilder urlPage=new StringBuilder("");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.