Valhalla Legends Forums Archive | Web Development | WINSOCK call to recv stalls

AuthorMessageTime
taylorjonl
I am writing a proxy server for DII and have the following code.

[code] while(1)
{
printf("\t\tChecking for input on client/server sockets\n"); fflush(stdout);

//
int n = select(2, 0, &fds, 0, &tv);

if(n == 0)
continue;
if(n < 0)
break;

//
if(FD_ISSET(server, &fds))
{
printf("\t\t\tFound activity on server socket\n"); fflush(stdout);
// receive data from server
int size = recv(server, sbuffer.buffer, sbuffer.length, 0);
printf("\t\t\tReceived %d bytes of data\n", size); fflush(stdout);
if(size < 0)
{
// error reading data
printf("Error receiving data from server\n");
break;
}

// handle decompression here
// handle passing to module here

printf("\t\t\tSending %d bytes of data to client\n", size); fflush(stdout);
// send data to client
int sent = send(client, sbuffer.buffer, size, 0);
if(sent < 0)
{
// error reading data
printf("Error sending data to client\n");
break;
}
printf("\t\t\tReceived %d bytes of data\n", sent); fflush(stdout);
}
else
{
printf("\t\t\tFound activity on client socket\n"); fflush(stdout);
// receive data from client
int size = recv(client, cbuffer.buffer, cbuffer.length, 0);
printf("\t\t\tReceived %d bytes of data\n", size); fflush(stdout);
if(size < 0)
{
// error reading data
printf("Error receiving data from client\n");
break;
}

// handle compression here
// handle passing to module here

printf("\t\t\tSending %d bytes of data to server\n", size); fflush(stdout);
// send data to server
int sent = send(server, cbuffer.buffer, size, 0);
if(sent < 0)
{
// error reading data
printf("Error sending data to server\n");
break;
}
printf("\t\t\tReceived %d bytes of data\n", sent); fflush(stdout);
}
}
[/code]

What happens is that I get this output.

[code]Checking for input on client/server sockets
Found activity on server socket[/code]

It freezes on the recv call. How is that? 'select' is supposed to return when a socket is ready for input and then 'FD_ISSET' should tell me if it is that socket. Why is it freezing?

I am a newbie socket programmer but this should work shouldn't it?
December 17, 2003, 4:43 AM

Search