Message ID | 1739bfe0907020513m78e06c83s980ce88b5cb5cca5@mail.gmail.com |
---|---|
State | Superseded, archived |
Headers | show |
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
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 )); + } + + } +