mhlkmn0108 / junixsocket

Automatically exported from code.google.com/p/junixsocket
1 stars 0 forks source link

SocketTimeout not handled properly #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.m_serverSocket = AFUNIXServerSocket.newInstance();
2.m_serverSocket.bind(new AFUNIXSocketAddress(socketFile));
3.m_serverSocket.setSoTimeout(30 * 1000); // timeout for 30 seconds
4. In run(), call m_serverSocket.accept() in a try/catch. Catch 
SocketTimeoutException to print debug and continue...

What is the expected output? What do you see instead?
Expect to see a ServerTimeoutException, as specified in java.net.ServerSocket. 
Since this class extends ServerSocket, and no mention of different behavior is 
specified, would expect same behavior as documented in super class.

Instead:
org.newsclub.net.unix.AFUNIXSocketException: Resource temporarily unavailable 
(socket: <path to socket>)
        at org.newsclub.net.unix.NativeUnixSocket.accept(Native Method)
        at org.newsclub.net.unix.AFUNIXSocketImpl.accept(AFUNIXSocketImpl.java:58)
        at org.newsclub.net.unix.AFUNIXServerSocket.accept(AFUNIXServerSocket.java:104)

What version of the product are you using? On what operating system?
1.3

Please provide any additional information below.

Original issue reported on code.google.com by droid.l...@gmail.com on 1 Jan 2012 at 8:41

GoogleCodeExporter commented 9 years ago
Same for me, quickfix:

### Eclipse Workspace Patch 1.0
#P junixsocket
Index: src/main/org/newsclub/net/unix/org_newsclub_net_unix_NativeUnixSocket.c
===================================================================
--- 
src/main/org/newsclub/net/unix/org_newsclub_net_unix_NativeUnixSocket.c (revisio
n 111)
+++ 
src/main/org/newsclub/net/unix/org_newsclub_net_unix_NativeUnixSocket.c (working
 copy)
@@ -68,11 +68,20 @@
  * @author Christian Kohlschuetter
  */
    void org_newsclub_net_unix_NativeUnixSocket_throwException(JNIEnv* env, char* message, jstring file) {
-       jclass exc = (*env)->FindClass(env, 
"org/newsclub/net/unix/AFUNIXSocketException");
-       jmethodID constr = (*env)->GetMethodID(env, exc, "<init>", 
"(Ljava/lang/String;Ljava/lang/String;)V");
+       jclass exc;
+       jmethodID constr;
        jstring str = (*env)->NewStringUTF(env, message);
-       jthrowable t = (jthrowable)(*env)->NewObject(env, exc, constr, str, file);
-        (*env)->Throw(env, t);
+       jthrowable t;
+       if (errno == EAGAIN || errno == EWOULDBLOCK) {
+         exc = (*env)->FindClass(env, "java/net/SocketTimeoutException");      
+         constr = (*env)->GetMethodID(env, exc, "<init>", "(Ljava/lang/String;)V");
+         t = (jthrowable)(*env)->NewObject(env, exc, constr, str);
+       } else {
+        exc = (*env)->FindClass(env, "org/newsclub/net/unix/AFUNIXSocketException");
+        constr = (*env)->GetMethodID(env, exc, "<init>", 
"(Ljava/lang/String;Ljava/lang/String;)V");
+        t = (jthrowable)(*env)->NewObject(env, exc, constr, str, file);
+       }
+           (*env)->Throw(env, t);
    }

    int org_newsclub_net_unix_NativeUnixSocket_getFD(JNIEnv * env, jobject fd) {

Original comment by paullus...@gmail.com on 4 Jan 2012 at 9:47