From fe1889b9236c002cf7b2ce340bbd591ba5312826 Mon Sep 17 00:00:00 2001 From: Kedar Sovani Date: Fri, 29 Jun 2018 09:22:18 +0530 Subject: [PATCH] sh2lib: Fix a bug in send --- .../http2_request/components/sh2lib/sh2lib.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/protocols/http2_request/components/sh2lib/sh2lib.c b/examples/protocols/http2_request/components/sh2lib/sh2lib.c index 8273265aef..4447a12803 100644 --- a/examples/protocols/http2_request/components/sh2lib/sh2lib.c +++ b/examples/protocols/http2_request/components/sh2lib/sh2lib.c @@ -58,22 +58,19 @@ static ssize_t callback_send(nghttp2_session *session, const uint8_t *data, int pending_data = length; /* Send data in 1000 byte chunks */ - while (copy_offset != (length - 1)) { + while (copy_offset != length) { int chunk_len = pending_data > 1000 ? 1000 : pending_data; int subrv = callback_send_inner(hd, data + copy_offset, chunk_len); if (subrv <= 0) { - if (copy_offset) { - /* If some data was xferred, send the number of bytes - * xferred */ - rv = copy_offset; - } else { - /* If not, send the error code */ + if (copy_offset == 0) { + /* If no data is transferred, send the error code */ rv = subrv; } break; } - copy_offset += chunk_len; - pending_data -= chunk_len; + copy_offset += subrv; + pending_data -= subrv; + rv += subrv; } return rv; }