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

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

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

Ruby.newErrnoENOPROTOOPTError介绍

暂无

代码示例

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

@Override
public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt, IRubyObject val) {
  SocketLevel level = SocketUtils.levelFromArg(_level);
  SocketOption opt = SocketUtils.optionFromArg(_opt);
  switch(level) {
    case SOL_SOCKET:
      switch(opt) {
        case SO_KEEPALIVE: {
          // TODO: socket options
        }
        break;
        default:
          throw context.runtime.newErrnoENOPROTOOPTError();
      }
      break;
    default:
      throw context.runtime.newErrnoENOPROTOOPTError();
  }
  return context.runtime.newFixnum(0);
}

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

@Override
public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt, IRubyObject val) {
  SocketLevel level = levelFromArg(_level);
  SocketOption opt = optionFromArg(_opt);
  switch(level) {
    case SOL_SOCKET:
      switch(opt) {
        case SO_KEEPALIVE: {
          // TODO: socket options
        }
        break;
        default:
          throw context.runtime.newErrnoENOPROTOOPTError();
      }
      break;
    default:
      throw context.runtime.newErrnoENOPROTOOPTError();
  }
  return context.runtime.newFixnum(0);
}

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

@Override
public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt, IRubyObject val) {
  SocketLevel level = levelFromArg(_level);
  SocketOption opt = optionFromArg(_opt);
  switch(level) {
    case SOL_SOCKET:
      switch(opt) {
        case SO_KEEPALIVE: {
          // TODO: socket options
        }
        break;
        default:
          throw context.runtime.newErrnoENOPROTOOPTError();
      }
      break;
    default:
      throw context.runtime.newErrnoENOPROTOOPTError();
  }
  return context.runtime.newFixnum(0);
}

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

@Override
public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt, IRubyObject val) {
  SocketLevel level = SocketUtils.levelFromArg(_level);
  SocketOption opt = SocketUtils.optionFromArg(_opt);
  switch(level) {
    case SOL_SOCKET:
      switch(opt) {
        case SO_KEEPALIVE: {
          // TODO: socket options
        }
        break;
        default:
          throw context.runtime.newErrnoENOPROTOOPTError();
      }
      break;
    default:
      throw context.runtime.newErrnoENOPROTOOPTError();
  }
  return context.runtime.newFixnum(0);
}

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

private void doBind(ThreadContext context, Channel channel, InetSocketAddress iaddr, int backlog) {
    Ruby runtime = context.runtime;

    try {
      if (channel instanceof ServerSocketChannel) {
        ServerSocket socket = ((ServerSocketChannel)channel).socket();
        socket.bind(iaddr, backlog);

      } else {
        throw runtime.newErrnoENOPROTOOPTError();
      }

    } catch(UnknownHostException e) {
      throw SocketUtils.sockerr(runtime, "bind(2): unknown host");

    } catch(SocketException e) {
      handleSocketException(runtime, "bind", e);

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

    } catch (IllegalArgumentException iae) {
      throw SocketUtils.sockerr(runtime, iae.getMessage());

    }
  }
}// RubySocket

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

private void doBind(ThreadContext context, Channel channel, InetSocketAddress iaddr, int backlog) {
    Ruby runtime = context.runtime;

    try {
      if (channel instanceof ServerSocketChannel) {
        ServerSocket socket = ((ServerSocketChannel)channel).socket();
        socket.bind(iaddr, backlog);

      } else {
        throw runtime.newErrnoENOPROTOOPTError();
      }

    } catch(UnknownHostException e) {
      throw SocketUtils.sockerr(runtime, "bind(2): unknown host");

    } catch(SocketException e) {
      handleSocketException(runtime, "bind", e);

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

    } catch (IllegalArgumentException iae) {
      throw SocketUtils.sockerr(runtime, iae.getMessage());

    }
  }
}// RubySocket

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

private void doBind(ThreadContext context, Channel channel, InetSocketAddress iaddr, int backlog) {
    Ruby runtime = context.runtime;

    try {
      if (channel instanceof ServerSocketChannel) {
        ServerSocket socket = ((ServerSocketChannel)channel).socket();
        socket.bind(iaddr, backlog);
      }
      else {
        throw runtime.newErrnoENOPROTOOPTError();
      }
    }
    catch (UnknownHostException e) {
      throw SocketUtils.sockerr(runtime, "bind(2): unknown host");
    }
    catch (SocketException e) {
      handleSocketException(runtime, e, "bind(2)", iaddr);
    }
    catch (IOException e) {
      throw sockerr(runtime, "bind(2): name or service not known", e);
    }
    catch (IllegalArgumentException e) {
      throw sockerr(runtime, e.getMessage(), e);
    }
  }
}// RubySocket

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

