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

java.net.SocketTimeoutException: Resource temporarily unavailable #85

Closed kuailelijuan closed 3 years ago

kuailelijuan commented 3 years ago

1.exception info: java.net.SocketTimeoutException: Resource temporarily unavailable at org.newsclub.net.unix.NativeUnixSocket.read(Native Method) at org.newsclub.net.unix.AFUNIXSocketImpl$AFUNIXInputStream.read(AFUNIXSocketImpl.java:325) at java.io.InputStream.read(InputStream.java:101) at com.my.server.junixsocket.UnixSocketServer.doServeSocket(UnixSocketServer.java:101) at org.newsclub.net.unix.server.AFUNIXSocketServer$2.run(AFUNIXSocketServer.java:354) at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:172) Closed: AFUNIXSocket[fd=java.io.FileDescriptor@4b545c2f;addr=org.newsclub.net.unix.AFUNIXSocketAddress[port=0;path=/user/demo/unix_domian_sock]] Active connections: 0; waiting for the next connection...

  1. client write by c++

    include

    include <sys/socket.h>

    include <sys/un.h>

int main(){ int sock; sockaddr_un s_un; int n; char buf[128];

sock = socket(AF_UNIX, SOCK_STREAM, 0); if(sock < 0){ perror("socket"); return 1; }

s_un.sun_family = AF_UNIX; strcpy(s_un.sun_path, "/user/demo/unix_domian_sock"); if(connect(sock, (sockaddr*)&s_un, sizeof(s_un)) != 0){ perror("connect"); return 1; } write(sock, "RC", 2); printf("after connect\n"); memset(buf, 0, sizeof(buf)); n = read(sock, buf, sizeof(buf)); if(n < 0){ perror("read"); return 1; }

printf("%s\n", buf); close(sock); return 0; } 3.server write by java

public static void main(String[] args) { String socketName = "/user/demo/unix_domian_sock"; try {

        File file = new File(socketName);

        if(!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }

        final SocketAddress listenAddress = socketAddress(socketName);
        UnixSocketServer server = new UnixSocketServer(listenAddress);
        server.setMaxConcurrentConnections(1);
        server.setServerTimeout(0);
        server.setSocketTimeout(100);
        server.setServerBusyTimeout(100);
        server.start();

        while (true) {
            Thread.sleep(1000);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
kohlschuetter commented 3 years ago

Hi kuailelijuan,

Your code doesn't compile. Please provide the full source code as file attachments.

It would be very helpful to understand what platform you're seeing this issue on (the error is coming from the system). Please also provide the output of java -jar junixsocket-selftest-2.3.2-jar-with-dependencies.jar (or, even better, use the selftest jar from the current pre-release version 2.3.3).

Lastly, you have a typo in the filename (domian instead of domain).

Best, Christian

kohlschuetter commented 3 years ago

Closing due to inactivity. Please try again with the latest junixsocket version (2.3.3 or newer) and re-open this issue (with a complete code fragment) if necessary