Socket read time consuming

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.
How much data are you reading?

Have you changed any socket options?
Last edited on
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.
Mmm, dunno. Maybe the sender hasn't sent anything yet.

What values are set for the timeouts?
Pull up Wireshark and see if maybe the client is just being slow.
Hi,

Time out is 30000 seconds. I will try with Wireshark.
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?
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.
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.