leoadonia / junixsocket

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

socket.setSoTimeout(100) causes error "protocol not available" #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
code:
    File socketFile = new File("/tmp/cgi.socket");
    AFUNIXSocket sock = AFUNIXSocket.newInstance();
    sock.connect(new AFUNIXSocketAddress(socketFile));
    sock.setSoTimeout(12000);
    sock.close();

output:
org.newsclub.net.unix.AFUNIXSocketException: Protocol not available
    at org.newsclub.net.unix.NativeUnixSocket.setSocketOptionInt(Native Method)
    at org.newsclub.net.unix.AFUNIXSocketImpl.setOption(AFUNIXSocketImpl.java:319)
    at java.net.Socket.setSoTimeout(Socket.java:1003)

is there any solution? thanks~~

Original issue reported on code.google.com by kaif...@gmail.com on 16 Jul 2010 at 7:42

GoogleCodeExporter commented 8 years ago
Hi Kaifuxu,

thanks for hinting me at this. I could not reproduce the "Protocol not 
available" error, but on OS X I was able to get an "invalid argument" error in 
some cases.

This happens if the socket is closed before Socket#setSoTimeout gets called, 
for example when the server decides to block the request.

In SVN trunk, I have added a new JUnit testcase (SoTimeoutTest) to trigger the 
problem.

Please let me know if that testcase fails for you.

Best,
Christian

Original comment by ckkohl79 on 20 Jul 2010 at 7:51

GoogleCodeExporter commented 8 years ago

Original comment by ckkohl79 on 20 Jul 2010 at 8:14

GoogleCodeExporter commented 8 years ago
I got Milestone-Release1.3 from svn and it works~
thanks for your great work~

Original comment by kaif...@gmail.com on 22 Jul 2010 at 2:02

GoogleCodeExporter commented 8 years ago
Thanks for the feedback, kaifuxu.

Does this mean that, using the SVN trunk, you cannot reproduce the "protocol 
not available" error? Or will this error only occur if the socket was closed 
prematurely?

Best,
Christian

Original comment by ckkohl79 on 22 Jul 2010 at 10:19

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi, Christian

I did as below on Ubuntu Desktop 10.04 and SuSE Enterprise Server 10.2 ~

# wget http://junixsocket.googlecode.com/files/junixsocket-1.2-bin.tar.bz2 
# tar -xf junixsocket-1.2-bin.tar.bz2
# mkdir -p /opt/newclub/lib-native
# chmod +x junixsocket-1.2/lib-native/libjunixsocket-linux-1.5-i386.so
# cp junixsocket-1.2/lib-native/libjunixsocket-linux-1.5-i386.so 
/opt/newclub/lib-native

and run my program,  then the error happened. 

so I checked out the source from svn :

# rm -fr /opt/newclub
# svn co http://junixsocket.googlecode.com/svn/trunk/junixsocket .
# ant -Djdk.home=/usr/lib/jvm/java-6-sun -Dgcc=/usr/bin/gcc gcc-linux.32
# mkdir /root/lib-native
# cp lib-native/libjunixsocket-linux-1.5-i386.so /root/lib-native/

and added the following line into my java source:
System.setProperty("org.newsclub.net.unix.library.path","/root/lib-native"); 

then no error occured

My Java Souce Code:

import java.io.File;
import org.newsclub.net.unix.AFUNIXSocket;
import org.newsclub.net.unix.AFUNIXSocketAddress;

public class Test {
    public static void main(String[] args) throws Exception {
        System.setProperty("org.newsclub.net.unix.library.path","/root/lib-native"); 
        File socketFile = new File("/tmp/fcgi.socket");
        AFUNIXSocket sock = AFUNIXSocket.newInstance();
        sock.connect(new AFUNIXSocketAddress(socketFile));
        sock.setSoTimeout(12000);
        sock.close();
    }
}

Best,
kaifuxu

Original comment by kaif...@gmail.com on 26 Jul 2010 at 2:34

GoogleCodeExporter commented 8 years ago
Thanks, kaifuxu.

Considerung this bug fixed in 1.3. Closing.

Original comment by ckkohl79 on 10 Aug 2010 at 5:48