Developed a networking library using Android NDK (2.3 and above)
Scenerio
- Third-party application (TCP socket based ) communicates to our native library.
- Our library processes that data and in turns communicates to a server using TCP socket communication. The communication is bi-directional.
We have designed and implemented socket communication mechanism between third-party-app and our library for IPC. our-library is utilizing the third-party-app port (default: 6700) to establish the connection between server.
So, it is kind of loopback connection through which communication is happening between our library and third-party-app.
int on = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
bind(s, (struct sockaddr *) &sin, sizeof (sin));
Problem Area
Everything works fine, but due to it, the performance is downgraded. If network library is not present , the communication is very fast. To verify that issue lies in loopback tcp socket, we removed all internal processing of library. The library just acting as pseudo-server (pass-through) for the application. The app sends data to localhost and socket, and the library just forwards it to server as it is.
> Queries
So is there any way to improve performance ?
1) What about UNIX-domain socket on the Android , can they be used between app and our library?
2) Can Binders be used to communicate between User level application and native Android library ?
3) Or Do we have something similar to IOCTL SIO_LOOPBACK_FASTPATH (The TCP loopback fast path is enabled by the socket IOCTL SIO_LOOPBACK_FASTPATH applied to the sending and receiving sockets.) Transmission Control Protocol (TCP) Loopback Optimization
Many Thanks in advance