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

SocketTimeout not handled properly #22

Open
GoogleCodeExporter opened this issue Mar 29, 2016 · 1 comment
Open

SocketTimeout not handled properly #22

GoogleCodeExporter opened this issue Mar 29, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 1 Jan 2012 at 8:41

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 4 Jan 2012 at 9:47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant