Search in sources :

Example 11 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project netty by netty.

the class KQueueSocketTest method testPeerCreds.

@Test
public void testPeerCreds() throws IOException {
    BsdSocket s1 = BsdSocket.newSocketDomain();
    BsdSocket s2 = BsdSocket.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)

Example 12 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project zuul by Netflix.

the class SocketAddressPropertyTest method bindTypeWorks_udsWithEquals.

@Test
public void bindTypeWorks_udsWithEquals() {
    SocketAddress address = SocketAddressProperty.Decoder.INSTANCE.apply("UDS=/var/run/zuul=.sock");
    assertEquals(DomainSocketAddress.class, address.getClass());
    DomainSocketAddress domainSocketAddress = (DomainSocketAddress) address;
    assertEquals("/var/run/zuul=.sock", domainSocketAddress.path());
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Test(org.junit.Test)

Example 13 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project grpc-java by grpc.

the class Utils method parseServerSocketAddress.

/**
 * Parse a {@link SocketAddress} from the given string.
 */
public static SocketAddress parseServerSocketAddress(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        DomainSocketAddress domainAddress = parseUnixSocketAddress(value);
        File file = new File(domainAddress.path());
        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);
        }
        return domainAddress;
    } else {
        // Standard TCP/IP address.
        String[] parts = value.split(":", 2);
        if (parts.length < 2) {
            throw new IllegalArgumentException("Address must be a unix:// path or be in the form host:port. Got: " + value);
        }
        String host = parts[0];
        int port = Integer.parseInt(parts[1]);
        return new InetSocketAddress(host, port);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) File(java.io.File)

Example 14 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project grpc-java by grpc.

the class Utils method parseUnixSocketAddress.

private static DomainSocketAddress parseUnixSocketAddress(String value) {
    Preconditions.checkArgument(value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX), "Must start with %s: %s", UNIX_DOMAIN_SOCKET_PREFIX, value);
    // 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);
    }
    // Create the SocketAddress referencing the file.
    return new DomainSocketAddress(file);
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) ByteString(com.google.protobuf.ByteString) File(java.io.File)

Example 15 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project grpc-java by grpc.

the class BinlogHelperTest method socketToProto_unix.

@Test
public void socketToProto_unix() throws Exception {
    String path = "/some/path";
    DomainSocketAddress socketAddress = new DomainSocketAddress(path);
    assertEquals(Address.newBuilder().setType(Address.Type.TYPE_UNIX).setAddress("/some/path").build(), BinlogHelper.socketToProto(socketAddress));
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) ByteString(com.google.protobuf.ByteString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)23 File (java.io.File)11 InetSocketAddress (java.net.InetSocketAddress)9 SocketAddress (java.net.SocketAddress)8 IOException (java.io.IOException)7 Test (org.junit.Test)6 ByteString (com.google.protobuf.ByteString)5 ByteBuf (io.netty.buffer.ByteBuf)4 AddressedEnvelope (io.netty.channel.AddressedEnvelope)4 DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)4 Test (org.junit.jupiter.api.Test)4 PeerCredentials (io.netty.channel.unix.PeerCredentials)3 SocketTest (io.netty.channel.unix.tests.SocketTest)3 DomainSocketAddress (org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress)3 DomainDatagramPacket (io.netty.channel.unix.DomainDatagramPacket)2 DomainDatagramSocketAddress (io.netty.channel.unix.DomainDatagramSocketAddress)2 IovArray (io.netty.channel.unix.IovArray)2 ByteBuffer (java.nio.ByteBuffer)2 GrpcServerBuilder (alluxio.grpc.GrpcServerBuilder)1 HostAndPort (com.google.common.net.HostAndPort)1