private void joinMulticastGroup(IRubyObject val) throws IOException, BadDescriptorException { Channel socketChannel = getOpenChannel(); if(socketChannel instanceof DatagramChannel) { if (multicastStateManager == null) { multicastStateManager = new MulticastStateManager(); } if (val instanceof RubyString) { byte [] ipaddr_buf = val.convertToString().getBytes(); multicastStateManager.addMembership(ipaddr_buf); } } }
public void addMembership(byte [] ipaddr_buf) throws IOException { String ipString = ""; if (ipaddr_buf.length >= 4) { ipString += String.valueOf((int) ipaddr_buf[0] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[1] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[2] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[3] & 0xff); } membershipGroups.add(ipString); updateMemberships(); }
multicastStateManager.rebindToPort(port); MulticastSocket ms = this.multicastStateManager.getMulticastSocket();
private static IRubyObject doReceiveMulticast(RubyBasicSocket socket, final Ruby runtime, final boolean non_block, int length, ReceiveTuple tuple) throws IOException { ByteBuffer recv = ByteBuffer.wrap(new byte[length]); SocketAddress address; DatagramChannel channel = socket.multicastStateManager.getMulticastSocket().getChannel(); address = channel.receive(recv); if (address == null) { if ( non_block ) return null; // :wait_readable or raise WaitReadable throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking"); } InetSocketAddress sender = (InetSocketAddress) address; // see JRUBY-4678 if (sender == null) { throw runtime.newErrnoECONNRESETError(); } recv.flip(); RubyString result = runtime.newString(new ByteList(recv.array(), recv.position(), recv.limit(), false)); if (tuple != null) { tuple.result = result; tuple.sender = sender; } return result; }
((DatagramChannel) channel).socket().bind(addr); } else { multicastStateManager.rebindToPort(port);
multicastStateManager.rebindToPort(addr.getPort()); MulticastSocket ms = this.multicastStateManager.getMulticastSocket();
private static IRubyObject doReceiveMulticast(RubyBasicSocket socket, final Ruby runtime, final boolean non_block, int length, ReceiveTuple tuple) throws IOException { ByteBuffer recv = ByteBuffer.wrap(new byte[length]); SocketAddress address; DatagramChannel channel = socket.multicastStateManager.getMulticastSocket().getChannel(); address = channel.receive(recv); if (address == null) { if ( non_block ) return null; // :wait_readable or raise WaitReadable throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking"); } InetSocketAddress sender = (InetSocketAddress) address; // see JRUBY-4678 if (sender == null) { throw runtime.newErrnoECONNRESETError(); } recv.flip(); RubyString result = runtime.newString(new ByteList(recv.array(), recv.position(), recv.limit(), false)); if (tuple != null) { tuple.result = result; tuple.sender = sender; } return result; }
((DatagramChannel) channel).socket().bind(addr); } else { multicastStateManager.rebindToPort(port);
private void joinMulticastGroup(IRubyObject val) throws IOException, BadDescriptorException { Channel socketChannel = getOpenChannel(); if(socketChannel instanceof DatagramChannel) { if (multicastStateManager == null) { multicastStateManager = new MulticastStateManager(); } if (val instanceof RubyString) { byte [] ipaddr_buf = val.convertToString().getBytes(); multicastStateManager.addMembership(ipaddr_buf); } } }
multicastStateManager.rebindToPort(port); MulticastSocket ms = this.multicastStateManager.getMulticastSocket();
public void addMembership(byte [] ipaddr_buf) throws IOException { String ipString = ""; if (ipaddr_buf.length >= 4) { ipString += String.valueOf((int) ipaddr_buf[0] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[1] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[2] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[3] & 0xff); } membershipGroups.add(ipString); updateMemberships(); }
private IRubyObject doReceiveMulticast(Ruby runtime, int length, ReceiveTuple tuple) throws IOException { byte[] buf2 = new byte[length]; DatagramPacket recv = new DatagramPacket(buf2, buf2.length); MulticastSocket ms = this.multicastStateManager.getMulticastSocket(); try { ms.receive(recv); } catch (IllegalBlockingModeException ibme) { // MulticastSocket does not support nonblocking // TODO: Use Java 7 NIO.2 DatagramChannel to do multicast if (runtime.is1_9()) { throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking"); } else { throw runtime.newErrnoEAGAINError("multicast UDP does not support nonblocking"); } } InetSocketAddress sender = (InetSocketAddress) recv.getSocketAddress(); // see JRUBY-4678 if (sender == null) { throw runtime.newErrnoECONNRESETError(); } RubyString result = runtime.newString(new ByteList(recv.getData(), 0, recv.getLength())); if (tuple != null) { tuple.result = result; tuple.sender = sender; } return result; }
((DatagramChannel) channel).bind(addr); } else { multicastStateManager.rebindToPort(port);
private void joinMulticastGroup(IRubyObject val) throws IOException, BadDescriptorException { Channel socketChannel = getOpenChannel(); if(socketChannel instanceof DatagramChannel) { if (multicastStateManager == null) { multicastStateManager = new MulticastStateManager(); } if (val instanceof RubyString) { byte [] ipaddr_buf = val.convertToString().getBytes(); multicastStateManager.addMembership(ipaddr_buf); } } }
multicastStateManager.rebindToPort(addr.getPort()); MulticastSocket ms = this.multicastStateManager.getMulticastSocket();
public void addMembership(byte [] ipaddr_buf) throws IOException { String ipString = ""; if (ipaddr_buf.length >= 4) { ipString += String.valueOf((int) ipaddr_buf[0] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[1] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[2] & 0xff); ipString += "."; ipString += String.valueOf((int) ipaddr_buf[3] & 0xff); } membershipGroups.add(ipString); updateMemberships(); }
private IRubyObject doReceiveMulticast(Ruby runtime, int length, ReceiveTuple tuple) throws IOException { byte[] buf2 = new byte[length]; DatagramPacket recv = new DatagramPacket(buf2, buf2.length); MulticastSocket ms = this.multicastStateManager.getMulticastSocket(); try { ms.receive(recv); } catch (IllegalBlockingModeException ibme) { // MulticastSocket does not support nonblocking // TODO: Use Java 7 NIO.2 DatagramChannel to do multicast if (runtime.is1_9()) { throw runtime.newErrnoEAGAINReadableError("multicast UDP does not support nonblocking"); } else { throw runtime.newErrnoEAGAINError("multicast UDP does not support nonblocking"); } } InetSocketAddress sender = (InetSocketAddress) recv.getSocketAddress(); // see JRUBY-4678 if (sender == null) { throw runtime.newErrnoECONNRESETError(); } RubyString result = runtime.newString(new ByteList(recv.getData(), 0, recv.getLength())); if (tuple != null) { tuple.result = result; tuple.sender = sender; } return result; }
((DatagramChannel) channel).bind(addr); } else { multicastStateManager.rebindToPort(port);
private void joinMulticastGroup(IRubyObject val) throws IOException, BadDescriptorException { Channel socketChannel = getOpenChannel(); if(socketChannel instanceof DatagramChannel) { if (multicastStateManager == null) { multicastStateManager = new MulticastStateManager(); } if (val instanceof RubyString) { byte [] ipaddr_buf = val.convertToString().getBytes(); multicastStateManager.addMembership(ipaddr_buf); } } }
public void rebindToPort(int port) throws IOException { if (multicastSocket != null) { multicastSocket.close(); } multicastSocket = new MulticastSocket(port); updateMemberships(); }