Hi,
When I try to do a read() on a socket, it works perfectly fine. But, when I put the same thing in a while loop and try to read into a buffer, it stalls my server. Can anyone suggest a solution?
Update:
Thanks for the responses. I was so much into the issue that I assumed everyone else in the world knew what I'm speaking about. Sorry for that. Here are more details:
The programming language I'm using is C++. I have the following code which worked perfectly fine.
char LOCALBUFFER[BUFFER_LENGTH] = "";
read(socketDescriptor, LOCALBUFFER, sizeof(BUFFER)-1);
...Did something with the info...
Quickly realizing what a dumb mistake I made, I changed this code to:
char LOCALBUFFER[BUFFER_LENGTH] = "";
string *data = new string(); //This absolutely has to be a pointer for some reasons.
while(read(socketDescriptor, LOCALBUFFER, sizeof(BUFFER)-1)!=-1) {
cout << "Debug Point 1" << endl;
*data += LOCALBUFFER;
cout << "Debug Point 2" << endl;
bzero(LOCALBUFFER, sizeof(BUFFER));
cout << "Debug Point 3" << endl;
}
cout << "Debug Point 4" << endl;
The socket has been setup as non-blocking too. Now, all I see in the output is:
Debug Point 1
Debug Point 2
Debug Point 3
And then the code hangs.