use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project beam by apache.
the class SocketAddressFactory method createFrom.
/**
* Parse a {@link SocketAddress} from the given string.
*/
public static SocketAddress createFrom(String value) {
if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
// Unix Domain Socket address.
// Create the underlying file for the Unix Domain Socket.
String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
File file = new File(filePath);
if (!file.isAbsolute()) {
throw new IllegalArgumentException("File path must be absolute: " + filePath);
}
try {
if (file.createNewFile()) {
// If this application created the file, delete it when the application exits.
file.deleteOnExit();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
// Create the SocketAddress referencing the file.
return new DomainSocketAddress(file);
} else {
// Standard TCP/IP address.
HostAndPort hostAndPort = HostAndPort.fromString(value);
checkArgument(hostAndPort.hasPort(), "Address must be a unix:// path or be in the form host:port. Got: %s", value);
return new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project beam by apache.
the class SocketAddressFactoryTest method testDomainSocket.
@Test
public void testDomainSocket() throws Exception {
File tmpFile = tmpFolder.newFile();
SocketAddress socketAddress = SocketAddressFactory.createFrom("unix://" + tmpFile.getAbsolutePath());
assertThat(socketAddress, Matchers.instanceOf(DomainSocketAddress.class));
assertEquals(tmpFile.getAbsolutePath(), ((DomainSocketAddress) socketAddress).path());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project grpc-java by grpc.
the class ChannelzProtoUtilTest method toAddress_uds.
@Test
public void toAddress_uds() throws Exception {
String path = "/tmp/foo";
DomainSocketAddress uds = new DomainSocketAddress(path);
assertEquals(Address.newBuilder().setUdsAddress(UdsAddress.newBuilder().setFilename(path)).build(), ChannelzProtoUtil.toAddress(uds));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project netty by netty.
the class KQueueSocketTest method testPeerPID.
@Test
public void testPeerPID() throws IOException {
BsdSocket s1 = BsdSocket.newSocketDomain();
BsdSocket s2 = BsdSocket.newSocketDomain();
try {
DomainSocketAddress dsa = UnixTestUtils.newDomainSocketAddress();
s1.bind(dsa);
s1.listen(1);
// PID of client socket is expected to be 0 before connection
assertEquals(0, s2.getPeerCredentials().pid());
assertTrue(s2.connect(dsa));
byte[] addr = new byte[64];
int clientFd = s1.accept(addr);
assertNotEquals(-1, clientFd);
PeerCredentials pc = new BsdSocket(clientFd).getPeerCredentials();
assertNotEquals(0, pc.pid());
assertNotEquals(0, s2.getPeerCredentials().pid());
// Server socket FDs should not have pid field set:
assertEquals(0, s1.getPeerCredentials().pid());
} finally {
s1.close();
s2.close();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project netty by netty.
the class EpollSocketTest method testPeerCreds.
@Test
public void testPeerCreds() throws IOException {
LinuxSocket s1 = LinuxSocket.newSocketDomain();
LinuxSocket s2 = LinuxSocket.newSocketDomain();
try {
DomainSocketAddress dsa = UnixTestUtils.newDomainSocketAddress();
s1.bind(dsa);
s1.listen(1);
assertTrue(s2.connect(dsa));
byte[] addr = new byte[64];
s1.accept(addr);
PeerCredentials pc = s1.getPeerCredentials();
assertNotEquals(pc.uid(), -1);
} finally {
s1.close();
s2.close();
}
}
Aggregations