[vis] fixed partial json output

Message ID 1739bfe0907150726l70ee35b1wa92f4fb1aabfdd61@mail.gmail.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

jonathan mzengeza July 15, 2009, 2:26 p.m. UTC
  2009/7/15 Sven Eckelmann <sven.eckelmann@gmx.de>:
>> Partial output was caused by failing to read the HTTP request. This
>> patch reads the HTTP request into a temporary buffer before discarding
>> it.
> This patch creates an endless loop on unrecoverable socket errors. See read(3)
> for more information about return codes. Please provide more information if I
> am wrong.
>
> Best regards,
>        Sven

Thanks, is this better?


Signed-off-by: Jonathan Mzengeza <jtmze87@gmail.com>
  

Comments

Sven Eckelmann July 15, 2009, 6:50 p.m. UTC | #1
> Thanks, is this better?
There are different things I don't understand complete. How does the receive 
buffer affect the output buffer in this case?
Isn't it possible to disable non-blocking sockets in vis.c:635-638 and change 
the read to following for json: Try to recv data until the read fails or an 
empty line (please check HTTP rfc before implementing) appears. If the read 
fails -> discard everything. If the empty line appeared then send the data.
You should create an extra function to read (and discard) the header stuff.

My personal opinion about the errno and delay stuff is... I don't like it. It 
seems to be somewhat correct to ask again on EAGAIN corresponding to the man 
page, but we could do it in a cleaner way if possible.

Maybe someone sees a problem in my proposal. The only thing I see is that the 
read should appear before locking the current buffer or a "bad person" (me) 
could delay the new buffers for all others by connecting and then wait for a 
long time. I see the same problem in your current implementation.

Regards,
	Sven
  

Patch

Index: vis.c
===================================================================
--- vis.c	(revision 1343)
+++ vis.c	(working copy)
@@ -566,6 +566,7 @@ 
 	buffer_t *last_send = NULL;
 	size_t ret;
 	char* send_buffer = NULL;
+  char tmp[512];

 	while ( !is_aborted() ) {

@@ -579,6 +580,11 @@ 
 				send_buffer = current->dot_buffer;
 			} else {
 				send_buffer = current->json_buffer;
+				ret = read( thread_data->socket, tmp, sizeof( tmp ));
+				while ( ret == -1 && errno == EAGAIN) {
+				  ret = read( thread_data->socket, tmp, sizeof( tmp ));
+				  usleep(250);
+				}
 			}

 			ret = write( thread_data->socket, send_buffer, strlen( send_buffer ) );