Skip to content
GitHub no longer supports this web browser. Learn more about the browsers we support.
Permalink
Browse files

Add support for Unix Domain Sockets when using native epoll transport

Motivation:

Using Unix Domain Sockets can be very useful when communication should take place on the same host and has less overhead then using loopback. We should support this with the native epoll transport.

Modifications:

- Add support for Unix Domain Sockets.
- Adjust testsuite to be able to reuse tests.

Result:

Unix Domain Sockets are now support when using native epoll transport.
  • Loading branch information
normanmaurer committed Jan 14, 2015
1 parent 108a95c commit b898bdda846a4cc4ae5d6261406b138f5393d018
Showing with 1,884 additions and 869 deletions.
  1. +8 −2 testsuite/src/main/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java
  2. +8 −3 testsuite/src/main/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java
  3. +8 −3 testsuite/src/main/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java
  4. +4 −5 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java
  5. +4 −5 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java
  6. +4 −5 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java
  7. +6 −7 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java
  8. +4 −5 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslGreetingTest.java
  9. +4 −5 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java
  10. +4 −5 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java
  11. +99 −0 transport-native-epoll/src/main/c/io_netty_channel_epoll_Native.c
  12. +71 −10 transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java
  13. +114 −0 transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollServerChannel.java
  14. +653 −0 transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java
  15. +63 −0 transport-native-epoll/src/main/java/io/netty/channel/epoll/DomainSocketAddress.java
  16. +11 −1 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java
  17. +78 −0 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDomainSocketChannel.java
  18. +165 −0 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerChannelConfig.java
  19. +85 −0 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerDomainSocketChannel.java
  20. +14 −73 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerSocketChannel.java
  21. +6 −55 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerSocketChannelConfig.java
  22. +25 −675 transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java
  23. +55 −9 transport-native-epoll/src/main/java/io/netty/channel/epoll/Native.java
  24. +35 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketEchoTest.java
  25. +35 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketFileRegionTest.java
  26. +37 −0 ...sport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketFixedLengthEchoTest.java
  27. +37 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketGatheringWriteTest.java
  28. +36 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketObjectEchoTest.java
  29. +47 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketSslEchoTest.java
  30. +42 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketSslGreetingTest.java
  31. +42 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketStartTlsTest.java
  32. +36 −0 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDomainSocketStringEchoTest.java
  33. +44 −1 transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketTestPermutation.java
@@ -24,11 +24,12 @@
import io.netty.util.NetUtil;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;

public abstract class AbstractClientSocketTest extends AbstractTestsuiteTest<Bootstrap> {

protected volatile InetSocketAddress addr;
protected volatile SocketAddress addr;

protected AbstractClientSocketTest() {
super(Bootstrap.class);
@@ -41,8 +42,13 @@ protected AbstractClientSocketTest() {

@Override
protected void configure(Bootstrap bootstrap, ByteBufAllocator allocator) {
addr = new InetSocketAddress(NetUtil.LOCALHOST, TestUtils.getFreePort());
addr = newSocketAddress();
bootstrap.remoteAddress(addr);
bootstrap.option(ChannelOption.ALLOCATOR, allocator);
}

protected SocketAddress newSocketAddress() {
return new InetSocketAddress(
NetUtil.LOCALHOST, TestUtils.getFreePort());
}
}
@@ -24,11 +24,12 @@
import io.netty.util.NetUtil;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;

public abstract class AbstractServerSocketTest extends AbstractTestsuiteTest<ServerBootstrap> {

protected volatile InetSocketAddress addr;
protected volatile SocketAddress addr;

protected AbstractServerSocketTest() {
super(ServerBootstrap.class);
@@ -41,10 +42,14 @@ protected AbstractServerSocketTest() {

@Override
protected void configure(ServerBootstrap bootstrap, ByteBufAllocator allocator) {
addr = new InetSocketAddress(
NetUtil.LOCALHOST, TestUtils.getFreePort());
addr = newSocketAddress();
bootstrap.localAddress(addr);
bootstrap.option(ChannelOption.ALLOCATOR, allocator);
bootstrap.childOption(ChannelOption.ALLOCATOR, allocator);
}

protected SocketAddress newSocketAddress() {
return new InetSocketAddress(
NetUtil.LOCALHOST, TestUtils.getFreePort());
}
}
@@ -25,11 +25,12 @@
import io.netty.util.NetUtil;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;

public abstract class AbstractSocketTest extends AbstractComboTestsuiteTest<ServerBootstrap, Bootstrap> {

protected volatile InetSocketAddress addr;
protected volatile SocketAddress addr;

protected AbstractSocketTest() {
super(ServerBootstrap.class, Bootstrap.class);
@@ -42,12 +43,16 @@ protected AbstractSocketTest() {

@Override
protected void configure(ServerBootstrap bootstrap, Bootstrap bootstrap2, ByteBufAllocator allocator) {
addr = new InetSocketAddress(
NetUtil.LOCALHOST, TestUtils.getFreePort());
addr = newSocketAddress();
bootstrap.localAddress(addr);
bootstrap.option(ChannelOption.ALLOCATOR, allocator);
bootstrap.childOption(ChannelOption.ALLOCATOR, allocator);
bootstrap2.remoteAddress(addr);
bootstrap2.option(ChannelOption.ALLOCATOR, allocator);
}

protected SocketAddress newSocketAddress() {
return new InetSocketAddress(
NetUtil.LOCALHOST, TestUtils.getFreePort());
}
}
@@ -24,7 +24,6 @@
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import org.junit.AfterClass;
@@ -129,15 +128,15 @@ private static void testSimpleEcho0(
final EchoHandler ch = new EchoHandler(autoRead);

if (additionalExecutor) {
sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(SocketChannel c) throws Exception {
protected void initChannel(Channel c) throws Exception {
c.pipeline().addLast(group, sh);
}
});
cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(SocketChannel c) throws Exception {
protected void initChannel(Channel c) throws Exception {
c.pipeline().addLast(group, ch);
}
});
@@ -23,7 +23,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.FixedLengthFrameDecoder;
import org.junit.Test;

@@ -64,17 +63,17 @@ private static void testFixedLengthEcho(ServerBootstrap sb, Bootstrap cb, boolea
final EchoHandler sh = new EchoHandler(autoRead);
final EchoHandler ch = new EchoHandler(autoRead);

sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
sch.pipeline().addLast("decoder", new FixedLengthFrameDecoder(1024));
sch.pipeline().addAfter("decoder", "handler", sh);
}
});

cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
sch.pipeline().addLast("decoder", new FixedLengthFrameDecoder(1024));
sch.pipeline().addAfter("decoder", "handler", ch);
}
@@ -21,7 +21,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
@@ -72,19 +71,19 @@ private static void testObjectEcho(ServerBootstrap sb, Bootstrap cb, boolean aut
final EchoHandler sh = new EchoHandler(autoRead);
final EchoHandler ch = new EchoHandler(autoRead);

sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
sch.pipeline().addLast(
new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())),
new ObjectEncoder(),
sh);
}
});

cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
sch.pipeline().addLast(
new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())),
new ObjectEncoder(),
@@ -25,7 +25,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.ssl.JdkSslClientContext;
import io.netty.handler.ssl.JdkSslServerContext;
import io.netty.handler.ssl.OpenSsl;
@@ -182,8 +181,8 @@ public String toString() {
private final AtomicInteger clientNegoCounter = new AtomicInteger();
private final AtomicInteger serverNegoCounter = new AtomicInteger();

private volatile SocketChannel clientChannel;
private volatile SocketChannel serverChannel;
private volatile Channel clientChannel;
private volatile Channel serverChannel;

private volatile SslHandler clientSslHandler;
private volatile SslHandler serverSslHandler;
@@ -222,10 +221,10 @@ public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
final ExecutorService delegatedTaskExecutor = Executors.newCachedThreadPool();
reset();

sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
@SuppressWarnings("deprecation")
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
serverChannel = sch;

if (serverUsesDelegatedTaskExecutor) {
@@ -243,10 +242,10 @@ public void initChannel(SocketChannel sch) throws Exception {
}
});

cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
@SuppressWarnings("deprecation")
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
clientChannel = sch;

if (clientUsesDelegatedTaskExecutor) {
@@ -24,7 +24,6 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.JdkSslClientContext;
@@ -117,19 +116,19 @@ public void testSslGreeting(ServerBootstrap sb, Bootstrap cb) throws Throwable {
final ServerHandler sh = new ServerHandler();
final ClientHandler ch = new ClientHandler();

sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast(serverCtx.newHandler(sch.alloc()));
p.addLast(new LoggingHandler(LOG_LEVEL));
p.addLast(sh);
}
});

cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast(clientCtx.newHandler(sch.alloc()));
p.addLast(new LoggingHandler(LOG_LEVEL));
@@ -23,7 +23,6 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
@@ -150,19 +149,19 @@ private void testStartTls(ServerBootstrap sb, Bootstrap cb, boolean autoRead) th
final StartTlsServerHandler sh = new StartTlsServerHandler(sse, autoRead);
final StartTlsClientHandler ch = new StartTlsClientHandler(cse, autoRead);

sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast("logger", new LoggingHandler(LOG_LEVEL));
p.addLast(new LineBasedFrameDecoder(64), new StringDecoder(), new StringEncoder());
p.addLast(executor, sh);
}
});

cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast("logger", new LoggingHandler(LOG_LEVEL));
p.addLast(new LineBasedFrameDecoder(64), new StringDecoder(), new StringEncoder());
@@ -21,7 +21,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
@@ -74,19 +73,19 @@ private static void testStringEcho(ServerBootstrap sb, Bootstrap cb, boolean aut
final StringEchoHandler sh = new StringEchoHandler(autoRead);
final StringEchoHandler ch = new StringEchoHandler(autoRead);

sb.childHandler(new ChannelInitializer<SocketChannel>() {
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
sch.pipeline().addLast("framer", new DelimiterBasedFrameDecoder(512, Delimiters.lineDelimiter()));
sch.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.ISO_8859_1));
sch.pipeline().addBefore("decoder", "encoder", new StringEncoder(CharsetUtil.ISO_8859_1));
sch.pipeline().addAfter("decoder", "handler", sh);
}
});

cb.handler(new ChannelInitializer<SocketChannel>() {
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(SocketChannel sch) throws Exception {
public void initChannel(Channel sch) throws Exception {
sch.pipeline().addLast("framer", new DelimiterBasedFrameDecoder(512, Delimiters.lineDelimiter()));
sch.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.ISO_8859_1));
sch.pipeline().addBefore("decoder", "encoder", new StringEncoder(CharsetUtil.ISO_8859_1));

0 comments on commit b898bdd

Please sign in to comment.
You can’t perform that action at this time.