private void doBind(ThreadContext context, Channel channel, InetSocketAddress iaddr, int backlog) {
    Ruby runtime = context.runtime;

    try {
      if (channel instanceof ServerSocketChannel) {
        ServerSocket socket = ((ServerSocketChannel)channel).socket();
        socket.bind(iaddr, backlog);
      }
      else {
        throw runtime.newErrnoENOPROTOOPTError();
      }
    }
    catch (UnknownHostException e) {
      throw SocketUtils.sockerr(runtime, "bind(2): unknown host");
    }
    catch (SocketException e) {
      handleSocketException(runtime, e, "bind(2)", iaddr);
    }
    catch (IOException e) {
      throw sockerr(runtime, "bind(2): name or service not known", e);
    }
    catch (IllegalArgumentException e) {
      throw sockerr(runtime, e.getMessage(), e);
    }
  }
}// RubySocket

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

protected void doBind(ThreadContext context, Channel channel, InetSocketAddress iaddr) {
  Ruby runtime = context.runtime;
  try {
    if (channel instanceof SocketChannel) {
      Socket socket = ((SocketChannel)channel).socket();
      socket.bind(iaddr);
    } else if (channel instanceof UnixSocketChannel) {
      // do nothing
    } else if (channel instanceof DatagramChannel) {
      DatagramSocket socket = ((DatagramChannel)channel).socket();
      socket.bind(iaddr);
    } else {
      throw runtime.newErrnoENOPROTOOPTError();
    }
  } catch(UnknownHostException e) {
    throw SocketUtils.sockerr(runtime, "bind(2): unknown host");
  } catch(SocketException e) {
    handleSocketException(runtime, "bind", e);
  } catch(IOException e) {
    throw SocketUtils.sockerr(runtime, "bind(2): name or service not known");
  } catch (IllegalArgumentException iae) {
    throw SocketUtils.sockerr(runtime, iae.getMessage());
  }
}

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

protected void doBind(ThreadContext context, Channel channel, InetSocketAddress iaddr) {
  Ruby runtime = context.runtime;
  try {
    if (channel instanceof SocketChannel) {
      Socket socket = ((SocketChannel)channel).socket();
      socket.bind(iaddr);
    } else if (channel instanceof UnixSocketChannel) {
      // do nothing
    } else if (channel instanceof DatagramChannel) {
      DatagramSocket socket = ((DatagramChannel)channel).socket();
      socket.bind(iaddr);
    } else {
      throw runtime.newErrnoENOPROTOOPTError();
    }
  } catch(UnknownHostException e) {
    throw SocketUtils.sockerr(runtime, "bind(2): unknown host");
  } catch(SocketException e) {
    handleSocketException(runtime, "bind", e);
  } catch(IOException e) {
    throw SocketUtils.sockerr(runtime, "bind(2): name or service not known");
  } catch (IllegalArgumentException iae) {
    throw SocketUtils.sockerr(runtime, iae.getMessage());
  }
}

代码示例来源: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: 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 RubyArray doAcceptNonblock(ThreadContext context, Channel channel) {
  try {
    if (channel instanceof SelectableChannel) {
      SelectableChannel selectable = (SelectableChannel)channel;
      synchronized (selectable.blockingLock()) {
        boolean oldBlocking = selectable.isBlocking();
        try {
          selectable.configureBlocking(false);
          RubySocket socket = doAccept(context, channel);
          SocketChannel socketChannel = (SocketChannel)socket.getChannel();
          InetSocketAddress addr = (InetSocketAddress)socketChannel.socket().getLocalSocketAddress();
          return context.runtime.newArray(
              socket,
              Sockaddr.packSockaddrFromAddress(context, addr));
        } finally {
          selectable.configureBlocking(oldBlocking);
        }
      }
    } else {
      throw getRuntime().newErrnoENOPROTOOPTError();
    }
  } catch(IOException e) {
    throw SocketUtils.sockerr(context.runtime, e.getLocalizedMessage());
  }
}

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

