Search in sources :

Example 1 with PeerCredentials

use of io.netty.channel.unix.PeerCredentials 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 2 with PeerCredentials

use of io.netty.channel.unix.PeerCredentials 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 3 with PeerCredentials

use of io.netty.channel.unix.PeerCredentials 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)3 PeerCredentials (io.netty.channel.unix.PeerCredentials)3 SocketTest (io.netty.channel.unix.tests.SocketTest)3 Test (org.junit.jupiter.api.Test)3