Monday, May 12, 2014

Android LocalServerSocket cannot handle more then 1024 connects/disconnects

For last couple of days I have been trying to fix one serious issue in my app. In Android 4.4.2 a client cannot connect /disconnect to server (created using LocalServerSocket Domain UNIX Socket)  more than 1024 times. How fucked up is that ?

I have uploaded my demo code here http://speedy.sh/NBSjr/SocketIssue.zip

I have posted questions on StackOverflow here http://stackoverflow.com/questions/23559827/emfile-too-many-open-files-error-while-connecting-to-localserversocket

and Google https://code.google.com/p/android/issues/detail?id=69594

Still got nothing!.

After few hours of pulling my hair out, I remembered Jackpal terminal emulator had some code to close the file descriptor. So I decided to take a look there.

https://github.com/jackpal/Android-Terminal-Emulator/blob/master/jni/termExec.cpp

If you pass the client socket file descriptor to his close function. it closes the connection. However it leaves a error on LogCat.

Please let me know if someone found a better solution.



No comments:

Post a Comment