[lwip-users] Problem with lwip_select under Nucleus
From:
brivero
Subject:
[lwip-users] Problem with lwip_select under Nucleus
Date:
Fri, 25 May 2007 09:54:20 +0200
First of all I would like to thank you very much for
your help.
Next, I would like to explain the scenario in which
the problem takes place. I have found a standard Unix-sockets code in a
book and I have implemented it for Win32 with no problem. Since the objective
is to create a wrapper socket API in order to work with a few OSs (Win32,
LWIP&Nucleus,...), I tried to do the same for LWIP. The structure of
the application is as follows:
This daytime application works in Win32 (both server
and client in Win32) with no problem. But in LWIP(server in Win32 and client
in LWIP), before the server sends the packet, the client ends the program
closing the connection. This way, the client finds nothing to receive,
and the server has no connection for when he is going to execute the send
statement, causing a send error.
At this point, I supposed that for default, sockets
in LWIP were non-blocking (is this true???), and in consequence, the lwip_recv()
worked as non blocking. That would be the reason for which it would not
wait for the server to send, and the client execution would finish before
the server send statement. Introducing a one second sleep statement just before
lwip_recv() all worked ok.
That´s why I tried to implement a blocking recv()
by calling select just before recv(). But In spite of the 5 seconds timeval
structure used as input to this select, it did not wait. I used this select
looking at the readset in which the socket used to receive was set. At
first I was afraid that there was some kind of problem with the semaphores,
dealing with the port to Nucleus or something like that. But I have had
a close look at some other select calls, and as long as there is not a
connect before, they work perfectly waiting the timeval value etc.
I have gone into the select by debugging, and the
execution changes in sys_sem_wait_timeout(in sys.c). This function returs
a 1 when it does not wait, and a 0 if it does wait. Inside this function,
the problem is in the sys_timeout function, as it does let the sswt_cb.timeflag
with a 0 value when it does not wait, while it changes its value to 1 when
it waits.
I cannot find an explanation to what happens, but
actually, select does not wait when it is called after a connect. I would
be very pleased if somebody could give me some advice.