Taplar
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER