Package java.nio.channels

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


    void doAccept(SelectionKey key) throws IOException,  OutOfMemoryError {
      Connection c = null;
      ServerSocketChannel server = (ServerSocketChannel) key.channel();
      SocketChannel channel = server.accept();
      channel.configureBlocking(false);
      SelectionKey readKey = channel.register(selector, SelectionKey.OP_READ);
      c = new Connection(readKey, channel, System.currentTimeMillis());
      readKey.attach(c);
      synchronized (connectionList) {
        connectionList.add(numConnections, c);
View Full Code Here


                ArrayList<SelectionKey> selectedList = new ArrayList<SelectionKey>(selected);
                Collections.shuffle(selectedList);
                for (SelectionKey k : selectedList) {
                    if ((k.readyOps() & SelectionKey.OP_ACCEPT) != 0) {
                        SocketChannel sc = ((ServerSocketChannel) k.channel()).accept();
                        sc.configureBlocking(false);
                        SelectionKey sk = sc.register(selector, SelectionKey.OP_READ);
                        Cnxn cnxn = new Cnxn(sc, sk);
                        sk.attach(cnxn);
                        addCnxn(cnxn);
                    } else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) {
View Full Code Here

    ServerSocketChannel ssc = ServerSocketChannel.open();
    ssc.socket().bind(localAddr);

    SocketChannel sc = SocketChannel.open();
    sc.connect(localAddr);
    sc.configureBlocking(false);
    assertFalse(sc.isBlocking());

    ssc.accept().close();
    ssc.close();
    assertFalse(sc.isBlocking());
View Full Code Here

            if( localAddress != null )
            {
                ch.socket().bind( localAddress );
            }
   
            ch.configureBlocking( false );

            if( ch.connect( address ) )
            {
                SocketSession session = newSession( ch, handler );
                success = true;
View Full Code Here

            SocketChannel ch = session.getChannel();
            boolean registered;

            try
            {
                ch.configureBlocking( false );
                session.setSelectionKey( ch.register( selector,
                                                      SelectionKey.OP_READ,
                                                      session ) );
                registered = true;
            }
View Full Code Here

   
    void doAccept(SelectionKey key) throws IOException,  OutOfMemoryError {
      Connection c = null;
      ServerSocketChannel server = (ServerSocketChannel) key.channel();
      SocketChannel channel = server.accept();
      channel.configureBlocking(false);
      SelectionKey readKey = channel.register(selector, SelectionKey.OP_READ);
      c = new Connection(readKey, channel, System.currentTimeMillis());
      readKey.attach(c);
      synchronized (connectionList) {
        connectionList.add(numConnections, c);
View Full Code Here

        }

        if (localAddress != null) {
            ch.socket().bind(localAddress);
        }
        ch.configureBlocking(false);
        return ch;
    }

    /**
     * {@inheritDoc}
 
View Full Code Here

  protected final void doAccept() throws Exception
  {
    SocketChannel sc = channel().accept();
    try
    {
      sc.configureBlocking( false );
      acceptedChannel( sc );
    }
    catch ( EOFException e )
    {
      sc.close();
View Full Code Here

   */
  public StreamHandler newStreamHandler( InetSocketAddress addr,
    StreamHandlerFactory factory ) throws Exception
  {
    SocketChannel sc = SocketChannel.open();
    sc.configureBlocking( false );
    StreamHandler sh = factory.newStreamHandler( sc, true );
    register( sh );
    sc.connect( addr );
    return sh;
  }
View Full Code Here

    void doAccept(SelectionKey key) throws InterruptedException, IOException,  OutOfMemoryError {
      ServerSocketChannel server = (ServerSocketChannel) key.channel();
      SocketChannel channel;
      while ((channel = server.accept()) != null) {

        channel.configureBlocking(false);
        channel.socket().setTcpNoDelay(tcpNoDelay);
        channel.socket().setKeepAlive(true);
       
        Reader reader = getReader();
        Connection c = connectionManager.register(channel);
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.