Search in sources :

Example 1 with Socket

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

the class SocketTest method testDoubleCloseDoesNotThrow.

@Test
public void testDoubleCloseDoesNotThrow() throws IOException {
    Socket socket = Socket.newSocketStream();
    socket.close();
    socket.close();
}
Also used : Socket(io.netty.channel.unix.Socket) Test(org.junit.jupiter.api.Test)

Example 2 with Socket

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

the class LinuxSocketTest method testUnixDomainSocketTooLongPathFails.

@Test
public void testUnixDomainSocketTooLongPathFails() throws IOException {
    // Most systems has a limit for UDS path of 108, 255 is generally too long.
    StringBuilder socketPath = new StringBuilder("/tmp/");
    while (socketPath.length() < 255) {
        socketPath.append(UUID.randomUUID());
    }
    final DomainSocketAddress domainSocketAddress = new DomainSocketAddress(socketPath.toString());
    final Socket socket = Socket.newSocketDomain();
    try {
        Exception exception = Assertions.assertThrows(NativeIoException.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                socket.bind(domainSocketAddress);
            }
        });
        Assertions.assertTrue(exception.getMessage().contains("too long"));
    } finally {
        socket.close();
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Executable(org.junit.jupiter.api.function.Executable) Socket(io.netty.channel.unix.Socket) NativeIoException(io.netty.channel.unix.Errors.NativeIoException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with Socket

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

the class EpollDatagramChannelTest method testActiveHasLocalAddress.

@Test
public void testActiveHasLocalAddress() throws IOException {
    Socket socket = Socket.newSocketDgram();
    EpollDatagramChannel channel = new EpollDatagramChannel(socket.intValue());
    InetSocketAddress localAddress = channel.localAddress();
    assertTrue(channel.active);
    assertNotNull(localAddress);
    assertEquals(socket.localAddress(), localAddress);
    channel.fd().close();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Socket(io.netty.channel.unix.Socket) Test(org.junit.jupiter.api.Test)

Aggregations

Socket (io.netty.channel.unix.Socket)3 Test (org.junit.jupiter.api.Test)3 DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)1 NativeIoException (io.netty.channel.unix.Errors.NativeIoException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Executable (org.junit.jupiter.api.function.Executable)1