buglwIP - A Lightweight TCP/IP stack - Bugs: bug #31084, socket API returns always EMSGSIZE...


You are not allowed to post comments on this tracker with your current authentication level.

bug #31084: socket API returns always EMSGSIZE on non-blocking sockets if data size > send buffers

Submitted by:  Martin Velek <allew>
Submitted on:  Mon 20 Sep 2010 01:56:22 PM UTC  
Category:  sockets/netconn Severity:  3 - Normal
Item Group:  Feature Request Status:  Fixed
Privacy:  Public Assigned to:  Simon Goldschmidt <goldsimon>
Open/Closed:  Closed Planned Release:  None
lwIP version:  CVS Head

( Jump to the original submission)

Wed 24 Aug 2011 03:37:45 PM UTC, comment #6: 

Hello All,

I use lwip-1.4.0. I need using non-blocking socket. So I have applied patch done at 2011-07-22 20:05:24 on the Git master branch. I have only done changes described in this commit on the 1.4.0 release version.

I call lwip_send(1, data=0x2000c030, size=2050, flags=0x0) on a socket alreay in non blocking mode (no need using MSG_DONTWAIT flag).

Unfortunally, it fails with logs

lwip_send(1, data=0x2000c030, size=2050, flags=0x0)
tcp_write(pcb=0x20001810, data=0x2000c030, len=1072, apiflags=1)
tcp_write: queuelen: 0
tcp_write: queueing 6511:7047
tcp_write: queueing 7047:7583
tcp_write: 2 (after enqueued)
tcp_output_segment: 6511:7047
lwip_send(1) err=0 written=1072
lwip_send(1, data=0x2000c460, size=978, flags=0x0)
do_writemore: No more tcp_sndbuf available
lwip_send(1) err=-7 written=0

where "do_writemore: No more tcp_sndbuf available" is a log in code

do_writemore(struct netconn *conn)
 available = tcp_sndbuf(conn->pcb.tcp);
  if (available < len) {
    /* don't try to write more than sendbuf */
    len = available;
    if (dontblock){
        if (!len) {
            LWIP_DEBUGF(SOCKETS_DEBUG, ("do_writemore: No more tcp_sndbuf available\n"));
            err = ERR_WOULDBLOCK;
            goto err_mem;
    } else {

Do you think the patch is correct on 1.4.0 version or do I need the GIT master version? Do I have a problem with my buffers's size in opt.h?

Best Regards


SandrineLWI1565 <nexvisionuser245>
Fri 22 Jul 2011 08:06:43 PM UTC, comment #5: 

Fixed. Added a new function netconn_write_partly() (that adds a parameter to return how many bytes were written) to prevent changing the netconn API.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Fri 22 Jul 2011 06:17:44 PM UTC, comment #4: 

re original post:

> I cannot find exact description of this situation but I think
> that lwip should send as much as possible(and returns less than
> required) and if the output buffer is full it would return -1
> with error EAGAIN or EWOULDBLOCK.

The opengroup definition of send() (http://pubs.opengroup.org/onlinepubs/009695399/functions/send.html) says:
"If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does have O_NONBLOCK set, send() shall fail."
"The send() function is equivalent to [..] write() if no flags are used."

However, the description of write() (http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html) says (for file descriptors that are neither regular files, pipes or FIFOs):
"If the O_NONBLOCK flag is set, write() shall not block the thread. If some data can be written without blocking the thread, write() shall write what it can and return the number of bytes written. Otherwise, it shall return -1 and set errno to [EAGAIN]."

This implies to me that both behaviours are correct... However, I think the latter solution is more practical, as the definition of send() seems to apply better to DGRAM sockets than to STREAM sockets.

I have a working patch which I'll check in these days.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Tue 11 Jan 2011 02:03:14 PM UTC, comment #3: 

I agree with Simon's comment #2 but moving to 1.4.1 as I don't think this should prevent the release of 1.4.0.  If you have a working solution though it's fine to commit it earlier.

Kieran Mansley <kieranm>
Project Member
Mon 22 Nov 2010 09:07:43 PM UTC, comment #2: 

This is a bit more tricky, since we should not only be able to send if((size > TCP_SND_BUF) || ((size / TCP_MSS) >
TCP_SND_QUEUELEN)), but also if size > available space. This can only be detected in tcpip_thread, but we would need to give netconn_write a return parameter for this to indicate how much data has been sent.

I'd target this for 1.4.0 in order to have that version support as much of nonblocking sockets as we can make it to.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Sun 21 Nov 2010 03:29:35 PM UTC, comment #1: 

Yep, seems like sending as much as possible is the way to go. It's not as if we did this deliberately, I guess: it's only not been implemented, yet.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Mon 20 Sep 2010 01:56:22 PM UTC, original submission:  

I would like to open discussion about sending data over LWIP socket API(1.4.x) in the non-blocking or MSG_DONTWAIT mode.
The current implementation returns always EMSGSIZE if data size is more than ((size > TCP_SND_BUF) || ((size / TCP_MSS) >
TCP_SND_QUEUELEN)). I cannot find exact description of this situation but I think that lwip should send as much as possible(and  returns less than required) and if the output buffer is full it would return -1 with error EAGAIN or EWOULDBLOCK.

I have discovered this behavior during playing with xavante http
server + luasockets and LWIP socket API. Every accepted connection has option TCP_NODELAY and O_NONBLOCK. Every attempt to send data(larger html page) failed with EMSGSIZE.

I have tried similar behavior with Ubuntu 10.04.1 LTS,
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (int *)&optval, sizeof(optval));
fcntl(sockfd, F_SETFL,O_NONBLOCK);
n = write(newsockfd, buff, x);
Only with big x (e.g. 655360) there is
n = 212992


Martin Velek <allew>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by nexvisionuser245 (Posted a comment)
  • -email is unavailable- added by kieranm (Posted a comment)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by allew (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-07-22 goldsimon StatusIn Progress => Fixed
        Open/ClosedOpen => Closed
    2011-01-11 kieranm Planned Release1.4.0 => 1.4.1
    2010-11-22 goldsimon StatusNone => In Progress
        Assigned toNone => goldsimon
        Planned Release => 1.4.0

    Back to the top

    Powered by Savane 3.5