mg_write is much slower than mg_send_header + mg_printf_data

135 views
Skip to first unread message

Dennis Mikhailitsky

unread,
Jun 18, 2015, 7:38:17 PM6/18/15
to mongoos...@googlegroups.com
Hi. I'm using Mongoose 5.4 and I noticed that when called from a user defined handler, the following function produces its output with a 30 seconds delay:

mg_write (conn, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n<some_data>", strlen ("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n<some_data>"));

while the following combination, producing the same output, does its job immediately:

mg_send_header (conn, "Content-Type", "text/plain");
mg_printf_data (conn, "%s", "<some_data>");

What is the cause of the huge delay when using the mg_write function?

Thanks.

Dennis Mikhailitsky

unread,
Jun 18, 2015, 7:52:34 PM6/18/15
to mongoos...@googlegroups.com
Looks likes adding a Content-Length field to the header in the mg_write call fixes the problem.

Sergey Lyubka

unread,
Jun 19, 2015, 4:42:48 AM6/19/15
to mongoose-users
mg_printf_data() uses chunked encoding, which sends content length to the client automatically.
mg_printf() doesn't do that, it sends data as-is. If you don't send content length, client assumes that the content ends when TCP connection is closed, and waits for the continuation until timeout.

On Fri, Jun 19, 2015 at 12:52 AM, Dennis Mikhailitsky <mikhai...@gmail.com> wrote:
Looks likes adding a Content-Length field to the header in the mg_write call fixes the problem.

--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages