diff options
author | Eric Lambert <eric.d.lambert@gmail.com> | 2009-03-21 02:21:17 -0700 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-03-21 02:21:17 -0700 |
commit | 9ce2e0ac5638064cb1d268292b08256e33643a19 (patch) | |
tree | eb79b0f96f4d92585d39bce8c785ddb9df773df0 | |
parent | 41e1b0c47dcaf573e717419f76bac60e48913a59 (diff) | |
download | memcached-9ce2e0ac5638064cb1d268292b08256e33643a19.tar.gz |
Fix ascii UDP set (bug36).
http://code.google.com/p/memcached/issues/detail?id=36
-rw-r--r-- | memcached.c | 6 | ||||
-rwxr-xr-x | t/udp.t | 27 |
2 files changed, 24 insertions, 9 deletions
diff --git a/memcached.c b/memcached.c index 28fb033..654a93e 100644 --- a/memcached.c +++ b/memcached.c @@ -1868,9 +1868,11 @@ static void reset_cmd_handler(conn *c) { static void complete_nread(conn *c) { assert(c != NULL); - assert(c->protocol == ascii_prot || c->protocol == binary_prot); + assert(c->protocol == ascii_udp_prot + || c->protocol == ascii_prot + || c->protocol == binary_prot); - if (c->protocol == ascii_prot) { + if (c->protocol == ascii_prot || c->protocol == ascii_udp_prot) { complete_nread_ascii(c); } else if (c->protocol == binary_prot) { complete_nread_binary(c); @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 33; +use Test::More tests => 48; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -17,8 +17,18 @@ mem_get_is($sock, "foo", "fooval"); my $usock = $server->new_udp_sock or die "Can't bind : $@\n"; -# test all the steps, one by one: -test_single($usock); +# test all the get steps, one by one: +test_single_op($usock,"get foo\r\n","VALUE foo 0 6\r\nfooval\r\nEND\r\n"); + +# test all the set steps, one by one: +test_single_op($usock,"set aval 0 0 1\r\n1\r\n","STORED\r\n"); + +# test all the incr steps, one by one: +test_single_op($usock,"incr aval 1\r\n","2\r\n"); + +# test all the delete steps, one by one: +test_single_op($usock,"delete aval\r\n","DELETED\r\n"); + # testing sequence numbers for my $offt (1, 1, 2) { @@ -53,10 +63,12 @@ is(substr($res->{0}, 8), "END\r\n"); is(hexify(substr($res->{1}, 0, 2)), hexify(pack("n", 999)), "sequence number of middle packet is correct"); } -sub test_single { +sub test_single_op { my $usock = shift; + my $op = shift; + my $resp = shift; my $req = pack("nnnn", 45, 0, 1, 0); # request id (opaque), seq num, #packets, reserved (must be 0) - $req .= "get foo\r\n"; + $req .= $op; ok(defined send($usock, $req, 0), "sent request"); my $rin = ''; @@ -69,9 +81,10 @@ sub test_single { $sender = $usock->recv($res, 1500, 0); my $id = pack("n", 45); + my $expctdlen = length($resp) + 8; is(hexify(substr($res, 0, 8)), hexify($id) . '0000' . '0001' . '0000', "header is correct"); - is(length $res, 36, ''); - is(substr($res, 8), "VALUE foo 0 6\r\nfooval\r\nEND\r\n", "payload is as expected"); + is(length $res,$expctdlen,''); + is(substr($res, 8), $resp, "response is correct"); } sub hexify { |