lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] an idea how to implement sending non-blocking sockets(LWIP1


From: Martin Velek
Subject: [lwip-users] an idea how to implement sending non-blocking sockets(LWIP1.4.x)
Date: Thu, 30 Sep 2010 12:54:58 +0200

Hello,

I have posted a feature request (or bug)
http://savannah.nongnu.org/bugs/?31084 and I would like to discuss a
suggestions how to how to implement non-blocking sockets in some
reasonable way. I think the lwip could behave as described in the
feature request (if a socket is in the non-blocking mode, the LWIP
tries to send as much as possible (free space in send buffer)).
However I do not know exactly the internal structure of LWIP so that
the following modification can break something.

The main idea is to determine free space in buffer and send only
MIN(size, free space in send buffer).

lwip-1.4.0.rc1

api.h, add below line 160 - size_t sent;
--need to modify netconn structure to have got a place where will be
stored number of characters sent.

sockets.c, line 767-773 - Comment out or remove the the checking for
flags or nonblocking netconn.

sockets.c, line 777 - change to ((flags & MSG_DONTWAIT) ||
netconn_is_nonblocking(sock->conn) ? NETCONN_DONTBLOCK : 0);
--set write_flags NETCONN_DONTBLOCK a) MSG_DONTWAIT is set or b) the
netconn is non-blocking

sockets.c, line 782 - change to return (err == ERR_OK ?
(int)sock->conn->sent : -1);
--return only number of characters sent or error

api_lib.c,add below line 596 - conn->sent = msg.msg.msg.w.len;
--store number of characters sent to the netconn structure

api_msg.c,add below line 1329 -
 if (NETCONN_DONTBLOCK & msg->msg.w.apiflags) {
        msg->msg.w.len = MIN(msg->msg.w.len, tcp_sndbuf(msg->conn->pcb.tcp));
}
if (msg->msg.w.len > 0) {
--MIN is some kind of selecting minimum, e.g. #define MIN(a,b) ((a)>(b)?(b):(a))

api_msg.c,add below line 1346 -
} else {
msg->err = ERR_WOULDBLOCK;
}

However there are some issues
If the lwip_send ends with EAGAIN  or  EWOULDBLOCK, can be lwip_select
able to detect event in case data was sent before calling
lwip_select?
What about other types of sockets?(A more sophisticated check should
be provided)

!!!The lwip sometimes hangs with segmentation fault on api_msg.c,
(original file) line 1204.

Regards,
Martin



reply via email to

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