Ejemplo n.º 1
0
  @JRubyMethod(meta = true)
  public static IRubyObject for_fd(ThreadContext context, IRubyObject _klass, IRubyObject _fileno) {
    Ruby runtime = context.runtime;
    int fileno = (int) _fileno.convertToInteger().getLongValue();
    RubyClass klass = (RubyClass) _klass;

    ChannelDescriptor descriptor =
        ChannelDescriptor.getDescriptorByFileno(runtime.getFilenoExtMap(fileno));

    RubyBasicSocket basicSocket = (RubyBasicSocket) klass.getAllocator().allocate(runtime, klass);
    basicSocket.initSocket(runtime, descriptor);

    return basicSocket;
  }