thank you for your advice, you open my mind. My new code, i am following
your advice but this solution will be useful?
We have eight TCP socket, => 8 sockect connection, and 8 socket for data( 5
to answer, and 3 for requets from PC). The customer said me that.
how do i reset the fd struct?
Thanks
Oscar
//Using of select function to wait for the accept connection
FD_ZERO(&acceptset);
maxfd=0;
//Add the 8 socket to wait the accept connection and then add the
accept socket
for(i=0;i<NUM_SOCKET;i++)
{
FD_SET(lSocket[i], &acceptset);
if (lSocket[i]> maxfd)
maxfd = lSocket[i];
}
while(1){
// Check for received packets on configured sockets (blocking )
ret = select(maxfd+1, &acceptset, NULL, NULL, NULL);
if (ret > 0) //No error
{
//Analyze with socket receive
for(i=0;i<NUM_SOCKET;i++)
{
//socket accept
//First thing see the connection
if (FD_ISSET(lSocket[i], &acceptset) && (i<NUM_SOCKET))
{
//connection receive ==> then accept
aSocket[i]= accept(lSocket[i],(struct
sockaddr*)&sRemoteAddr[i],(socklen_t *)sizeof(sRemoteAddr[i]));
if(aSocket[i]>0)
{
if (i<3)
{
FD_SET(aSocket[i], &acceptset); //Add the three
socket to wait for the receive data
if (aSocket[i]> maxfd)
maxfd = aSocket[i];
}
else
CloseConnectionPC(aSocket,lSocket );
FD_CLR(lSocket[i], &acceptset);
}
}
}
//Check data for socket 1
if (FD_ISSET(aSocket[0], &acceptset))
ProcessRequestPC_to_RTU(aSocket[0]);
//Check data for socket 2
if (FD_ISSET(aSocket[1], &acceptset))
ProcessRequestPC_to_PCU(aSocket[1]);
//Check data for socket 3
if (FD_ISSET(aSocket[2], &acceptset))
ProcessRequestPC_Finish(aSocket[2]);
}
}
}
On Tue, Sep 29, 2009 at 1:18 PM, Kieran Mansley <[email protected]> wrote:
> A few obvious things are:
>
> 1) you're using the select() API incorrectly. This is just like normal
> select: you need to reset the acceptset each time you go round the loop.
>
> > /* Number of raw connection PCBs */
> > #define MEMP_NUM_RAW_PCB 10
>
> You don't need any of those, I think.
>
> > /* MEMP_NUM_TCP_PCB: the number of simultaneously active TCP
> > connections. */
> > #define MEMP_NUM_TCP_PCB 12
>
> You need more than 12 of those: at least 16 (as I think I mentioned
> before): one for each listening socket and one for each data socket.
>
> You should increase the number of netbufs and netconns to match.
>
> Most likely there is some resource shortage (e.g. PCBs, buffers, or
> similar) after accepting the first connection that means the others are
> dropped. If you can turn on debug in lwIP, or access the lwIP stats,
> these should help show you what is going wrong and so point the way to
> correcting it.
>
> Kieran
>
>
>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users