Move write_offset from struct netconn to struct api_msg

This moves the write_offset variable from struct netconn to struct api_msg

This optimizes the storage by only having the space claimed when it is
needed (during a netconn_write_partly() call) and not throughout the
lifetime of the netconn

This also reduces code space/execution by not having to separately manage
clearing/checking write_offset from the current_msg pointer

Lastly, we also save execution by using msg.w.offset as the output
rather than marshaling the result to msg.w.len. Previously, len was used
as input length of dataptr and output for the write operation.
netconn_write_partly() also has access to msg.w.offset, so we can use
that
This commit is contained in:
Joel Cunningham
2017-02-17 13:26:16 -06:00
parent deaa6e9406
commit 4c76fd500c
4 changed files with 22 additions and 32 deletions

View File

@@ -784,6 +784,7 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
API_MSG_VAR_REF(msg).msg.w.dataptr = dataptr;
API_MSG_VAR_REF(msg).msg.w.apiflags = apiflags;
API_MSG_VAR_REF(msg).msg.w.len = size;
API_MSG_VAR_REF(msg).msg.w.offset = 0;
#if LWIP_SO_SNDTIMEO
if (conn->send_timeout != 0) {
/* get the time we started, which is later compared to
@@ -801,7 +802,7 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
if ((err == ERR_OK) && (bytes_written != NULL)) {
if (dontblock) {
/* nonblocking write: maybe the data has been sent partly */
*bytes_written = API_MSG_VAR_REF(msg).msg.w.len;
*bytes_written = API_MSG_VAR_REF(msg).msg.w.offset;
} else {
/* blocking call succeeded: all data has been sent if it */
*bytes_written = size;