Re: Temporary build
Colin Leroy <[email protected]>
| Newsgroups | gmane.network.everybuddy.user |
|---|---|
| Message-ID | <[email protected]> |
On 09 Apr 2003 at 21h28, Meredydd Luff wrote: Hi, > A temporary tarball (built in the same way as the alpha releases) of > eb-lite is now available at http://www.everybuddy.com/eb-lite/ Attached is a diff of a bugfix in msn. Basically the bug is that read() may return having read less than msglen. From `man 2 read`: ssize_t read(int fd, void *buf, size_t count); read() attempts to read __up__ to count bytes from file That would leave parts of the message to the standard incoming_handler. The fix consists in .unregister sock (so we are sure the handler won't come up in the way) .call read() until we did read msglen bytes (ok 6 times only in order to avoid infinite loop when network is really bad) .register sock again HTH, -- Colin http://www.colino.net/
msn_core.C.diff
(text/plain, 868 B)
--- plugins/msn/msn_core.C.orig Wed Apr 9 23:51:18 2003
+++ plugins/msn/msn_core.C Wed Apr 9 23:52:29 2003
@@ -709,16 +709,35 @@
void msn_handle_MSG(msnconn * conn, char ** args, int numargs)
{
- int msglen;
+ int msglen, remaining;
char * msg;
char * mime;
char * body;
char * tmp;
+ int tries = 0;
msglen=atoi(args[3]);
msg=new char[msglen+1];
- read(conn->sock, msg, msglen);
+ memset(msg,'\0',msglen);
+
+ ext_unregister_sock(conn->sock);
+
+ remaining=msglen;
+ do {
+ char tbuf[1250]="";
+ int i=read(conn->sock, tbuf, remaining);
+ if (errno == EAGAIN || i < remaining) {
+ sleep(1);
+ tries++;
+ }
+ if (i>=0) {
+ remaining -= i;
+ }
+ strncat(msg, tbuf, msglen-strlen(msg));
+ } while (remaining > 0 && tries < 6);
+
+ ext_register_sock(conn->sock, 1, 0);
msg[msglen]='\0';
mime=msg;