protected SocketAddress getSocketAddress() { Channel channel = getChannel(); return SocketType.forChannel(channel).getLocalSocketAddress(channel); }
protected SocketAddress getSocketAddress() { Channel channel = getChannel(); return SocketType.forChannel(channel).getLocalSocketAddress(channel); }
@JRubyMethod() public IRubyObject connect(ThreadContext context, IRubyObject arg) { SocketAddress addr = addressForChannel(context, arg); doConnect(context, getChannel(), addr); return RubyFixnum.zero(context.runtime); }
@JRubyMethod() public IRubyObject bind(ThreadContext context, IRubyObject arg) { InetSocketAddress iaddr = Sockaddr.addressFromArg(context, arg); doBind(context, getChannel(), iaddr); return RubyFixnum.zero(context.runtime); }
@JRubyMethod() public IRubyObject connect_nonblock(ThreadContext context, IRubyObject arg) { SocketAddress addr = addressForChannel(context, arg); doConnectNonblock(context, getChannel(), addr); return RubyFixnum.zero(context.runtime); }
@JRubyMethod() public IRubyObject connect(ThreadContext context, IRubyObject arg) { SocketAddress addr = addressForChannel(context, arg); doConnect(context, getChannel(), addr); return RubyFixnum.zero(context.runtime); }
@JRubyMethod() public IRubyObject bind(ThreadContext context, IRubyObject arg) { InetSocketAddress iaddr = Sockaddr.addressFromSockaddr_in(context, arg); doBind(context, getChannel(), iaddr); return RubyFixnum.zero(context.runtime); }
@JRubyMethod() public IRubyObject connect_nonblock(ThreadContext context, IRubyObject arg) { SocketAddress addr = addressForChannel(context, arg); doConnectNonblock(context, getChannel(), addr); return RubyFixnum.zero(context.runtime); }
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); } }
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); } }
protected void doBind(ThreadContext context, SocketAddress iaddr) { Ruby runtime = context.runtime; Channel channel = getChannel();
protected void doBind(ThreadContext context, SocketAddress iaddr) { Ruby runtime = context.runtime; Channel channel = getChannel();
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()); } }
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); } }
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); } }
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()); } }
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); } } }
protected IRubyObject doConnect(ThreadContext context, SocketAddress addr, boolean ex) { Ruby runtime = context.runtime; Channel channel = getChannel();
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); } } }
protected IRubyObject doConnect(ThreadContext context, SocketAddress addr, boolean ex) { Ruby runtime = context.runtime; Channel channel = getChannel();