From 005e5f2f72e85e41ca96ecb4b82c735a55a4c404 Mon Sep 17 00:00:00 2001 From: fbernon Date: Mon, 26 Mar 2007 15:37:48 +0000 Subject: [PATCH] api_lib.c (from Dmitry Potapov) : patch for netconn_write(), fixes a possible race condition which cause to send some garbage. It is not a definitive solution, but the patch does solve the problem for most cases. --- CHANGELOG | 5 +++++ src/api/api_lib.c | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 57412a43..a88344c7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -78,6 +78,11 @@ HISTORY ++ Bug fixes: + 2007-03-26 Frédéric Bernon (based on patch from Dmitry Potapov) + * api_lib.c: patch for netconn_write(), fixes a possible race condition which cause + to send some garbage. It is not a definitive solution, but the patch does solve + the problem for most cases. + 2007-03-22 Frédéric Bernon * api_msg.h, api_msg.c: Remove obsolete API_MSG_ACCEPT and do_accept (never used). diff --git a/src/api/api_lib.c b/src/api/api_lib.c index b18d919f..128ca288 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -589,7 +589,7 @@ err_t netconn_write(struct netconn *conn, const void *dataptr, u16_t size, u8_t copy) { struct api_msg msg; - u16_t len; + u16_t len, sndbuf; if (conn == NULL) { return ERR_VAL; @@ -608,16 +608,15 @@ netconn_write(struct netconn *conn, const void *dataptr, u16_t size, u8_t copy) msg.msg.msg.w.copy = copy; if (conn->type == NETCONN_TCP) { - if (tcp_sndbuf(conn->pcb.tcp) == 0) { + while ((sndbuf = tcp_sndbuf(conn->pcb.tcp)) == 0) { sys_sem_wait(conn->sem); if (conn->err != ERR_OK) { goto ret; } } - if (size > tcp_sndbuf(conn->pcb.tcp)) { - /* We cannot send more than one send buffer's worth of data at a - time. */ - len = tcp_sndbuf(conn->pcb.tcp); + if (size > sndbuf) { + /* We cannot send more than one send buffer's worth of data at a time. */ + len = sndbuf; } else { len = size; }