From 39c126b51ba23685f8ba761fcd7c8124eef8a1ae Mon Sep 17 00:00:00 2001 From: djcb Date: Wed, 26 Oct 2011 21:59:53 +0300 Subject: [PATCH] * don't send dummy data anymore -- no longer needed --- src/mu-cmd-server.c | 59 +++++++++------------------------------------ 1 file changed, 12 insertions(+), 47 deletions(-) diff --git a/src/mu-cmd-server.c b/src/mu-cmd-server.c index 89403f51..057f7336 100644 --- a/src/mu-cmd-server.c +++ b/src/mu-cmd-server.c @@ -29,6 +29,8 @@ #include #include +#include + #ifdef HAVE_LIBREADLINE #include #include @@ -86,51 +88,28 @@ static void send_expr (const char* frm, ...) G_GNUC_PRINTF(1, 2); static void send_expr (const char* frm, ...) { - char *hdr; + char *expr; va_list ap; - char pfx[16]; - int rv; + char hdr[16]; + size_t exprlen, hdrlen; va_start (ap, frm); - hdr = g_strdup_vprintf (frm, ap); - snprintf (pfx, sizeof(pfx), BOX "%u" BOX, strlen(hdr)); + expr = NULL; + exprlen = g_vasprintf (&expr, frm, ap); + hdrlen = snprintf (hdr, sizeof(hdr), BOX "%u" BOX, exprlen); - rv = write (fileno(stdout), pfx, strlen (pfx)); - if (rv < 0) + if (write (fileno(stdout), hdr, hdrlen) < 0) MU_WRITE_LOG ("error writing output: %s", strerror(errno)); - rv = write (fileno(stdout), hdr, strlen (hdr)); - if (rv < 0) + if (write (fileno(stdout), expr, exprlen) < 0) MU_WRITE_LOG ("error writing output: %s", strerror(errno)); - { - MU_WRITE_LOG ("--\n%s\n--", hdr); - } - - - g_free (hdr); + g_free (expr); va_end (ap); } -/* ugly, ugly... emacs reads/processes the data from the server in - * up-to 4096 byte blobs (see read_process_output in the emacs source - * code), and for longer messages / more headers, it may only start - * processing (showing) the message after more data comes, instead of - * immediately. As a work-around for this, here, we just send some - * 'filler data' as to 'flush the pipe', so to speak. hopefully, one - * day I can come up with a more elegant way to do this...*/ -static void -send_filler_data (unsigned len) -{ - unsigned u; - const char* filler = ";; \n"; - for (u = 0; u != len/8; ++u) - write (fileno(stdout), filler, strlen (filler)); -} - - static MuError server_error (GError **err, MuError merr, const char* frm, ...) G_GNUC_PRINTF(3, 4); @@ -364,9 +343,7 @@ cmd_find (MuStore *store, MuQuery *query, GSList *lst, GError **err) mu_msg_iter_destroy (iter); /* return the number of results found */ - send_expr ("(:found %u)", u); - - send_filler_data (2048); + send_expr ("(:found %u)\n", u); return MU_OK; } @@ -709,18 +686,6 @@ cmd_view (MuStore *store, GSList *args, GError **err) send_expr ("(:view %s)\n", sexp); - - /* ugly, ugly... emacs reads/processes the data from the - * server in up-to 4096 byte blobs (see read_process_output in - * the emacs source code), and for longer messages, it may - * only start processing (showing) the message after more data - * comes, instead of immediately. As a work-around for this, - * here, we just send some 'filler data' as to 'flush the - * pipe', so to speak. hopefully, one day I can come up with a - * more elegant way to do this...*/ - if (strlen (sexp) > 4000) - send_filler_data (256); - g_free (sexp); return MU_OK;