use of zmq.io.net.Address in project jeromq by zeromq.
the class TcpAddressTest method parsesIpv6AddressSimple.
@Test
public void parsesIpv6AddressSimple() throws IOException {
String addressString = "2000::a1";
int port = Utils.findOpenPort();
Address addr = new Address(NetProtocol.tcp, addressString + ":" + port);
addr.resolve(true);
InetSocketAddress expected = new InetSocketAddress(addressString, port);
Address.IZAddress resolved = addr.resolved();
assertEquals(expected, resolved.address());
InetSocketAddress sa = (InetSocketAddress) resolved.address();
Assert.assertTrue(sa.getAddress() instanceof Inet6Address);
Assert.assertEquals(port, sa.getPort());
}
use of zmq.io.net.Address in project jeromq by zeromq.
the class TcpConnecter method open.
// Open TCP connecting socket.
// Returns true if connect was successful immediately.
// Returns false if async connect was launched.
private boolean open() throws IOException {
assert (fd == null);
// Resolve the address
if (addr == null) {
throw new IOException("Null address");
}
addr.resolve(options.ipv6);
Address.IZAddress resolved = addr.resolved();
if (resolved == null) {
throw new IOException("Address not resolved");
}
SocketAddress sa = resolved.address();
if (sa == null) {
throw new IOException("Socket address not resolved");
}
// Create the socket.
if (options.selectorChooser == null) {
fd = SocketChannel.open();
} else {
fd = options.selectorChooser.choose(resolved, options).openSocketChannel();
}
// The method enableIpv4Mapping is empty. Still to be written
if (resolved.family() == StandardProtocolFamily.INET6) {
TcpUtils.enableIpv4Mapping(fd);
}
// Set the socket to non-blocking mode so that we get async connect().
TcpUtils.unblockSocket(fd);
// Set the socket buffer limits for the underlying socket.
if (options.sndbuf != 0) {
TcpUtils.setTcpSendBuffer(fd, options.sndbuf);
}
if (options.rcvbuf != 0) {
TcpUtils.setTcpReceiveBuffer(fd, options.rcvbuf);
}
// Set the IP Type-Of-Service priority for this socket
if (options.tos != 0) {
TcpUtils.setIpTypeOfService(fd, options.tos);
}
// TODO V4 Set a source address for conversations
if (resolved.sourceAddress() != null) {
// SocketChannel bind = channel.bind(resolved.sourceAddress());
// if (bind == null) {
// return false;
// }
}
// Connect to the remote peer.
boolean rc;
try {
rc = fd.connect(sa);
if (rc) {
// Connect was successful immediately.
} else {
// Translate error codes indicating asynchronous connect has been
// launched to a uniform EINPROGRESS.
errno.set(ZError.EINPROGRESS);
}
} catch (IllegalArgumentException e) {
// I've found that IAE is thrown in openjdk as well as on android.
throw new IOException(e.getMessage(), e);
}
return rc;
}
Aggregations