private RubyArray doAcceptNonblock(ThreadContext context, Channel channel) {
  try {
    if (channel instanceof SelectableChannel) {
      SelectableChannel selectable = (SelectableChannel)channel;
      synchronized (selectable.blockingLock()) {
        boolean oldBlocking = selectable.isBlocking();
        try {
          selectable.configureBlocking(false);
          RubySocket socket = doAccept(context, channel);
          SocketChannel socketChannel = (SocketChannel)socket.getChannel();
          InetSocketAddress addr = (InetSocketAddress)socketChannel.socket().getLocalSocketAddress();
          return context.runtime.newArray(
              socket,
              Sockaddr.packSockaddrFromAddress(context, addr));
        } finally {
          selectable.configureBlocking(oldBlocking);
        }
      }
    } else {
      throw getRuntime().newErrnoENOPROTOOPTError();
    }
  } catch(IOException e) {
    throw SocketUtils.sockerr(context.runtime, e.getLocalizedMessage());
  }
}

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

public static IRubyObject doAcceptNonblock(RubySocket sock, ThreadContext context, boolean ex) {
  try {
    Channel channel = sock.getChannel();
    if (channel instanceof SelectableChannel) {
      SelectableChannel selectable = (SelectableChannel)channel;
      synchronized (selectable.blockingLock()) {
        boolean oldBlocking = selectable.isBlocking();
        try {
          selectable.configureBlocking(false);
          IRubyObject socket = doAccept(sock, context, ex);
          if (!(socket instanceof RubySocket)) return socket;
          SocketChannel socketChannel = (SocketChannel)((RubySocket)socket).getChannel();
          InetSocketAddress addr = (InetSocketAddress)socketChannel.socket().getRemoteSocketAddress();
          return context.runtime.newArray(
              socket,
              Sockaddr.packSockaddrFromAddress(context, addr));
        } finally {
          selectable.configureBlocking(oldBlocking);
        }
      }
    }
    else {
      throw context.runtime.newErrnoENOPROTOOPTError();
    }
  }
  catch (IOException e) {
    throw sockerr(context.runtime, e.getLocalizedMessage(), e);
  }
}

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

private void doConnectNonblock(ThreadContext context, Channel channel, SocketAddress addr) {
  if (!(channel instanceof SelectableChannel)) {
    throw getRuntime().newErrnoENOPROTOOPTError();
  }
  SelectableChannel selectable = (SelectableChannel)channel;
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        doConnect(context, channel, addr);
      } finally {
        selectable.configureBlocking(oldBlocking);
      }
    } catch(ClosedChannelException e) {
      throw context.runtime.newErrnoECONNREFUSEDError();
    } catch(IOException e) {
      throw SocketUtils.sockerr(context.runtime, "connect(2): name or service not known");
    }
  }
}

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

private IRubyObject doConnectNonblock(ThreadContext context, SocketAddress addr, boolean ex) {
  Channel channel = getChannel();
  if ( ! (channel instanceof SelectableChannel) ) {
    throw context.runtime.newErrnoENOPROTOOPTError();
  }
  SelectableChannel selectable = (SelectableChannel) channel;
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        return doConnect(context, addr, ex);
      } finally {
        selectable.configureBlocking(oldBlocking);
      }
    }
    catch (ClosedChannelException e) {
      throw context.runtime.newErrnoECONNREFUSEDError();
    }
    catch (IOException e) {
      throw sockerr(context.runtime, "connect(2): name or service not known", e);
    }
  }
}

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

private IRubyObject doConnectNonblock(ThreadContext context, SocketAddress addr, boolean ex) {
  Channel channel = getChannel();
  if ( ! (channel instanceof SelectableChannel) ) {
    throw context.runtime.newErrnoENOPROTOOPTError();
  }
  SelectableChannel selectable = (SelectableChannel) channel;
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        return doConnect(context, addr, ex);
      } finally {
        selectable.configureBlocking(oldBlocking);
      }
    }
    catch (ClosedChannelException e) {
      throw context.runtime.newErrnoECONNREFUSEDError();
    }
    catch (IOException e) {
      throw sockerr(context.runtime, "connect(2): name or service not known", e);
    }
  }
}

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

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: com.ning.billing/killbill-osgi-bundles-jruby

private void doConnectNonblock(ThreadContext context, Channel channel, SocketAddress addr) {
  if (!(channel instanceof SelectableChannel)) {
    throw getRuntime().newErrnoENOPROTOOPTError();
  }
  SelectableChannel selectable = (SelectableChannel)channel;
  synchronized (selectable.blockingLock()) {
    boolean oldBlocking = selectable.isBlocking();
    try {
      selectable.configureBlocking(false);
      try {
        doConnect(context, channel, addr);
      } finally {
        selectable.configureBlocking(oldBlocking);
      }
    } catch(ClosedChannelException e) {
      throw context.runtime.newErrnoECONNREFUSEDError();
    } catch(IOException e) {
      throw SocketUtils.sockerr(context.runtime, "connect(2): name or service not known");
    }
  }
}

相关文章

Ruby类方法