tried to fix the simult connection issue
This commit is contained in:
parent
44b997c69f
commit
7c6d817b26
1 changed files with 5 additions and 3 deletions
|
|
@ -62,8 +62,10 @@ int main(int argc, char **argv)
|
|||
printf("Echoserver listening on port: %d\n", ECHOPORT);
|
||||
while (quitFlag)
|
||||
{
|
||||
// set of active connections
|
||||
fd_set activeSet = socketList;
|
||||
// use the select() function here to check the set of sockets
|
||||
int selectedFD = select(maxFD+1, &socketList, NULL, NULL, NULL);
|
||||
int selectedFD = select(maxFD+1, &activeSet, NULL, NULL, NULL);
|
||||
// check to make sure select() didn't error out.
|
||||
if(selectedFD == -1)
|
||||
{
|
||||
|
|
@ -75,7 +77,7 @@ int main(int argc, char **argv)
|
|||
for(int fileIter = 0; fileIter <= maxFD; fileIter++)
|
||||
{
|
||||
// check to see if the file descriptor is in the set of sockets using FD_ISSET()
|
||||
if(FD_ISSET(fileIter, &socketList))
|
||||
if(FD_ISSET(fileIter, &activeSet))
|
||||
{
|
||||
// if the server socket is being written to/read from,
|
||||
if(fileIter == socketEchoFD)
|
||||
|
|
@ -111,7 +113,7 @@ int main(int argc, char **argv)
|
|||
// grab the data from the client, save to message.
|
||||
messageBytes = recv(fileIter, message, BUFFER_SIZE, 0);
|
||||
// make sure that the connection is still open before attempting to send.
|
||||
if(messageBytes == 0) // old: messageBytes <= 0
|
||||
if(messageBytes <= 0) // old: messageBytes <= 0
|
||||
{
|
||||
// if it is not open, close the socket and remove the socket from the socket list using FD_CLR()
|
||||
close(fileIter);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue