org.jruby.Ruby.newErrnoEAGAINReadableError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.7k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.jruby.Ruby.newErrnoEAGAINReadableError方法的一些代码示例,展示了Ruby.newErrnoEAGAINReadableError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newErrnoEAGAINReadableError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newErrnoEAGAINReadableError

Ruby.newErrnoEAGAINReadableError介绍

暂无

代码示例

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private RubySocket doAccept(ThreadContext context, Channel channel) {
  Ruby runtime = context.runtime;
  try {
    if (channel instanceof ServerSocketChannel) {
      ServerSocketChannel serverChannel = (ServerSocketChannel)getChannel();
      SocketChannel socket = serverChannel.accept();
      if (socket == null) {
        // This appears to be undocumented in JDK; null as a sentinel value
        // for a nonblocking accept with nothing available. We raise for Ruby.
        // indicates that no connection is available in non-blocking mode
        throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
      }
      RubySocket rubySocket = new RubySocket(runtime, runtime.getClass("Socket"));
      rubySocket.initFromServer(runtime, this, socket);
      return rubySocket;
    } else {
      throw runtime.newErrnoENOPROTOOPTError();
    }
  } catch (IllegalBlockingModeException ibme) {
    // indicates that no connection is available in non-blocking mode
    throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
  } catch(IOException e) {
    throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
  }
}

代码示例来源:origin: org.jruby/jruby-complete

private static IRubyObject doReceiveMulticast(RubyBasicSocket socket, final Ruby runtime, final boolean non_block,
  int length, ReceiveTuple tuple) throws IOException {
  ByteBuffer recv = ByteBuffer.wrap(new byte[length]);
  SocketAddress address;
  DatagramChannel channel = socket.multicastStateManager.getMulticastSocket().getChannel();
  address = channel.receive(recv);
  if (address == null) {
    if ( non_block ) return null; // :wait_readable or raise WaitReadable
    throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking");
  }
  InetSocketAddress sender = (InetSocketAddress) address;
  // see JRUBY-4678
  if (sender == null) {
    throw runtime.newErrnoECONNRESETError();
  }
  recv.flip();
  RubyString result = runtime.newString(new ByteList(recv.array(), recv.position(), recv.limit(), false));
  if (tuple != null) {
    tuple.result = result;
    tuple.sender = sender;
  }
  return result;
}

代码示例来源:origin: org.jruby/jruby-core

private static IRubyObject doReceiveMulticast(RubyBasicSocket socket, final Ruby runtime, final boolean non_block,
  int length, ReceiveTuple tuple) throws IOException {
  ByteBuffer recv = ByteBuffer.wrap(new byte[length]);
  SocketAddress address;
  DatagramChannel channel = socket.multicastStateManager.getMulticastSocket().getChannel();
  address = channel.receive(recv);
  if (address == null) {
    if ( non_block ) return null; // :wait_readable or raise WaitReadable
    throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking");
  }
  InetSocketAddress sender = (InetSocketAddress) address;
  // see JRUBY-4678
  if (sender == null) {
    throw runtime.newErrnoECONNRESETError();
  }
  recv.flip();
  RubyString result = runtime.newString(new ByteList(recv.array(), recv.position(), recv.limit(), false));
  if (tuple != null) {
    tuple.result = result;
    tuple.sender = sender;
  }
  return result;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private RubySocket doAccept(ThreadContext context, Channel channel) {
  Ruby runtime = context.runtime;
  try {
    if (channel instanceof ServerSocketChannel) {
      ServerSocketChannel serverChannel = (ServerSocketChannel)getChannel();
      SocketChannel socket = serverChannel.accept();
      if (socket == null) {
        // This appears to be undocumented in JDK; null as a sentinel value
        // for a nonblocking accept with nothing available. We raise for Ruby.
        // indicates that no connection is available in non-blocking mode
        throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
      }
      RubySocket rubySocket = new RubySocket(runtime, runtime.getClass("Socket"));
      rubySocket.initFromServer(runtime, this, socket);
      return rubySocket;
    } else {
      throw runtime.newErrnoENOPROTOOPTError();
    }
  } catch (IllegalBlockingModeException ibme) {
    // indicates that no connection is available in non-blocking mode
    throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
  } catch(IOException e) {
    throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private IRubyObject doReceive(Ruby runtime, int length, ReceiveTuple tuple) throws IOException {
  DatagramChannel channel = (DatagramChannel)getChannel();
  ByteBuffer buf = ByteBuffer.allocate(length);
  InetSocketAddress sender = (InetSocketAddress)channel.receive(buf);
  if (sender == null) {
    // noblocking receive
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError("recvfrom(2) would block");
    } else {
      throw runtime.newErrnoEAGAINError("recvfrom(2) would block");
    }
  }
  // see JRUBY-4678
  if (sender == null) {
    throw runtime.newErrnoECONNRESETError();
  }
  RubyString result = runtime.newString(new ByteList(buf.array(), 0, buf.position()));
  if (tuple != null) {
    tuple.result = result;
    tuple.sender = sender;
  }
  return result;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private IRubyObject doReceive(Ruby runtime, int length, ReceiveTuple tuple) throws IOException {
  DatagramChannel channel = (DatagramChannel)getChannel();
  ByteBuffer buf = ByteBuffer.allocate(length);
  InetSocketAddress sender = (InetSocketAddress)channel.receive(buf);
  if (sender == null) {
    // noblocking receive
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError("recvfrom(2) would block");
    } else {
      throw runtime.newErrnoEAGAINError("recvfrom(2) would block");
    }
  }
  // see JRUBY-4678
  if (sender == null) {
    throw runtime.newErrnoECONNRESETError();
  }
  RubyString result = runtime.newString(new ByteList(buf.array(), 0, buf.position()));
  if (tuple != null) {
    tuple.result = result;
    tuple.sender = sender;
  }
  return result;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public ByteList doReceiveNonblock(ThreadContext context, int length) {
  Ruby runtime = context.runtime;
  Channel channel = getChannel();
  if (!(channel instanceof SelectableChannel)) {
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError(channel.getClass().getName() + " does not support nonblocking");
    } 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);
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public ByteList doReceiveNonblock(ThreadContext context, int length) {
  Ruby runtime = context.runtime;
  Channel channel = getChannel();
  if (!(channel instanceof SelectableChannel)) {
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError(channel.getClass().getName() + " does not support nonblocking");
    } 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);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

protected final ByteList doReadNonblock(ThreadContext context, final ByteBuffer buffer) {
  Channel channel = getChannel();
  if ( ! (channel instanceof SelectableChannel) ) {
    throw context.runtime.newErrnoEAGAINReadableError(channel.getClass().getName() + " does not support nonblocking");
  }
  SelectableChannel selectable = (SelectableChannel) channel;
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        return doRead(context, buffer);
      }
      finally {
        selectable.configureBlocking(oldBlocking);
      }
    }
    catch (IOException e) {
      throw context.runtime.newIOErrorFromException(e);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-core

protected final ByteList doReadNonblock(ThreadContext context, final ByteBuffer buffer) {
  Channel channel = getChannel();
  if ( ! (channel instanceof SelectableChannel) ) {
    throw context.runtime.newErrnoEAGAINReadableError(channel.getClass().getName() + " does not support nonblocking");
  }
  SelectableChannel selectable = (SelectableChannel) channel;
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        return doRead(context, buffer);
      }
      finally {
        selectable.configureBlocking(oldBlocking);
      }
    }
    catch (IOException e) {
      throw context.runtime.newIOErrorFromException(e);
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private IRubyObject doReceiveMulticast(Ruby runtime, int length, ReceiveTuple tuple) throws IOException {
  byte[] buf2 = new byte[length];
  DatagramPacket recv = new DatagramPacket(buf2, buf2.length);
  MulticastSocket ms = this.multicastStateManager.getMulticastSocket();
  try {
    ms.receive(recv);
  } catch (IllegalBlockingModeException ibme) {
    // MulticastSocket does not support nonblocking
    // TODO: Use Java 7 NIO.2 DatagramChannel to do multicast
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking");
    } else {
      throw runtime.newErrnoEAGAINError("multicast UDP does not support nonblocking");
    }
  }
  InetSocketAddress sender = (InetSocketAddress) recv.getSocketAddress();
  // see JRUBY-4678
  if (sender == null) {
    throw runtime.newErrnoECONNRESETError();
  }
  RubyString result = runtime.newString(new ByteList(recv.getData(), 0, recv.getLength()));
  if (tuple != null) {
    tuple.result = result;
    tuple.sender = sender;
  }
  return result;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@JRubyMethod
public IRubyObject recv_nonblock(ThreadContext context, IRubyObject _length) {
  Ruby runtime = context.runtime;
  ByteList bytes = doReceiveNonblock(context, RubyNumeric.fix2int(_length));
  if (bytes == null) {
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError("recvfrom(2)");
    } else {
      throw runtime.newErrnoEAGAINError("recvfrom(2)");
    }
  }
  return RubyString.newString(runtime, bytes);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod
public IRubyObject recv_nonblock(ThreadContext context, IRubyObject _length) {
  Ruby runtime = context.runtime;
  ByteList bytes = doReceiveNonblock(context, RubyNumeric.fix2int(_length));
  if (bytes == null) {
    if (runtime.is1_9()) {
      throw runtime.newErrnoEAGAINReadableError("recvfrom(2)");
    } else {
      throw runtime.newErrnoEAGAINError("recvfrom(2)");
    }
  }
  return RubyString.newString(runtime, bytes);
}

代码示例来源:origin: org.jruby/jruby-complete

public IRubyObject accept_nonblock(ThreadContext context, Ruby runtime, boolean ex) {
  SelectableChannel selectable = (SelectableChannel)getChannel();
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        UnixSocketChannel socketChannel = ((UnixServerSocketChannel) selectable).accept();
        if (socketChannel == null) {
          if (!ex) return runtime.newSymbol("wait_readable");
          throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
        }
        RubyUNIXSocket sock = (RubyUNIXSocket)(Helpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
        sock.init_sock(context.runtime, socketChannel, "");
        return sock;
      } finally {
        selectable.configureBlocking(oldBlocking);
      }
    } catch (IOException ioe) {
      if (ioe.getMessage().equals("accept failed: Resource temporarily unavailable")) {
        if (!ex) return runtime.newSymbol("wait_readable");
        throw runtime.newErrnoEAGAINReadableError("accept");
      }
      throw context.runtime.newIOErrorFromException(ioe);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-core

public static IRubyObject doAccept(RubySocket sock, ThreadContext context, boolean ex) {
  Ruby runtime = context.runtime;
  Channel channel = sock.getChannel();
  try {
    if (channel instanceof ServerSocketChannel) {
      ServerSocketChannel serverChannel = (ServerSocketChannel)sock.getChannel();
      SocketChannel socket = serverChannel.accept();
      if (socket == null) {
        // This appears to be undocumented in JDK; null as a sentinel value
        // for a nonblocking accept with nothing available. We raise for Ruby.
        // indicates that no connection is available in non-blocking mode
        if (!ex) return runtime.newSymbol("wait_readable");
        throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
      }
      RubySocket rubySocket = new RubySocket(runtime, runtime.getClass("Socket"));
      rubySocket.initFromServer(runtime, sock, socket);
      return runtime.newArray(rubySocket, new Addrinfo(runtime, runtime.getClass("Addrinfo"), socket.getRemoteAddress()));
    }
    throw runtime.newErrnoENOPROTOOPTError();
  }
  catch (IllegalBlockingModeException e) {
    // indicates that no connection is available in non-blocking mode
    if (!ex) return runtime.newSymbol("wait_readable");
    throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
  }
  catch (IOException e) {
    throw sockerr(runtime, e.getLocalizedMessage(), e);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

throw runtime.newErrnoEAGAINReadableError("Resource temporarily unavailable");

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(required = 1, optional = 3) // (length) required = 1 handled above
public IRubyObject recv_nonblock(ThreadContext context, IRubyObject[] args) {
  int argc = args.length;
  IRubyObject opts = ArgsUtil.getOptionsArg(context.runtime, args);
  if (opts != context.nil) argc--;
  IRubyObject length, flags, str;
  length = flags = context.nil; str = null;
  switch (argc) {
    case 3: str = args[2];
    case 2: flags = args[1];
    case 1: length = args[0];
  }
  // TODO: implement flags
  final ByteBuffer buffer = ByteBuffer.allocate(RubyNumeric.fix2int(length));
  ByteList bytes = doReadNonblock(context, buffer);
  if (bytes == null) {
    if (!extractExceptionArg(context, opts)) return context.runtime.newSymbol("wait_readable");
    throw context.runtime.newErrnoEAGAINReadableError("recvfrom(2)");
  }
  if (str != null && str != context.nil) {
    str = str.convertToString();
    ((RubyString) str).setValue(bytes);
    return str;
  }
  return RubyString.newString(context.runtime, bytes);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public IRubyObject doReadNonblock(ThreadContext context, IRubyObject[] args, boolean useException) {
  IRubyObject value = getPartial(context, args, true);
  if (value.isNil()) {
    throw context.runtime.newEOFError();
  }
  if (value instanceof RubyString) {
    RubyString str = (RubyString) value;
    if (str.isEmpty()) {
      Ruby ruby = context.runtime;
      if (useException) {
        if (ruby.is1_9()) {
          throw ruby.newErrnoEAGAINReadableError("");
        } else {
          throw ruby.newErrnoEAGAINError("");
        }
      } else {
        return ruby.fastNewSymbol("wait_readable");
      }
    }
  }
  return value;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public IRubyObject doReadNonblock(ThreadContext context, IRubyObject[] args, boolean useException) {
  IRubyObject value = getPartial(context, args, true);
  if (value.isNil()) {
    throw context.runtime.newEOFError();
  }
  if (value instanceof RubyString) {
    RubyString str = (RubyString) value;
    if (str.isEmpty()) {
      Ruby ruby = context.runtime;
      if (useException) {
        if (ruby.is1_9()) {
          throw ruby.newErrnoEAGAINReadableError("");
        } else {
          throw ruby.newErrnoEAGAINError("");
        }
      } else {
        return ruby.fastNewSymbol("wait_readable");
      }
    }
  }
  return value;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@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)(Helpers.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()) {
          throw runtime.newErrnoEAGAINReadableError("accept");
        } else {
          throw runtime.newErrnoEAGAINError("accept");
        }
      }
      throw context.runtime.newIOErrorFromException(ioe);
    }
  }
}

相关文章

微信公众号

最新文章

更多

Ruby类方法