Socket read time consuming

Jul 21, 2014 at 10:36am
Hi,

I have developed a multi threaded tcp server application using C. In my server it's getting 200 - 300 milliseconds to read something.

1
2
3
4
5
void readRequest(int sockFD,unsigned char *readData){
     int readLen = 0;
     readLen = read(sockFD,readData.sizeof(readData));
     readData[readLen] = '\0';
}


Any idea?

Thank you.
Jul 21, 2014 at 2:05pm
How much data are you reading?

Have you changed any socket options?
Last edited on Jul 21, 2014 at 2:06pm
Jul 23, 2014 at 7:33am
Hi,

Sorry for the delay. I have to read maximum 10 bytes And I did change some socket options.

1
2
3
4
5
6
7
8
9

int optval = 1;
optlen = sizeof(optval);

setsockopt(sockFd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
setsockopt(sockFd, IPPROTO_TCP, TCP_NODELAY, &optval, optlen);
setsockopt (sockFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(timeout));
setsockopt (sockFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,sizeof(timeout));


Any idea?

Thank you.
Jul 23, 2014 at 12:39pm
Mmm, dunno. Maybe the sender hasn't sent anything yet.

What values are set for the timeouts?
Jul 23, 2014 at 1:32pm
Pull up Wireshark and see if maybe the client is just being slow.
Jul 24, 2014 at 8:38am
Hi,

Time out is 30000 seconds. I will try with Wireshark.
Jul 24, 2014 at 1:49pm
Are you sure the data is available for read and it's not just waiting for the response? Have you checked the otherr size of the comms to be sure that's not where the delay is?
Jul 28, 2014 at 5:42am
Hi,

Actually this server is developed for HSM Secure Execution Engine environment. I don't know whether this issue comes from the SEE environment or my code. Anyone did this before?

yes I am sure that the data is available for read. Yes I did check the client side.
Jul 28, 2014 at 9:05am
yes I am sure that the data is available for read.
How do you know?

Maybe there's more to your code than you've posted, but what you shown is ok.

Yes I did check the client side.
I meant check the server side. But appears you don't really have access to it. But you can probably write your own mock server and see if you have problems with that.
Topic archived. No new replies allowed.