why socket function recv is so slowly

recently , I meet a question about the function recv of socket programming, let me introduce the background of the question ,
now I have a client and server in different pc , the client is linux OS without any 3th network libray, such ACE , curl ... and the server is Window OS - and I have deployed the http server - Apache , in my project , I will send http post request from socket programming to server which is a php website timely (about 1 time 2 seconds), and the post data is encapluted with Json format , that is the http Content-Type:application/json, but when I send the request , then I recv the response with Json format from server (in fact the response data is not big < 5*1024), but in the next , very slowly , about more than 10 seconds ,then I can get the response wholly , sometimes can not the any response Json , I suppose the reason is bacause the unfit buf length , I tried 1024 , 2048 , 512 ... , and the result is disappointed , the below is my recv code , could you help to see it ? thanks in advance , BTW , I use SOCK_STREAM in the socket

void Communication::receive(char buffer[], int BUFFER_SIZE){
static const int small_buf = 512;
char buf[small_buf];
int length = 0;
char* pp = buffer;
length = recv(socket_,buf,small_buf,0);
if(length < 0)
connect_state_ = false;
}else if(length == small_buf){
connect_state_ = true;
memcpy(pp, buf, small_buf);
pp = pp+small_buf;
}else if(length < small_buf && length > 0)
connect_state_ = true;
memcpy(pp, buf, length);
pp = pp + length;
}else if(length == 0)
}while(length > 0);
//merge the small_buf into a big buffer which is big enough (50*1024), which is one of function's param
Next time, please post your code using the code tags (under format).

You can change options on the socket by using IOCTL calls to specify the buffer size of the underlying socket internals. That might point you into where the slowdown is happening.
Topic archived. No new replies allowed.