udp bugfix

Iain Wade iwade at optusnet.com.au
Sat Nov 11 17:40:58 UTC 2006


I note that the current UDP support is broken for anything other than GET.

This is due to GET calling add_iov direct (and refcnt'ing the object)
whereas a lot of other bit use out_string (which accumulates in a
per-connection buffer).

The current code only adds that buffer to the iovec if the iovec is
empty, which is never the case for udp because of the reserved header
entry.

Result: Failed to write, and not due to blocking: Bad address

The fix is below.

Thanks for making a fantastic piece of software Brad (and others).

Regards,
--Iain

--- memcached.c.orig    2006-09-10 03:10:21.000000000 +1000
+++ memcached.c.udp_fix 2006-11-12 04:32:33.000000000 +1100
@@ -1551,13 +1551,13 @@
         case conn_write:
             /*
              * We want to write out a simple response. If we haven't already,
              * assemble it into a msgbuf list (this will be a single-entry
              * list for TCP or a two-entry list for UDP).
              */
-            if (c->iovused == 0) {
+            if (c->iovused == 0 || (c->udp && c->iovused == 1)) {
                 if (add_iov(c, c->wcurr, c->wbytes) ||
                         c->udp && build_udp_headers(c)) {
                     if (settings.verbose > 0)
                         fprintf(stderr, "Couldn't build response\n");
                     conn_set_state(c, conn_closing);
                     break;


More information about the memcached mailing list