[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Nonblocking sockets problem
From: |
Åke Forslund |
Subject: |
Re: [lwip-users] Nonblocking sockets problem |
Date: |
Wed, 14 Mar 2012 08:19:28 +0000 |
Hi again, this is not the original code but a implementation of the problem in
our simple telnet-server for debug. Code below. In our original code we use
ioctlsocket() to set non-blocking but using lwip_ fcntl() makes no difference.
void task_telnet(void * arg)
{
int lSocketRecv;
u32_t lAddrSize;
struct addrinfo *sListenAddr, hints;
char buffer[1024];
unsigned short u16L_buffPtr = 0;
int nbytes;
unsigned char one = 1;
LWIP_DEBUGF(SOCKETS_DEBUG, ("Recv Task started!\n"));
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
lwip_getaddrinfo("0.0.0.0", "23", &hints, &sListenAddr);
lSocketRecv = lwip_socket(sListenAddr->ai_family, sListenAddr->ai_socktype,
sListenAddr->ai_protocol);
lwip_bind(lSocketRecv, sListenAddr->ai_addr, sListenAddr->ai_addrlen);
//ioctlsocket(lSocketRecv, FIONBIO, &one);
lwip_fcntl(lSocketRecv, F_SETFL, lwip_fcntl(lSocketRecv, F_GETFL, 0) |
O_NONBLOCK);
lwip_listen(lSocketRecv, 128);
while (1)
{
os_dly_wait(100);
lAddrSize = sizeof(sListenAddr);
new_fd = lwip_accept(lSocketRecv, (struct sockaddr *)&sListenAddr,
&lAddrSize);
lwip_write(new_fd, "Welcome to the jungle\n\n\r>", 25);
str_tcpTty.active = 1;
while (1)
{
nbytes = lwip_read(new_fd, &buffer[u16L_buffPtr], 1);
if (nbytes > 0)
{
u16L_buffPtr += nbytes;
if (buffer[u16L_buffPtr-1] == 'q') // q ends the session
break; // Terminate session
if (!testParseBuff((char *)buffer, u16L_buffPtr, &str_tcpTty)) //
complete command found and parsed
{
u16L_buffPtr = 0;
lwip_write(new_fd, "\r>", 2);
}
}
os_dly_wait(6);
}
str_tcpTty.active = 0;
u16L_buffPtr = 0;
lwip_close(new_fd);
}
}
At the moment we can manage without nonblocking sockets using lwip_setsockopt()
to set a timeout for the socket, but we are still curious as to why
nonblocking-sockets don't work for us.
Best regards
/Åke
-----Ursprungligt meddelande-----
Från: address@hidden [mailto:address@hidden För Simon Goldschmidt
Skickat: den 13 mars 2012 09:06
Till: Mailing list for lwIP users
Ämne: Re: [lwip-users] Nonblocking sockets problem
"Åke Forslund" <address@hidden> wrote:
> We added some debug-prints in the case NETCONN_EVT_RCVPLUS in
> event_callback() showing that rcvevent was only incremented when the
> socket was set as blocking.
>
> I'm having trouble seeing where to probe for the error so if anyone
> has an idea of where to look, I would be very thankful. Is there any
> options in lwipopt that could trigger this behavior?
> From where is event_callback() triggered normally, it's added as a
> callback to the netconnection-object but where is this callback called?
The callback is called via the macro API_EVENT(), which is mainly called with
RECVPLUS from the raw API recv- and accept-callbacks in api_msg.c (those are
called from tcpip_thread). However, it is also called with RECVMINUS from
netconn_recv_data() in api_lib.c (called from your application thread).
Which type of socket are you using (tcp, udp, raw)?
Could you provide a simple test code that reproduces this, that would make it
much easier for me to check.
Thanks,
Simon
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users