Re: [PATCH v2 05/20] insert: copy stdin to Maildir tmp file
authorTomi Ollila <tomi.ollila@iki.fi>
Mon, 26 Nov 2012 09:39:41 +0000 (11:39 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:01 +0000 (09:51 -0800)
10/170c39b9c0dc2fff2e414db447ec6956360d10 [new file with mode: 0644]

diff --git a/10/170c39b9c0dc2fff2e414db447ec6956360d10 b/10/170c39b9c0dc2fff2e414db447ec6956360d10
new file mode 100644 (file)
index 0000000..7ad3a2b
--- /dev/null
@@ -0,0 +1,131 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E596D431FAF\r
+       for <notmuch@notmuchmail.org>; Mon, 26 Nov 2012 01:39:46 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id U3xKyyiXwLgQ for <notmuch@notmuchmail.org>;\r
+       Mon, 26 Nov 2012 01:39:46 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id E08D9431FAE\r
+       for <notmuch@notmuchmail.org>; Mon, 26 Nov 2012 01:39:45 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id 353071000E5;\r
+       Mon, 26 Nov 2012 11:39:42 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 05/20] insert: copy stdin to Maildir tmp file\r
+In-Reply-To: <1353806206-29133-6-git-send-email-novalazy@gmail.com>\r
+References: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\r
+       <1353806206-29133-6-git-send-email-novalazy@gmail.com>\r
+User-Agent: Notmuch/0.14+84~g8a199bf (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 26 Nov 2012 11:39:41 +0200\r
+Message-ID: <m2txscitya.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 26 Nov 2012 09:39:47 -0000\r
+\r
+On Sun, Nov 25 2012, Peter Wang <novalazy@gmail.com> wrote:\r
+\r
+> Read the new message from standard input into the Maildir tmp file.\r
+> ---\r
+\r
+There are a few issues that gort my attention in this particular function:\r
+\r
+\r
+>  notmuch-insert.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++----\r
+>  1 file changed, 47 insertions(+), 4 deletions(-)\r
+>\r
+> diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+> index 371fb47..88e8533 100644\r
+> --- a/notmuch-insert.c\r
+> +++ b/notmuch-insert.c\r
+> @@ -94,6 +94,47 @@ maildir_open_tmp_file (void *ctx, const char *dir,\r
+>      return fd;\r
+>  }\r
+>  \r
+> +/* Copy the contents of fdin into fdout. */\r
+> +static notmuch_bool_t\r
+> +copy_fd_data (int fdin, int fdout)\r
+> +{\r
+> +    char buf[4096];\r
+\r
+Copying in 4k blocks is slow when at least when doing file to file copy.\r
+Also socket buffers can often hold much more data. When reading from\r
+network and saving to file (in low-load machine) this is OK, but otherwise\r
+something like 64k buffer works better(*).\r
+\r
+(*) Now that I said it I have to measure this yet another time ;)\r
+\r
+> +    char *p;\r
+> +    ssize_t remain;\r
+> +    ssize_t written;\r
+> +\r
+> +    for (;;) {\r
+> +    remain = read (fdin, buf, sizeof(buf));\r
+\r
+space between sizeof and (buf)\r
+\r
+> +    if (remain == 0)\r
+> +        break;\r
+> +    if (remain < 0) {\r
+> +        if (errno == EINTR)\r
+> +            continue;\r
+> +        fprintf (stderr, "Error: reading from standard input: %s\n",\r
+> +                 strerror (errno));\r
+> +        return FALSE;\r
+> +    }\r
+\r
+You're claiming in function name & and its description that this is more\r
+"generic" copy function -- yet error message speaks about 'standard input'.\r
+\r
+> +\r
+> +    p = buf;\r
+> +    do {\r
+> +        written = write (fdout, p, remain);\r
+> +        if (written == 0)\r
+> +            return FALSE;\r
+> +        if (written < 0) {\r
+> +            if (errno == EINTR)\r
+> +                continue;\r
+> +            fprintf (stderr, "Error: writing to temporary file: %s",\r
+> +                     strerror (errno));\r
+> +            return FALSE;\r
+> +        }\r
+\r
+Ditto.\r
+\r
+> +        p += written;\r
+> +        remain -= written;\r
+> +    } while (remain > 0);\r
+> +    }\r
+> +\r
+> +    return TRUE;\r
+> +}\r
+> +\r
+\r
+Tomi\r