From 15d56dd9dac2489ac8b2b79d39cdce711ef56c14 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 10 Apr 2014 11:23:18 +0800 Subject: [PATCH] truncated send always callback on writeable Suggested by a Windows log where leaf.jpg meets EAGAIN and after issuing the truncated send buffer, never sends any more https://github.com/warmcat/libwebsockets/issues/111#issuecomment-39873129 Added note in README.coding about WRITEABLE callbacks able to be generated by lws. Signed-off-by: Andy Green --- README.coding | 14 ++++++++++++++ lib/output.c | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.coding b/README.coding index a34211e..333011c 100644 --- a/README.coding +++ b/README.coding @@ -67,6 +67,20 @@ in the ...WRITEABLE callback. See the test server code for an example of how to do this. +Do not rely on only your own WRITEABLE requests appearing +--------------------------------------------------------- + +Libwebsockets may generate additional LWS_CALLBACK_CLIENT_WRITEABLE events +if it met network conditions where it had to buffer your send data internally. + +So your code for LWS_CALLBACK_CLIENT_WRITEABLE needs to own the decision +about what to send, it can't assume that just because the writeable callback +came it really is time to send something. + +It's quite possible you get an 'extra' writeable callback at any time and +just need to return 0 and wait for the expected callback later. + + Closing connections from the user side -------------------------------------- diff --git a/lib/output.c b/lib/output.c index 9c98cae..7419b8e 100644 --- a/lib/output.c +++ b/lib/output.c @@ -148,8 +148,9 @@ handle_truncated_send: lwsl_info("***** %x partial send completed\n", wsi); /* done with it, but don't free it */ n = real_len; - } else - libwebsocket_callback_on_writable( + } + /* always callback on writeable */ + libwebsocket_callback_on_writable( wsi->protocol->owning_server, wsi); return n; -- 2.7.4