lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] recv returning zero after 4 connections


From: Mullanix, Todd
Subject: [lwip-users] recv returning zero after 4 connections
Date: Mon, 7 Mar 2011 16:18:02 -0600

Hi All,

 

First of all I’m using NO_SYS=0 and SYS_LIGHTWEIGHT_PROT = 1 and the OS is SYS/BIOS.

 

I have a thread A that opens a TCP socket and waits in the accept(). Once a connection is made, thread A gives the new socket to a thread wokerN (where there can be 5 worker threads) to handle the sending/receiving. Thread A goes back and waits for a new request.

 

Thread A pseudo code

lSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

       

memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));

sLocalAddr.sin_family = AF_INET;

sLocalAddr.sin_len = sizeof(sLocalAddr);

sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);

sLocalAddr.sin_port = htons(1000);

       

bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr));

listen(lSocket, 5);

while (1) {           

   clientfd = accept(lSocket, (struct sockaddr*)&client_addr, (socklen_t *)&addrlen);       

 

   give clientfd to a worker thread… 

}

 

The worker does the following echo once it is told to run.

 

WorkerThread pseudo code

while (flag) {

   nbytes = recv(clientfd, (char *)&buffer, sizeof(buffer),0);                                       

   if (nbytes > 0) {

       send(clientfd, (char *)&buffer, nbytes, 0 );               

   }

   else {

       close(clientfd);

       flag = FALSE;

   }

}

 

This works great for the first 2 requests. I see worker1 and worker2 start with clientfd of 1 and 2. Once I start a third request, I see the request come in and the third thread start to run. For a few seconds all three connections streaming, then either W1 or W2 thread receives an nbytes=0 and closes the socket. I’ll try again to get the third connection going, and it runs for a couple seconds and then one of the threads gets a nbytes=0.

 

If I only exit if nbytes is negative (basically nop if nbytes=0), then all three streams halt.

 

Any ideas what to look at? The mem lwIP_stats looked ok.

 

Thanks,

Todd


reply via email to

[Prev in Thread] Current Thread [Next in Thread]