private DatagramChannel getDatagramChannel() { return (DatagramChannel) getChannel(); }
private DatagramChannel getDatagramChannel() { return (DatagramChannel) getChannel(); }
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; }
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; }
private ReceiveTuple doReceiveNonblockTuple(Ruby runtime, int length) throws IOException { DatagramChannel channel = (DatagramChannel)getChannel(); synchronized (channel.blockingLock()) { boolean oldBlocking = channel.isBlocking(); channel.configureBlocking(false); try { return doReceiveTuple(runtime, length); } finally { channel.configureBlocking(oldBlocking); } } }
@JRubyMethod public IRubyObject connect(ThreadContext context, IRubyObject host, IRubyObject port) { Ruby runtime = context.runtime; try { InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(host.convertToString().toString()), SocketUtils.portToInt(port)); ((DatagramChannel) this.getChannel()).connect(addr); return RubyFixnum.zero(runtime); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "connect: name or service not known"); } catch (IOException e) { throw SocketUtils.sockerr(runtime, "connect: name or service not known"); } }
@JRubyMethod public IRubyObject connect(ThreadContext context, IRubyObject host, IRubyObject port) { Ruby runtime = context.runtime; try { InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(host.convertToString().toString()), SocketUtils.portToInt(port)); ((DatagramChannel) this.getChannel()).connect(addr); return RubyFixnum.zero(runtime); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "connect: name or service not known"); } catch (IOException e) { throw SocketUtils.sockerr(runtime, "connect: name or service not known"); } }
private ReceiveTuple doReceiveNonblockTuple(Ruby runtime, int length) throws IOException { DatagramChannel channel = (DatagramChannel)getChannel(); synchronized (channel.blockingLock()) { boolean oldBlocking = channel.isBlocking(); channel.configureBlocking(false); try { return doReceiveTuple(runtime, length); } finally { channel.configureBlocking(oldBlocking); } } }
InetSocketAddress addr = new InetSocketAddress(addrs[i], SocketUtils.portToInt(port)); ((DatagramChannel) this.getChannel()).connect(addr);
InetSocketAddress addr = new InetSocketAddress(addrs[i], SocketUtils.portToInt(port)); ((DatagramChannel) this.getChannel()).connect(addr);
@JRubyMethod public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _flags) { // TODO: implement flags Ruby runtime = context.runtime; try { int written; RubyString data = _mesg.convertToString(); ByteBuffer buf = ByteBuffer.wrap(data.getBytes()); written = ((DatagramChannel) this.getChannel()).write(buf); return runtime.newFixnum(written); } catch (NotYetConnectedException nyce) { throw runtime.newErrnoEDESTADDRREQError("send(2)"); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "send: name or service not known"); } catch (IOException e) { throw SocketUtils.sockerr(runtime, "send: name or service not known"); } }
@JRubyMethod public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _flags) { // TODO: implement flags Ruby runtime = context.runtime; try { int written; RubyString data = _mesg.convertToString(); ByteBuffer buf = ByteBuffer.wrap(data.getBytes()); written = ((DatagramChannel) this.getChannel()).write(buf); return runtime.newFixnum(written); } catch (NotYetConnectedException nyce) { throw runtime.newErrnoEDESTADDRREQError("send(2)"); } catch (UnknownHostException e) { throw SocketUtils.sockerr(runtime, "send: name or service not known"); } catch (IOException e) { throw SocketUtils.sockerr(runtime, "send: name or service not known"); } }
@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); } }
Channel channel = getChannel(); int port = SocketUtils.portToInt(_port);
Channel channel = getChannel(); int port = SocketUtils.portToInt(_port);
written = ((DatagramChannel) this.getChannel()).send(buf, addr);
written = ((DatagramChannel) this.getChannel()).send(buf, addr);
final int port = SocketUtils.portToInt(_port); try { final Channel channel = getChannel();
final int port = SocketUtils.portToInt(_port); try { final Channel channel = getChannel();