From patchwork Tue Nov 11 10:51:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 418560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E6F381400D2 for ; Mon, 8 Dec 2014 13:52:38 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id DB46428C184; Mon, 8 Dec 2014 03:49:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, DATE_IN_PAST_96_XX, FREEMAIL_FROM,T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id C528C28C177 for ; Mon, 8 Dec 2014 03:49:28 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 8 Dec 2014 03:49:28 +0100 (CET) Received: by mail-pa0-f43.google.com with SMTP id kx10so4303148pab.16 for ; Sun, 07 Dec 2014 18:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aShDoU/2JczwvWuFyhViMTVW8deCB8BYCSfGyLqsVPQ=; b=eVLZMaVoZRwkwjsGQyL8F94TMouh/kBJ+YpLuz4KyBsZmafbwbu0kZArIb/xIau46u Ht6Tojxa9rA34Nf3SOfAmhn4s/iS1C8vVYWZKU0JAh2keHXlWdPZT+/zzJnHmIi6acaW FLcJJCQZGhcg15g1uoDolWjV9lGohLUY+EH8lMA62LhzmGTktrrn3KMZEOi+7hugI1SO pyKIUfHiN61PepDLSiDablofAKXoOzPwxGvGEnVI4d+fo6pp7fCtoujHC5KpELyqTS/h jaF5bU+09QnczPcV407oVxx/1u0uQn3+ClYxJs/xK+6iRXbQTLRrzehOP7V+Nin3Cjpt kBAQ== X-Received: by 10.70.96.162 with SMTP id dt2mr16624449pdb.57.1418007069598; Sun, 07 Dec 2014 18:51:09 -0800 (PST) Received: from debian.lan ([103.29.140.56]) by mx.google.com with ESMTPSA id fn5sm34940623pdb.55.2014.12.07.18.51.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Dec 2014 18:51:08 -0800 (PST) From: Yousong Zhou To: openwrt-devel@lists.openwrt.org Date: Tue, 11 Nov 2014 18:51:32 +0800 Message-Id: <1415703092-46458-5-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1415703092-46458-1-git-send-email-yszhou4tech@gmail.com> References: <1415703092-46458-1-git-send-email-yszhou4tech@gmail.com> Subject: [OpenWrt-Devel] [PATCH 5/5] ustream: call notify_write() when bytes are written. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Yousong Zhou --- ustream.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ustream.c b/ustream.c index 64cdc6a..1d0c38e 100644 --- a/ustream.c +++ b/ustream.c @@ -364,6 +364,17 @@ static void ustream_write_error(struct ustream *s) s->write_error = true; } +static int ustream_call_write_cb(struct ustream *s, const char *data, int len, bool more) +{ + int bytes; + + bytes = s->write(s, data, len, more); + if (s->notify_write && bytes > 0) + s->notify_write(s, bytes); + + return bytes; +} + bool ustream_write_pending(struct ustream *s) { struct ustream_buf *buf = s->w.head; @@ -376,7 +387,7 @@ bool ustream_write_pending(struct ustream *s) struct ustream_buf *next = buf->next; int maxlen = buf->tail - buf->data; - len = s->write(s, buf->data, maxlen, !!buf->next); + len = ustream_call_write_cb(s, buf->data, maxlen, !!buf->next); if (len < 0) { ustream_write_error(s); break; @@ -396,9 +407,6 @@ bool ustream_write_pending(struct ustream *s) buf = next; } - if (s->notify_write) - s->notify_write(s, wr); - if (s->eof && wr && !s->w.data_bytes) ustream_state_change(s); @@ -441,7 +449,7 @@ int ustream_write(struct ustream *s, const char *data, int len, bool more) return 0; if (!l->data_bytes) { - wr = s->write(s, data, len, more); + wr = ustream_call_write_cb(s, data, len, more); if (wr == len) return wr; @@ -475,7 +483,7 @@ int ustream_vprintf(struct ustream *s, const char *format, va_list arg) maxlen = vsnprintf(buf, MAX_STACK_BUFLEN, format, arg2); va_end(arg2); if (maxlen < MAX_STACK_BUFLEN) { - wr = s->write(s, buf, maxlen, false); + wr = ustream_call_write_cb(s, buf, maxlen, false); if (wr < 0) { ustream_write_error(s); return wr;