From 36b9a45c3bf5e06563315dd5d55e091d120fc07b Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Fri, 24 Feb 2017 15:32:48 -0600 Subject: [PATCH] netconn_write_partly cleanups This commit changes netconn_write_partly to use msg.w.offset to set bytes_written for both blocking and non-blocking connections This is correct because msg.w.offset is the canonical output from the do_write call and in the case that not all bytes were written, (a bug?) returning the full size to the caller is dangerous Lastly, this commit adds an assert for the blocking case to sanity check that all the bytes we requested were written. This will help catch bugs in do_write --- src/api/api_lib.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 1a40e994..e929e532 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -799,13 +799,14 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size, but if it is, this is done inside api_msg.c:do_write(), so we can use the non-blocking version here. */ err = netconn_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg)); - if ((err == ERR_OK) && (bytes_written != NULL)) { - if (dontblock) { - /* nonblocking write: maybe the data has been sent partly */ + if (err == ERR_OK) { + if (bytes_written != NULL) { *bytes_written = API_MSG_VAR_REF(msg).msg.w.offset; - } else { - /* blocking call succeeded: all data has been sent if it */ - *bytes_written = size; + } + /* for blocking, check all requested bytes were written, NOTE: send_timeout is + treated as dontblock (see dontblock assignment above) */ + if (!dontblock) { + LWIP_ASSERT("do_write failed to write all bytes", API_MSG_VAR_REF(msg).msg.w.offset == size); } } API_MSG_VAR_FREE(msg);