Package org.jruby.util.io

Examples of org.jruby.util.io.ChannelDescriptor


    }

    protected static ChannelDescriptor newChannelDescriptor(Ruby runtime, Channel channel) {
        ModeFlags modeFlags = newModeFlags(runtime, ModeFlags.RDWR);

        return new ChannelDescriptor(channel, modeFlags);
    }
View Full Code Here


    public RubyFile(Ruby runtime, String path, InputStream in) {
        super(runtime, runtime.getFile());
        this.path = path;
        try {
            this.openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(in))));
            this.openFile.setMode(openFile.getMainStreamSafe().getModes().getOpenFileFlags());
        } catch (BadDescriptorException e) {
            throw runtime.newErrnoEBADFError();
        } catch (InvalidValueException ex) {
            throw runtime.newErrnoEINVALError();
View Full Code Here

    public IRubyObject flock(ThreadContext context, IRubyObject lockingConstant) {
        Ruby runtime = context.runtime;
       
        // TODO: port exact behavior from MRI, and move most locking logic into ChannelDescriptor
        // TODO: for all LOCK_NB cases, return false if they would block
        ChannelDescriptor descriptor;
        try {
            descriptor = openFile.getMainStreamSafe().getDescriptor();
        } catch (BadDescriptorException e) {
            throw context.runtime.newErrnoEBADFError();
        }

        // null channel always succeeds for all locking operations
        if (descriptor.isNull()) return RubyFixnum.zero(runtime);

        if (descriptor.getChannel() instanceof FileChannel) {
            FileChannel fileChannel = (FileChannel)descriptor.getChannel();
            int lockMode = RubyNumeric.num2int(lockingConstant);

            checkSharedExclusive(runtime, openFile, lockMode);
   
            if (!lockStateChanges(currentLock, lockMode)) return RubyFixnum.zero(runtime);
View Full Code Here

        if (modes.isBinary()) readEncoding = ASCIIEncoding.INSTANCE;

        int umask = getUmaskSafe( getRuntime() );
        perm = perm - (perm & umask);

        ChannelDescriptor descriptor = sysopen(path, modes, perm);
        openFile.setMainStream(fdopen(descriptor, modes));
    }
View Full Code Here

        openFile.setMainStream(fopen(path, modes.getModeFlags()));
    }

    private ChannelDescriptor sysopen(String path, ModeFlags modes, int perm) {
        try {
            ChannelDescriptor descriptor = ChannelDescriptor.open(
                    getRuntime().getCurrentDirectory(),
                    path,
                    modes,
                    perm,
                    getRuntime().getPosix(),
View Full Code Here

            ssc = ServerSocketChannel.open();
            socket_address = new InetSocketAddress(addr, port);

            ssc.socket().bind(socket_address);

            initSocket(runtime, new ChannelDescriptor(ssc, newModeFlags(runtime, ModeFlags.RDWR)));

        } catch(UnknownHostException e) {
            throw SocketUtils.sockerr(runtime, "initialize: name or service not known");

        } catch(BindException e) {
View Full Code Here

                        connected.configureBlocking(false);
                        connected.configureBlocking(true);
                    }

                    // otherwise one key has been selected (ours) so we get the channel and hand it off
                    socket.initSocket(runtime, new ChannelDescriptor(connected, newModeFlags(runtime, ModeFlags.RDWR)));

                    return socket;
                }
            }
View Full Code Here

                    // no connection immediately accepted, let them try again
                    throw runtime.newErrnoEAGAINError("Resource temporarily unavailable");

                } else {
                    // otherwise one key has been selected (ours) so we get the channel and hand it off
                    socket.initSocket(context.runtime, new ChannelDescriptor(ssc.accept(), newModeFlags(runtime, ModeFlags.RDWR)));

                    return socket;
                }

            } catch(IOException e) {
View Full Code Here

                channel.finishConnect();

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

                initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR)));
                success = true;
            } catch (NoRouteToHostException nrthe) {
                throw runtime.newErrnoEHOSTUNREACHError("SocketChannel.connect");

            } catch(ConnectException e) {
View Full Code Here

    protected void init_sock(Ruby runtime) {
        try {
            ModeFlags modes = newModeFlags(runtime, ModeFlags.RDWR);

            openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(channel, modes)));
            openFile.setPipeStream(openFile.getMainStreamSafe());
            openFile.setMode(modes.getOpenFileFlags());
            openFile.getMainStreamSafe().setSync(true);

        } catch (BadDescriptorException e) {
View Full Code Here

TOP

Related Classes of org.jruby.util.io.ChannelDescriptor

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.