Ejemplo n.º 1
0
  @JRubyMethod(required = 1, optional = 1)
  public IRubyObject seek(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.runtime;

    checkFrozen();
    checkFinalized();

    int offset = RubyNumeric.num2int(args[0]);
    IRubyObject whence = context.nil;

    if (args.length > 1 && !args[0].isNil()) whence = args[1];

    checkOpen();

    switch (whence.isNil() ? 0 : RubyNumeric.num2int(whence)) {
      case 0:
        break;
      case 1:
        offset += ptr.pos;
        break;
      case 2:
        offset += ptr.string.size();
        break;
      default:
        throw runtime.newErrnoEINVALError("invalid whence");
    }

    if (offset < 0) throw runtime.newErrnoEINVALError("invalid seek value");

    ptr.pos = offset;

    return RubyFixnum.zero(runtime);
  }
Ejemplo n.º 2
0
  protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) {
    // 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);
  }
Ejemplo n.º 3
0
  protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) {
    // continue with normal initialization
    MakeOpenFile();

    try {
      openFile.setMainStream(
          ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.RDONLY)));
      openFile.setPipeStream(
          ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.WRONLY)));
      openFile.getPipeStream().setSync(true);

    } catch (org.jruby.util.io.InvalidValueException ex) {
      throw runtime.newErrnoEINVALError();
    }

    openFile.setMode(OpenFile.READWRITE | OpenFile.SYNC);

    // see rsock_init_sock in MRI; sockets are initialized to binary
    setAscii8bitBinmode();
  }