Package java.nio.channels

Examples of java.nio.channels.Channel


        return context.getRuntime().newString(sb.toString());
    }

    @JRubyMethod(backtrace = true)
    public IRubyObject connect_nonblock(ThreadContext context, IRubyObject arg) {
        Channel socketChannel = getChannel();
        try {
            if (socketChannel instanceof AbstractSelectableChannel) {
                ((AbstractSelectableChannel) socketChannel).configureBlocking(false);
                connect(context, arg);
            } else {
View Full Code Here


            IRubyObject addr = sockaddr.pop(context);
            IRubyObject port = sockaddr.pop(context);
            InetSocketAddress iaddr = new InetSocketAddress(
                    addr.convertToString().toString(), RubyNumeric.fix2int(port));

            Channel socketChannel = getChannel();
            if (socketChannel instanceof SocketChannel) {
                if(!((SocketChannel) socketChannel).connect(iaddr)) {
                    throw context.getRuntime().newErrnoEINPROGRESSError();
                }
            } else if (socketChannel instanceof DatagramChannel) {
                ((DatagramChannel)socketChannel).connect(iaddr);
            } else {
                throw getRuntime().newErrnoENOPROTOOPTError();
            }
        } catch(AlreadyConnectedException e) {
            throw context.getRuntime().newErrnoEISCONNError();
        } catch(ConnectionPendingException e) {
            Channel socketChannel = getChannel();
            if (socketChannel instanceof SocketChannel) {
                try {
                    if (((SocketChannel) socketChannel).finishConnect()) {
                        throw context.getRuntime().newErrnoEISCONNError();
                    }
View Full Code Here

            IRubyObject addr = sockaddr.pop(context);
            IRubyObject port = sockaddr.pop(context);
            InetSocketAddress iaddr = new InetSocketAddress(
                    addr.convertToString().toString(), RubyNumeric.fix2int(port));

            Channel socketChannel = getChannel();
            if (socketChannel instanceof SocketChannel) {
                Socket socket = ((SocketChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else if (socketChannel instanceof DatagramChannel) {
                DatagramSocket socket = ((DatagramChannel)socketChannel).socket();
View Full Code Here

            context.getThread().afterBlockingCall();
        }
    }

    protected InetSocketAddress getLocalSocket(String caller) throws BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        if (socketChannel instanceof SocketChannel) {
            return (InetSocketAddress)((SocketChannel)socketChannel).socket().getLocalSocketAddress();
        } else if (socketChannel instanceof ServerSocketChannel) {
            return (InetSocketAddress)((ServerSocketChannel) socketChannel).socket().getLocalSocketAddress();
        } else if (socketChannel instanceof DatagramChannel) {
View Full Code Here

            return null;
        }
    }
   
    protected InetSocketAddress getRemoteSocket() throws BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        if(socketChannel instanceof SocketChannel) {
            return (InetSocketAddress)((SocketChannel)socketChannel).socket().getRemoteSocketAddress();
        } else {
            return null;
        }
View Full Code Here

            return null;
        }
    }

    private Socket asSocket() throws BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        if(!(socketChannel instanceof SocketChannel)) {
            throw getRuntime().newErrnoENOPROTOOPTError();
        }

        return ((SocketChannel)socketChannel).socket();
View Full Code Here

        return ((SocketChannel)socketChannel).socket();
    }

    private ServerSocket asServerSocket() throws BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        if(!(socketChannel instanceof ServerSocketChannel)) {
            throw getRuntime().newErrnoENOPROTOOPTError();
        }

        return ((ServerSocketChannel)socketChannel).socket();
View Full Code Here

        return ((ServerSocketChannel)socketChannel).socket();
    }

    private DatagramSocket asDatagramSocket() throws BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        if(!(socketChannel instanceof DatagramChannel)) {
            throw getRuntime().newErrnoENOPROTOOPTError();
        }

        return ((DatagramChannel)socketChannel).socket();
View Full Code Here

        return ((DatagramChannel)socketChannel).socket();
    }

    private IRubyObject getBroadcast(Ruby runtime) throws IOException, BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        return trueFalse(runtime, (socketChannel instanceof DatagramChannel) ? asDatagramSocket().getBroadcast() : false);
    }
View Full Code Here

        Channel socketChannel = getOpenChannel();
        return trueFalse(runtime, (socketChannel instanceof DatagramChannel) ? asDatagramSocket().getBroadcast() : false);
    }

    private void setBroadcast(IRubyObject val) throws IOException, BadDescriptorException {
        Channel socketChannel = getOpenChannel();
        if(socketChannel instanceof DatagramChannel) {
            asDatagramSocket().setBroadcast(asBoolean(val));
        }
    }
View Full Code Here

TOP

Related Classes of java.nio.channels.Channel

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.