From 055ed940f8cfe9d69c9dad4aaa8372ee4af80aa8 Mon Sep 17 00:00:00 2001 From: Russell Date: Thu, 29 Aug 2013 15:53:46 -0500 Subject: [PATCH 1/2] Added quit() method. --- memcache.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/memcache.py b/memcache.py index db8e632..be7beb1 100644 --- a/memcache.py +++ b/memcache.py @@ -291,6 +291,10 @@ def get_stats(self, stat_args = None): return(data) + def quit(self): + for s in self.servers: + s.quit() + def get_slabs(self): data = [] for s in self.servers: @@ -1215,6 +1219,12 @@ def recv(self, rlen): self.buffer = buf[rlen:] return buf[:rlen] + def quit(self): + if self.socket: + self.send_cmd('quit') + self.socket.recv(1) + self.close_socket() + def flush(self): self.send_cmd('flush_all') self.expect('OK') From 582cfe01c3b634e55a748c9b5ca80a48aac097f4 Mon Sep 17 00:00:00 2001 From: Russell Date: Tue, 3 Sep 2013 17:52:48 -0500 Subject: [PATCH 2/2] Added docstring/comments to _Host.quit(), renamed Client.quit() to Client.quit_all(). --- memcache.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/memcache.py b/memcache.py index be7beb1..d7b1f16 100644 --- a/memcache.py +++ b/memcache.py @@ -291,7 +291,8 @@ def get_stats(self, stat_args = None): return(data) - def quit(self): + def quit_all(self): + '''Send a "quit" command to all servers and wait for the connection to close.''' for s in self.servers: s.quit() @@ -1220,9 +1221,20 @@ def recv(self, rlen): return buf[:rlen] def quit(self): + '''Send a "quit" command to remote server and wait for connection to close.''' if self.socket: + # Using self.send_cmd, so no need for '\r\n'. self.send_cmd('quit') + + # We can't close the local socket until the remote end processes the quit + # command and sends us a FIN packet. When that happens, socket.recv() + # will stop blocking and return an empty string. If we try to close the + # socket before then, the OS will think we're initiating the connection + # close and will put the socket into TIME_WAIT. self.socket.recv(1) + + # At this point, socket should be in CLOSE_WAIT. Closing the socket should + # release the port back to the OS. self.close_socket() def flush(self):