Package java.nio.channels

Examples of java.nio.channels.SelectableChannel


            } else {
                throw runtime.newErrnoEAGAINError(channel.getClass().getName() + " does not support nonblocking");
            }
        }

        SelectableChannel selectable = (SelectableChannel)channel;

        synchronized (selectable.blockingLock()) {
            boolean oldBlocking = selectable.isBlocking();

            try {
                selectable.configureBlocking(false);

                try {
                    return doReceive(context, length);
                } finally {
                    selectable.configureBlocking(oldBlocking);
                }

            } catch(IOException e) {
                throw runtime.newIOErrorFromException(e);
            }
View Full Code Here


    @JRubyMethod
    public IRubyObject accept_nonblock(ThreadContext context) {
        Ruby runtime = context.runtime;

        SelectableChannel selectable = (SelectableChannel)channel;

        synchronized (selectable.blockingLock()) {
            boolean oldBlocking = selectable.isBlocking();

            try {
                selectable.configureBlocking(false);

                try {
                    UnixSocketChannel socketChannel = ((UnixServerSocketChannel) channel).accept();

                    RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));

                    sock.channel = socketChannel;
                    sock.fpath = "";

                    sock.init_sock(context.runtime);

                    return sock;

                } finally {
                    selectable.configureBlocking(oldBlocking);
                }

            } catch (IOException ioe) {
                if (ioe.getMessage().equals("accept failed: Resource temporarily unavailable")) {
                    if (runtime.is1_9()) {
View Full Code Here

                OpenFile of = rubyIO.getOpenFile();
                Stream stream = of.getMainStreamSafe();
                if (stream instanceof ChannelStream) {
                    ChannelStream cStream = (ChannelStream)stream;
                    if (cStream.getDescriptor().getChannel() instanceof SelectableChannel)  {
                        SelectableChannel selChannel = (SelectableChannel)cStream.getDescriptor().getChannel();

                        ((RubyObject)recv).extend(
                                new IRubyObject[]{((RubyModule)recv.getRuntime().getModule("Net").getConstant("BufferedIO")).getConstant("NativeImplementation")});
                        SelectableChannel sc = (SelectableChannel)(selChannel);
                        recv.dataWrapStruct(new NativeImpl(sc));
                    }
                }
            }
View Full Code Here

    }

    private RubyArray doAcceptNonblock(ThreadContext context, Channel channel) {
        try {
            if (channel instanceof SelectableChannel) {
                SelectableChannel selectable = (SelectableChannel)channel;

                synchronized (selectable.blockingLock()) {
                    boolean oldBlocking = selectable.isBlocking();

                    try {
                        selectable.configureBlocking(false);

                        RubySocket socket = doAccept(context, channel);
                        SocketChannel socketChannel = (SocketChannel)socket.getChannel();
                        InetSocketAddress addr = (InetSocketAddress)socketChannel.socket().getLocalSocketAddress();

                        return context.runtime.newArray(
                                socket,
                                Sockaddr.packSockaddrFromAddress(context, addr));
                    } finally {
                        selectable.configureBlocking(oldBlocking);
                    }
                }
            } else {
                throw getRuntime().newErrnoENOPROTOOPTError();
View Full Code Here

                             * http://developer.java.sun.com/developer/bugParade/bugs/4729342.html
                             */
                            Iterator iter = closing.iterator();

                            while (iter.hasNext()) {
                                SelectableChannel selectableChannel = (SelectableChannel) iter.next();
                                selectableChannel.close();
                            }
                            closing.clear();
                        }
                    }

View Full Code Here

   private void register() throws IOException {
      while(!pending.isEmpty()) {
         Action action = pending.poll();
        
         if(action != null) {
            SelectableChannel channel = action.getChannel();   
            ActionSet set = executing.remove(channel);
           
            if(set == null) {
               set = selecting.get(channel);
           
View Full Code Here

    * is not removed from the selector when cancellation is done.
    *
    * @param action this is the operation that is to be registered  
    */
   private void register(Action action) throws IOException {
      SelectableChannel channel = action.getChannel();
     
      if(channel.isOpen()) {           
         select(action);              
      }
   }  
View Full Code Here

    * @param action this is the operation that is to be registered
    *
    * @return this returns the selection key used for selection
    */
   private void select(Action action) throws IOException {
      SelectableChannel channel = action.getChannel();
      int interest = action.getInterest();
     
      if(interest > 0) {
         ActionSet set = selector.register(channel, interest)
        
View Full Code Here

        return new IoSessionIterator(selector.selectedKeys());
    }

    @Override
    protected void init(NioSession session) throws Exception {
        SelectableChannel ch = (SelectableChannel) session.getChannel();
        ch.configureBlocking(false);
        session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ, session));
    }
View Full Code Here

        interestOps = key.interestOps();
    } catch (CancelledKeyException e) {
        throw new ClosedAsynchronousChannelException();
    }

                SelectableChannel channel = asyncKey.channel();
               
                // These precondition checks don't belong here; they
                // should be refactored to AsyncSocketChannelImpl.
                // However, they need to occur inside the asyncKey
                // lock after we know the interest ops won't change,
View Full Code Here

TOP

Related Classes of java.nio.channels.SelectableChannel

Copyright © 2018 www.massapicom. 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.