Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple Unix from Linux in Native Transport #4335

Closed
wants to merge 1 commit into from

Conversation

Scottmitch
Copy link
Member

Motivation:
transport-native-epoll is designed to be specific to Linux. However there is native code that can be extracted out and made to work on more Unix like distributions. There are a few steps to be completely decoupled but the first step is to extract out code that can run in a more general Unix environment from the Linux specific code base.

Modifications:

  • Move all non-Linux specific stuff from Native.java into the io.netty.channel.unix package.
  • io.netty.channel.unix.FileDescriptor will inherit all the native methods that are specific to file descriptors.
  • io_netty_channel_epoll_Native.[c|h] will only have code that is specific to Linux.

Result:
Code is decoupled and design is streamlined in FileDescriptor.

@Scottmitch Scottmitch self-assigned this Oct 9, 2015
@Scottmitch Scottmitch added this to the 4.0.33.Final milestone Oct 9, 2015
@Scottmitch
Copy link
Member Author

@normanmaurer @nmittler @trustin - FYI

super(parent, fd.intValue());
}

/**
* Creates a new {@link EpollDomainSocketChannel} from an existing {@link FileDescriptor}
*/
public EpollDomainSocketChannel(FileDescriptor fd) {
super(fd);
public EpollDomainSocketChannel(Socket fd, boolean active) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normanmaurer - I spent a bunch of time debugging an issue related to the socket was marked as active because getSoError() returned 0, but then SslHandler.handlerAdded initiated the handshake, which involved doing a write before the FD was actually connected. This results in a rather nebulous channel closed exception which was difficult to track down (the root cause was a 107 - Transport endpoint is not connected as a result of writeAddress). I changed the API here just to discuss ... 1. do you have an example of a time when someone creates an FD and it is already active (as determined by getSoError)? 2. If so I will add another constructor which sets active based upon getSoError.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normanmaurer - I deprecated all the constructors that appear to be misleading and may get users into trouble.

@Scottmitch
Copy link
Member Author

@normanmaurer - PTAL

@nmittler
Copy link
Member

@Scottmitch took a cursory glance ... looks great! I'll defer to @normanmaurer for a detailed review :)

@Scottmitch
Copy link
Member Author

@nmittler - Thanks :) Hopefully paves the way for broader unix support.

@@ -0,0 +1,191 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Scottmitch love that this is now in an extra file 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

private static final long serialVersionUID = 3094819287843178401L;

// holds the amount of received bytes
final int receivedAmount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@normanmaurer
Copy link
Member

@Scottmitch all in all I love this PR! Makes stuff a lot cleaner. Good work, just a few comments buddy!

@normanmaurer
Copy link
Member

@Scottmitch let us release a new 4.0 and 4.1 before we pull this in so we have a bit more time to test this. WDYT ?

@Scottmitch
Copy link
Member Author

@normanmaurer - I think that is a good idea. However I have PR #4336 based off of this PR right now which should prolly go in...

@normanmaurer
Copy link
Member

@Scottmitch can you maybe refactor #4336 so we can pull it in on the "original" code ?

@ninja-
Copy link

ninja- commented Oct 24, 2015

