Package java.nio.channels

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


  public void handleConnect(SelectionKey key) throws IOException {
    logger.debug("handle connect...");
    SocketChannel sc = (SocketChannel) channel;
    if (sc.isConnectionPending()) {
      try {
        sc.finishConnect();
        invokeConnectSuccessfulCallback();
        interestOps &= ~SelectionKey.OP_CONNECT;
        IOLoop.INSTANCE.updateHandler(channel, interestOps |= SelectionKey.OP_READ);
      } catch (ConnectException e) {
        logger.warn("Connect failed: {}", e.getMessage());
View Full Code Here


            public boolean
            selectSuccess(
              VirtualChannelSelector selector, SocketChannel sc, Object attachment)
            {
              try{
                if ( channel.finishConnect()){
                 
                  outgoing( channel );
                 
                  return( true );
                }else{
View Full Code Here

    SocketAddress address = new InetSocketAddress("localhost",port);
    SocketChannel channel = SocketChannel.open();
    channel.configureBlocking(false);
    if (! channel.connect(address)) {
      // we're willing to wait for about a second.
      for (int i = 0; (! channel.finishConnect()) && i < 4; i++) {
  try {
    getLogger().log(Level.FINE, "not connected; sleeping (" + i + ").");
    Thread.currentThread().sleep(250);
  } catch (Exception e) {
  }
View Full Code Here

                    java.net.Socket ss = (java.net.Socket)ch.socket();
                    Socket s = (Socket)key.attachment();
                    if (s != null)
                    {
//                        System.out.println(s + ": OnConnect");
                        ch.finishConnect();
                        s.SetConnecting(false);
                        s.GetKey().interestOps(SelectionKey.OP_READ);
                        s.OnConnect();
                    }
                }
View Full Code Here

                channel = SocketChannel.open();
                Socket socket = channel.socket();
                socket.bind(new InetSocketAddress(InetAddress.getByName(localHost), localPort));
                socket.connect(new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort));
            }
            channel.finishConnect();
            initSocket(context.getRuntime(), new ChannelDescriptor(channel, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
        } catch (InvalidValueException ex) {
            throw context.getRuntime().newErrnoEINVALError();
        } catch(ConnectException e) {
            throw context.getRuntime().newErrnoECONNREFUSEDError();
View Full Code Here

                    // we were woken up without being selected...poll for thread events and go back to sleep
                    context.pollThreadEvents();
                } else {
                    try {
                        SocketChannel connected = ssc.accept();
                        connected.finishConnect();
                       
                        //
                        // Force the client socket to be blocking
                        //
                        synchronized (connected.blockingLock()) {
View Full Code Here

   * process a connect complete selection
   */
  public void doConnect() {
    SocketChannel sc = (SocketChannel) sk.channel();
    try {
      sc.finishConnect();
      sk.interestOps(sk.interestOps() & ~SelectionKey.OP_CONNECT);
      log.fine("connect complete");
      state = Connection.OPEN;
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

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

            boolean success = false;
            try {
                ch.finishConnect();
                newSession(ch, entry.handler, entry.config, entry);
                success = true;
            } catch (Throwable e) {
                entry.setException(e);
            } finally {
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

                    // 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

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.