<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -224,6 +224,32 @@ AC_CHECK_FUNCS(mlockall)
 AC_CHECK_FUNCS(getpagesizes)
 AC_CHECK_FUNCS(memcntl)
 
+AC_DEFUN([AC_C_ALIGNMENT],
+[AC_CACHE_CHECK(for alignment, ac_cv_c_alignment,
+[
+  AC_RUN_IFELSE(
+    [AC_LANG_PROGRAM([
+#include &lt;stdlib.h&gt;
+#include &lt;inttypes.h&gt;
+    ], [
+       char *buf = malloc(32);
+       uint64_t *ptr = (uint64_t*)(buf+2);
+       *ptr = 0x1;
+       return 0;
+    ])
+  ],[
+    ac_cv_c_alignment=none
+  ],[
+    ac_cv_c_endian=need
+  ])
+])
+if test $ac_cv_c_endian = need; then
+  AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment])
+fi
+])
+
+AC_C_ALIGNMENT
+
 dnl Let the compiler be a bit more picky. Please note that you cannot
 dnl specify these flags to the compiler before AC_CHECK_FUNCS, because
 dnl the test program will generate a compilation warning and hence fail</diff>
      <filename>configure.ac</filename>
    </modified>
    <modified>
      <diff>@@ -881,6 +881,8 @@ static void* binary_get_request(conn *c) {
     char *ret = c-&gt;rcurr;
     ret -= (sizeof(c-&gt;binary_header) + c-&gt;binary_header.request.keylen +
             c-&gt;binary_header.request.extlen);
+
+    assert(ret &gt;= c-&gt;rbuf);
     return ret;
 }
 
@@ -2848,6 +2850,16 @@ static int try_read_command(conn *c) {
             /* need more data! */
             return 0;
         } else {
+#ifdef NEED_ALIGN
+            if (((long)(c-&gt;rcurr)) % 8 != 0) {
+                /* must realign input buffer */
+                memmove(c-&gt;rbuf, c-&gt;rcurr, c-&gt;rbytes);
+                c-&gt;rcurr = c-&gt;rbuf;
+                if (settings.verbose) {
+                    fprintf(stderr, &quot;%d: Realign input buffer\n&quot;, c-&gt;sfd);
+                }
+            }
+#endif
             protocol_binary_request_header* req;
             req = (protocol_binary_request_header*)c-&gt;rcurr;
 
@@ -3247,6 +3259,9 @@ static void drive_machine(conn *c) {
                 STATS_LOCK();
                 stats.bytes_read += res;
                 STATS_UNLOCK();
+                if (c-&gt;rcurr == c-&gt;ritem) {
+                    c-&gt;rcurr += res;
+                }
                 c-&gt;ritem += res;
                 c-&gt;rlbytes -= res;
                 break;</diff>
      <filename>memcached.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d9d315f6dddda9099998da7119b723206a13001b</id>
    </parent>
  </parents>
  <author>
    <name>Trond Norbye</name>
    <email>Trond.Norbye@sun.com</email>
  </author>
  <url>http://github.com/trondn/memcached/commit/4c3797b1d4fe9088ef96c9f7d571b1221cb40fef</url>
  <id>4c3797b1d4fe9088ef96c9f7d571b1221cb40fef</id>
  <committed-date>2008-12-04T02:52:45-08:00</committed-date>
  <authored-date>2008-12-04T02:52:45-08:00</authored-date>
  <message>Realign command input buffer (binary protocol)</message>
  <tree>1a116c74cc7ac5d20036112d513b435f4c3d053e</tree>
  <committer>
    <name>Trond Norbye</name>
    <email>Trond.Norbye@sun.com</email>
  </committer>
</commit>
