Package org.jruby.util.io

Examples of org.jruby.util.io.ModeFlags


                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();
        } catch(UnknownHostException e) {
View Full Code Here


     * @param channel the channel to examine for capabilities
     * @return the mode flags
     * @throws org.jruby.util.io.InvalidValueException
     */
    private static ModeFlags getModesFromChannel(Channel channel) throws InvalidValueException {
        ModeFlags modes;
        if (channel instanceof ReadableByteChannel) {
            if (channel instanceof WritableByteChannel) {
                modes = new ModeFlags(RDWR);
            } else {
                modes = new ModeFlags(RDONLY);
            }
        } else if (channel instanceof WritableByteChannel) {
            modes = new ModeFlags(WRONLY);
        } else {
            // FIXME: I don't like this
            modes = new ModeFlags(RDWR);
        }
       
        return modes;
    }
View Full Code Here

       
        // continue with normal initialization
        openFile = new OpenFile();
       
        try {
            openFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, new ModeFlags(ModeFlags.RDONLY)));
            openFile.setPipeStream(ChannelStream.fdopen(runtime, descriptor, new ModeFlags(ModeFlags.WRONLY)));
            openFile.getPipeStream().setSync(true);
        } catch (org.jruby.util.io.InvalidValueException ex) {
            throw runtime.newErrnoEINVALError();
        }
        openFile.setMode(OpenFile.READWRITE | OpenFile.SYNC);
View Full Code Here

                channel = SocketChannel.open();
            } else if(soType == SOCK_DGRAM) {
                channel = DatagramChannel.open();
            }
           
            initSocket(context.getRuntime(), new ChannelDescriptor(channel, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
        } catch (InvalidValueException ex) {
            throw context.getRuntime().newErrnoEINVALError();
        } catch(IOException e) {
            throw sockerr(context.getRuntime(), "initialize: " + e.toString());
        }
View Full Code Here

                }
            }

            socket_address = new InetSocketAddress(addr, portInt);
            ssc.socket().bind(socket_address);
            initSocket(context.getRuntime(), new ChannelDescriptor(ssc, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
        } catch (InvalidValueException ex) {
            throw context.getRuntime().newErrnoEINVALError();
        } catch(UnknownHostException e) {
            throw sockerr(context.getRuntime(), "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(context.getRuntime(), new ChannelDescriptor(connected, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
                    } catch (InvalidValueException ex) {
                        throw context.getRuntime().newErrnoEINVALError();
                    }
                    return socket;
                }
View Full Code Here

                // no connection immediately accepted, let them try again
                throw context.getRuntime().newErrnoEAGAINError("Resource temporarily unavailable");
            } else {
                try {
                    // otherwise one key has been selected (ours) so we get the channel and hand it off
                    socket.initSocket(context.getRuntime(), new ChannelDescriptor(ssc.accept(), RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
                } catch (InvalidValueException ex) {
                    throw context.getRuntime().newErrnoEINVALError();
                }
                return socket;
            }
View Full Code Here

    public FileDescriptorIO(Ruby runtime, RubyClass klass) {
        super(runtime, klass);
    }
    public FileDescriptorIO(Ruby runtime, IRubyObject fd) {
        super(runtime, FFIProvider.getModule(runtime).fastGetClass(CLASS_NAME));
        ModeFlags modes;
        try {
            modes = new ModeFlags(ModeFlags.RDWR);
        } catch (InvalidValueException ex) {
            throw new RuntimeException(ex);
        }
        openFile.setMainStream(new ChannelStream(getRuntime(),
                new ChannelDescriptor(Factory.getInstance().newByteChannel(RubyNumeric.fix2int(fd)),
                getNewFileno(), modes, new java.io.FileDescriptor())));
        openFile.setPipeStream(openFile.getMainStream());
        openFile.setMode(modes.getOpenFileFlags());
        openFile.getMainStream().setSync(true);
    }
View Full Code Here

    @JRubyMethod(visibility = Visibility.PRIVATE)
    public IRubyObject initialize(ThreadContext context) {
        try {
            DatagramChannel channel = DatagramChannel.open();
            initSocket(context.getRuntime(), new ChannelDescriptor(channel, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
        } catch (org.jruby.util.io.InvalidValueException ex) {
            throw context.getRuntime().newErrnoEINVALError();
        } catch (ConnectException e) {
            throw context.getRuntime().newErrnoECONNREFUSEDError();
        } catch (UnknownHostException e) {
View Full Code Here

        getRuntime().checkSafeString(filename);
       
        path = filename.convertToString().getUnicodeValue();
       
        String modeString;
        ModeFlags modes;
        int perm;
       
        try {
            if ((args.length > 1 && args[1] instanceof RubyFixnum) || (args.length > 2 && !args[2].isNil())) {
                if (args[1] instanceof RubyFixnum) {
                    modes = new ModeFlags(RubyNumeric.num2int(args[1]));
                } else {
                    modeString = args[1].convertToString().toString();
                    modes = getIOModes(getRuntime(), modeString);
                }
                if (args.length > 2 && !args[2].isNil()) {
View Full Code Here

TOP

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

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.