Link to home
Start Free TrialLog in
Avatar of Taplar
TaplarFlag for United States of America

asked on

C/C++ Server Request Deadlock

Lang: C/C++
OS: Ubuntu
Compiler: g++
Interface to server: Firefox web browser
Problem: Loop Deadlocks

while ( ( n = recv(slave_socket, buffer_pointer, 255, 0) ) > 0) {
...prints to server terminal for time being...
}

buffer is 256, request is accepted, loop and browser deadlock
Browser continuely waits for a response, server continuely waits for packets.

Temporary Fix: buffer is 2048, replaced loop with if statement

if ( ( n = recv(slave_socket, buffer_pointer, 2047, 0) ) > 0 ) { ... }

Question: I would like to keep using the loop and fix the deadlocking, or atleast find another way so that the buffer can be dynamic so to accomidate any request and also to not waste space.
ASKER CERTIFIED SOLUTION
Avatar of Adrien de Croy
Adrien de Croy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Taplar

ASKER

n is a signed int, there isn't an issue there.  ioctlsocket is a windows function, not a linux function.  I've looked for a reference to ioctl() to find the parameters to get how much data is in the socket waiting to be read, but I haven't found it yet.  Could you point me to a reference?
Avatar of Taplar

ASKER

I found the solution thanks to you.  I can use  ioctl(file_descriptor, FIONREAD, &byte_count_variable) to see how much data is waiting to be read and loop off of that.  Works great.  Thanks.