|
40 | 40 | import java.net.SocketAddress;
|
41 | 41 | import java.net.SocketException;
|
42 | 42 | import java.net.MulticastSocket;
|
| 43 | +import java.net.SocketOption; |
43 | 44 | import java.net.StandardProtocolFamily;
|
44 | 45 | import java.net.UnknownHostException;
|
45 | 46 | import java.net.DatagramPacket;
|
|
48 | 49 | import java.nio.channels.DatagramChannel;
|
49 | 50 | import java.nio.channels.IllegalBlockingModeException;
|
50 | 51 | import java.nio.channels.NotYetConnectedException;
|
| 52 | +import java.nio.channels.UnsupportedAddressTypeException; |
51 | 53 |
|
52 | 54 | import jnr.constants.platform.AddressFamily;
|
53 | 55 | import jnr.netdb.Service;
|
@@ -123,6 +125,7 @@ public IRubyObject initialize(ThreadContext context, ProtocolFamily family) {
|
123 | 125 | Ruby runtime = context.runtime;
|
124 | 126 |
|
125 | 127 | try {
|
| 128 | + this.family = family; |
126 | 129 | DatagramChannel channel = DatagramChannel.open(family);
|
127 | 130 | initSocket(newChannelFD(runtime, channel));
|
128 | 131 | } catch (ConnectException e) {
|
@@ -188,6 +191,11 @@ else if (host instanceof RubyFixnum) {
|
188 | 191 |
|
189 | 192 | return RubyFixnum.zero(runtime);
|
190 | 193 | }
|
| 194 | + catch (UnsupportedAddressTypeException e) { |
| 195 | + // This may not be the appropriate message for all such exceptions |
| 196 | + ProtocolFamily family = this.family == null ? StandardProtocolFamily.INET : this.family; |
| 197 | + throw SocketUtils.sockerr(runtime, "bind: unsupported address " + host.inspect() + " for protocol family " + family); |
| 198 | + } |
191 | 199 | catch (UnknownHostException e) {
|
192 | 200 | throw SocketUtils.sockerr(runtime, "bind: name or service not known");
|
193 | 201 | }
|
@@ -630,6 +638,7 @@ private static IRubyObject doReceiveMulticast(RubyBasicSocket socket, final Ruby
|
630 | 638 | }
|
631 | 639 |
|
632 | 640 | private volatile Class<? extends InetAddress> explicitFamily;
|
| 641 | + private volatile ProtocolFamily family; |
633 | 642 |
|
634 | 643 | @Deprecated
|
635 | 644 | public IRubyObject bind(IRubyObject host, IRubyObject port) {
|
|
0 commit comments