public IRubyObject initialize(ThreadContext context, ProtocolFamily family) { Ruby runtime = context.runtime; try { this.family = family; DatagramChannel channel = DatagramChannel.open(family); initSocket(newChannelFD(runtime, channel)); } catch (ConnectException e) { throw runtime.newErrnoECONNREFUSEDError(); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); } catch (UnsupportedOperationException uoe) { if (uoe.getMessage().contains("IPv6 not available")) { throw runtime.newErrnoEAFNOSUPPORTError("socket(2) - udp"); } throw sockerr(runtime, "UnsupportedOperationException: " + uoe.getLocalizedMessage(), uoe); } catch (IOException e) { throw sockerr(runtime, "initialize: name or service not known", e); } return this; }
public IRubyObject initialize(ThreadContext context, ProtocolFamily family) { Ruby runtime = context.runtime; try { this.family = family; DatagramChannel channel = DatagramChannel.open(family); initSocket(newChannelFD(runtime, channel)); } catch (ConnectException e) { throw runtime.newErrnoECONNREFUSEDError(); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); } catch (UnsupportedOperationException uoe) { if (uoe.getMessage().contains("IPv6 not available")) { throw runtime.newErrnoEAFNOSUPPORTError("socket(2) - udp"); } throw sockerr(runtime, "UnsupportedOperationException: " + uoe.getLocalizedMessage(), uoe); } catch (IOException e) { throw sockerr(runtime, "initialize: name or service not known", e); } return this; }
/** * Overrides BasicSocket#recv */ @Override public IRubyObject recv(ThreadContext context, IRubyObject length) { final Ruby runtime = context.runtime; try { return doReceive(this, runtime, false, RubyNumeric.fix2int(length), null); } catch (PortUnreachableException e) { throw runtime.newErrnoECONNREFUSEDError(); } catch (IOException e) { // SocketException throw runtime.newIOErrorFromException(e); } catch (RaiseException e) { throw e; } catch (Exception e) { throw sockerr(runtime, e.getLocalizedMessage(), e); } }
/** * Overrides BasicSocket#recv */ @Override public IRubyObject recv(ThreadContext context, IRubyObject length) { final Ruby runtime = context.runtime; try { return doReceive(this, runtime, false, RubyNumeric.fix2int(length), null); } catch (PortUnreachableException e) { throw runtime.newErrnoECONNREFUSEDError(); } catch (IOException e) { // SocketException throw runtime.newIOErrorFromException(e); } catch (RaiseException e) { throw e; } catch (Exception e) { throw sockerr(runtime, e.getLocalizedMessage(), e); } }
public static IRubyObject recvfrom(RubyBasicSocket socket, ThreadContext context, IRubyObject length) { final Ruby runtime = context.runtime; try { ReceiveTuple tuple = doReceiveTuple(socket, runtime, false, RubyNumeric.fix2int(length)); IRubyObject addressArray = socket.addrFor(context, tuple.sender, false); return runtime.newArray(tuple.result, addressArray); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "recvfrom: name or service not known"); } catch (PortUnreachableException e) { throw runtime.newErrnoECONNREFUSEDError(); } catch (IOException e) { // SocketException throw runtime.newIOErrorFromException(e); } catch (RaiseException e) { throw e; } catch (Exception e) { throw sockerr(runtime, e.getLocalizedMessage(), e); } }
public static IRubyObject recvfrom(RubyBasicSocket socket, ThreadContext context, IRubyObject length) { final Ruby runtime = context.runtime; try { ReceiveTuple tuple = doReceiveTuple(socket, runtime, false, RubyNumeric.fix2int(length)); IRubyObject addressArray = socket.addrFor(context, tuple.sender, false); return runtime.newArray(tuple.result, addressArray); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "recvfrom: name or service not known"); } catch (PortUnreachableException e) { throw runtime.newErrnoECONNREFUSEDError(); } catch (IOException e) { // SocketException throw runtime.newIOErrorFromException(e); } catch (RaiseException e) { throw e; } catch (Exception e) { throw sockerr(runtime, e.getLocalizedMessage(), e); } }
@JRubyMethod public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _flags) { // TODO: implement flags final Ruby runtime = context.runtime; try { int written; RubyString data = _mesg.convertToString(); ByteList dataBL = data.getByteList(); ByteBuffer buf = ByteBuffer.wrap(dataBL.unsafeBytes(), dataBL.begin(), dataBL.realSize()); written = ((DatagramChannel) this.getChannel()).write(buf); return runtime.newFixnum(written); } catch (NotYetConnectedException e) { throw runtime.newErrnoEDESTADDRREQError("send(2)"); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "send: name or service not known"); } catch (IOException e) { // SocketException throw runtime.newIOErrorFromException(e); } catch (RaiseException e) { throw e; } catch (Exception e) { throw sockerr(runtime, e.getLocalizedMessage(), e); } }
@JRubyMethod public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _flags) { // TODO: implement flags final Ruby runtime = context.runtime; try { int written; RubyString data = _mesg.convertToString(); ByteList dataBL = data.getByteList(); ByteBuffer buf = ByteBuffer.wrap(dataBL.unsafeBytes(), dataBL.begin(), dataBL.realSize()); written = ((DatagramChannel) this.getChannel()).write(buf); return runtime.newFixnum(written); } catch (NotYetConnectedException e) { throw runtime.newErrnoEDESTADDRREQError("send(2)"); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "send: name or service not known"); } catch (IOException e) { // SocketException throw runtime.newIOErrorFromException(e); } catch (RaiseException e) { throw e; } catch (Exception e) { throw sockerr(runtime, e.getLocalizedMessage(), e); } }
throw sockerr(runtime, e.getLocalizedMessage(), e);
throw sockerr(runtime, e.getLocalizedMessage(), e);
throw sockerr(runtime, e.getLocalizedMessage(), e);
throw sockerr(runtime, e.getLocalizedMessage(), e);