kohlschutter / junixsocket

Unix Domain Sockets in Java 7 and newer (AF_UNIX), AF_TIPC, AF_VSOCK, and more
Apache License 2.0
433 stars 114 forks source link

Enhancement request: Create a AFUNIXSocket from a file descriptor (or FileDescriptor) #91

Closed karstenspang closed 3 years ago

karstenspang commented 3 years ago

Background

I have a Java application running a C program in a child process. The C program is started using JNI code, which among other things sets up pipes for IPC between the two. The native method returns FileDescriptors which the Java code uses to create a FileInputStream and a FileOutputStream. Using Streams is not satisfactory, and I would very much like to use a Socket instead. This I would want to create from the file descriptor returned by socketpair() in my native code. I have looked into the code of junixsocket to see if there was a way to use that for my purpose, but at least I am not able to find an easy way of doing it.

Request

Please provide a way to create an AFUNIXSocket from an already open file descriptor. Maybe more info is needed, e.g. to tell that it is a stream or datagram socket, whether it is a listening socket on an already connected socket, etc. Or perhaps junixsocket could get that info using getsockopt().

kohlschuetter commented 3 years ago

Thanks for reporting the enhancement request! Please check out the new FileDescriptorCast class in version 2.4.0.