Search in sources :

Example 26 with DomainSocketAddress

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());
    }
}
Also used : HostAndPort(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) File(java.io.File)

Example 27 with DomainSocketAddress

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());
}
Also used : DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) File(java.io.File) Test(org.junit.Test)

Example 28 with DomainSocketAddress

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));
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 29 with DomainSocketAddress

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();
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) PeerCredentials(io.netty.channel.unix.PeerCredentials) Test(org.junit.jupiter.api.Test) SocketTest(io.netty.channel.unix.tests.SocketTest)

Example 30 with DomainSocketAddress

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();
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) PeerCredentials(io.netty.channel.unix.PeerCredentials) Test(org.junit.jupiter.api.Test) SocketTest(io.netty.channel.unix.tests.SocketTest)

Aggregations

DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)42 File (java.io.File)15 InetSocketAddress (java.net.InetSocketAddress)15 SocketAddress (java.net.SocketAddress)14 IOException (java.io.IOException)9 Test (org.junit.jupiter.api.Test)8 Connection (reactor.netty.Connection)7 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.junit.Test)6 Mono (reactor.core.publisher.Mono)5 DisposableServer (reactor.netty.DisposableServer)5 ByteString (com.google.protobuf.ByteString)4 AddressedEnvelope (io.netty.channel.AddressedEnvelope)4 DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)4 Duration (java.time.Duration)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 LoopResources (reactor.netty.resources.LoopResources)4 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3