[INFO] libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./src -O3 -Werror -I/usr/lib/jvm/java-8-jdk/include -I/usr/lib/jvm/java-8-jdk/include/linux -c src/io_netty_channel_unix_FileDescriptor.c  -fPIC -DPIC -o src/.libs/io_netty_channel_unix_FileDescriptor.o
[INFO] src/io_netty_channel_unix_FileDescriptor.c: In function ‘_write’:
[INFO] src/io_netty_channel_unix_FileDescriptor.c:37:14: error: implicit declaration of function ‘write’ [-Werror=implicit-function-declaration]
[INFO]         res = write(fd, buffer + pos, (size_t) (limit - pos));
[INFO]               ^
[INFO] src/io_netty_channel_unix_FileDescriptor.c: In function ‘_read’:
[INFO] src/io_netty_channel_unix_FileDescriptor.c:65:15: error: implicit declaration of function ‘read’ [-Werror=implicit-function-declaration]
[INFO]          res = read(fd, buffer + pos, (size_t) (limit - pos));
[INFO]                ^
[INFO] src/io_netty_channel_unix_FileDescriptor.c: In function ‘Java_io_netty_channel_unix_FileDescriptor_close’:
[INFO] src/io_netty_channel_unix_FileDescriptor.c:136:8: error: implicit declaration of function ‘close’ [-Werror=implicit-function-declaration]
[INFO]     if (close(fd) < 0) {
[INFO]         ^
[INFO] src/io_netty_channel_unix_FileDescriptor.c: In function ‘Java_io_netty_channel_unix_FileDescriptor_newPipe’:
[INFO] src/io_netty_channel_unix_FileDescriptor.c:224:14: error: implicit declaration of function ‘pipe’ [-Werror=implicit-function-declaration]
[INFO]           if (pipe(fd) == 0) {

this pr broke my build.
need to add

#include <unistd.h>

@ninja-
Copy link

ninja- commented Oct 24, 2015

3 places to fix @Scottmitch and my build process is ok

@normanmaurer
Copy link
Member

Yeah i guess missing

#include <unistd.h>

Am 24.10.2015 um 19:58 schrieb ninja notifications@github.com:

3 places to fix @Scottmitch and my build process is ok


Reply to this email directly or view it on GitHub.

@Scottmitch
Copy link
Member Author

@ninja- - Thanks for the comments. The issues you pointed out should be resolved now.

@ninja-
Copy link

ninja- commented Oct 29, 2015

@Scottmitch can your 2 epoll PRs be merged ? I am having a hard time rebasing on them every time

@ninja-
Copy link

ninja- commented Oct 29, 2015

@Scottmitch your pr still has build errors. somehow github wiped my on-line comments when I mentioned fix for the last 3 of them

@ninja-
Copy link

ninja- commented Oct 29, 2015

diff --git a/transport-native-epoll/src/main/c/io_netty_channel_unix_FileDescriptor.c b/transport-native-epoll/src/main/c/io_netty_channel_unix_FileDescriptor.c
index 9ad191c..abcc82b 100644
--- a/transport-native-epoll/src/main/c/io_netty_channel_unix_FileDescriptor.c
+++ b/transport-native-epoll/src/main/c/io_netty_channel_unix_FileDescriptor.c
@@ -17,6 +17,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/uio.h>
+#include <unistd.h>

 #include "netty_unix_errors.h"
 #include "netty_unix_filedescriptor.h"
diff --git a/transport-native-epoll/src/main/c/io_netty_channel_unix_Socket.c b/transport-native-epoll/src/main/c/io_netty_channel_unix_Socket.c
index de73777..2f39fce 100644
--- a/transport-native-epoll/src/main/c/io_netty_channel_unix_Socket.c
+++ b/transport-native-epoll/src/main/c/io_netty_channel_unix_Socket.c
@@ -23,8 +23,10 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#include <arpa/inet.h>

 #include "netty_unix_socket.h"
+#include "netty_unix_errors.h"
 #include "io_netty_channel_unix_Socket.h"

 static jclass datagramSocketAddressClass = NULL;
diff --git a/transport-native-epoll/src/main/c/netty_unix_errors.h b/transport-native-epoll/src/main/c/netty_unix_errors.h
index ba3ad5d..e23f383 100644
--- a/transport-native-epoll/src/main/c/netty_unix_errors.h
+++ b/transport-native-epoll/src/main/c/netty_unix_errors.h
@@ -27,7 +27,7 @@ void netty_unix_errors_throwClosedChannelException(JNIEnv* env);
 void netty_unix_errors_throwOutOfMemoryError(JNIEnv* env);

 // JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods.
-jint netty_unix_exceptions_JNI_OnLoad(JNIEnv* env);
-void netty_unix_exceptions_JNI_OnUnLoad(JNIEnv* env);
+jint netty_unix_errors_JNI_OnLoad(JNIEnv* env);
+void netty_unix_errors_JNI_OnUnLoad(JNIEnv* env);

 #endif /* NETTY_UNIX_ERRORS_H_ */

@normanmaurer
Copy link
Member

@Scottmitch @ninja- actually I want to cut a release first (over the next days) and after that merge in as this is a massive change-set and I want to test it a bit more.

@Scottmitch
Copy link
Member Author

@ninja- I think I already fixed the issues the first time around (checkout the "Files" in github on this PR) ... maybe you are looking at old code?

@ninja-
Copy link

ninja- commented Oct 29, 2015

@Scottmitch hm ok maybe I forgot to git fetch your branch

@normanmaurer
Copy link
Member

@Scottmitch just cherry-pick it, so we can move on

Motivation:
transport-native-epoll is designed to be specific to Linux. However there is native code that can be extracted out and made to work on more Unix like distributions. There are a few steps to be completely decoupled but the first step is to extract out code that can run in a more general Unix environment from the Linux specific code base.

Modifications:
- Move all non-Linux specific stuff from Native.java into the io.netty.channel.unix package.
- io.netty.channel.unix.FileDescriptor will inherit all the native methods that are specific to file descriptors.
- io_netty_channel_epoll_Native.[c|h] will only have code that is specific to Linux.

Result:
Code is decoupled and design is streamlined in FileDescriptor.
@Scottmitch
Copy link
Member Author

Cherry-picked 4.0 (94ef424) 4.1 (dbbdbe1) master (e319a37)

@Scottmitch Scottmitch closed this Nov 2, 2015
@Scottmitch Scottmitch deleted the epoll_unix_decouple branch November 2, 2015 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants