Revision: 14338 Author: adrian.chadd Date: Mon Oct 19 21:56:41 2009 Log: * populate the packet buffer * round the cmd/len section to 32 bits, so alignment issues are less likely to creep up
http://code.google.com/p/lusca-cache/source/detail?r=14338 Modified: /branches/LUSCA_HEAD/libloghelper/loghelper.c /branches/LUSCA_HEAD/libloghelper/writelog-daemon.c ======================================= --- /branches/LUSCA_HEAD/libloghelper/loghelper.c Mon Oct 19 21:29:45 2009 +++ /branches/LUSCA_HEAD/libloghelper/loghelper.c Mon Oct 19 21:56:41 2009 @@ -3,6 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> @@ -263,12 +264,17 @@ /* Create a new buffer */ lb = loghelper_buffer_create(); - /* Copy in the command */ + lb->buf[0] = 0; + lb->buf[1] = u_cmd; /* Copy in the packet length */ + lb->buf[1] = (u_len & 0xff00) >> 8; /* encode high byte */ + lb->buf[2] = (u_len & 0xff); /* .. and low byte, giving us network byte order */ /* Copy in the payload, if any */ + if (payload_len > 0) + memcpy(lb->buf + 4, payload, payload_len); /* Add it to the instance buffer list tail */ loghelper_append_buffer(lh, lb); ======================================= --- /branches/LUSCA_HEAD/libloghelper/writelog-daemon.c Sun Oct 18 22:34:29 2009 +++ /branches/LUSCA_HEAD/libloghelper/writelog-daemon.c Mon Oct 19 21:56:41 2009 @@ -114,14 +114,15 @@ inbuf_read(); /* Do we have enough for the header? */ - if (have_header == 0 && inbuf_curused() < 3) { + if (have_header == 0 && inbuf_curused() < 4) { continue; /* need more data */ } /* If we don't have the header, snaffle it from the front */ if (have_header == 0) { - c_cmd = inbuf.buf[0]; /* command, byte */ - c_len = inbuf.buf[1] * 256 + inbuf.buf[2]; /* length of entire packet, word, network byte order */ + /* first byte is 0 for now */ + c_cmd = inbuf.buf[1]; /* command, byte */ + c_len = inbuf.buf[2] * 256 + inbuf.buf[3]; /* length of entire packet, word, network byte order */ have_header = 1; } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "lusca-commit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/lusca-commit?hl=en -~----------~----~----~----~------~----~------~--~---
