* [B.A.T.M.A.N.] [PATCH] json output from vis server would fail with incomplete writes
@ 2009-07-02 12:13 jonathan mzengeza
2009-07-02 23:32 ` Marek Lindner
0 siblings, 1 reply; 2+ messages in thread
From: jonathan mzengeza @ 2009-07-02 12:13 UTC (permalink / raw)
To: b.a.t.m.a.n
[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]
Hi
Jonathan here I am attending a code sprint here at CSIR in South Africa.
We are using B.A.T.M.A.N as a mesh networking software. We ran into a bug
which occurred with web browser whereby the data written back through the
socket was not complete thereby causing an error with our program.
The fix works by making sure that all the data that is to be sent in the
send_buffer is sent. It checks the value of ret until it equals the size of
the data to be sent.
--
Index: vis.c
===================================================================
--- vis.c (revision 1336)
+++ vis.c (working copy)
@@ -580,8 +580,18 @@
} else {
send_buffer = current->json_buffer;
}
+
+ ret = write( thread_data->socket, send_buffer, strlen(
send_buffer ));
- ret = write( thread_data->socket, send_buffer, strlen(
send_buffer ) );
+ while(ret != strlen( send_buffer )) {
+ send_buffer += ret;
+
+ if ( fsync(thread_data->socket) != 0 ) {
+ ret = write(thread_data->socket, send_buffer, strlen(
send_buffer ));
+ }
+
+ }
+
if( ret != strlen( send_buffer ) || (thread_data->format ==
json) )
{
pthread_mutex_lock( ¤t->mutex );
[-- Attachment #2: Type: text/html, Size: 1520 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] json output from vis server would fail with incomplete writes
2009-07-02 12:13 [B.A.T.M.A.N.] [PATCH] json output from vis server would fail with incomplete writes jonathan mzengeza
@ 2009-07-02 23:32 ` Marek Lindner
0 siblings, 0 replies; 2+ messages in thread
From: Marek Lindner @ 2009-07-02 23:32 UTC (permalink / raw)
To: The list for a Better Approach To Mobile Ad-hoc Networking
Hi,
> We are using B.A.T.M.A.N as a mesh networking software. We ran into a bug
> which occurred with web browser whereby the data written back through the
> socket was not complete thereby causing an error with our program.
>
> The fix works by making sure that all the data that is to be sent in the
> send_buffer is sent. It checks the value of ret until it equals the size of
> the data to be sent.
thanks for your patch. This spot you found really is not that beautiful. ;-)
Looking at your patch I ask myself what will happen if the other end dies in
the process ? You are in a loop that constantly checks if all data has been
transmitted and retries to send without checking for timeout errors or
connection problems. I have the feeling it could lead to an endless loop. I
might be wrong - what do you think ?
Also, I never used fsync on a socket. It is doing the same thing as on a file ?
What about using the SIOCOUTQ ioctl (which is linux specific and not
portable) ?
Regards,
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-07-02 23:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-02 12:13 [B.A.T.M.A.N.] [PATCH] json output from vis server would fail with incomplete writes jonathan mzengeza
2009-07-02 23:32 ` Marek Lindner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox