Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added quit() method. #15

Merged
merged 2 commits into from
Apr 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ def get_stats(self, stat_args = None):

return(data)

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()

def get_slabs(self):
data = []
for s in self.servers:
Expand Down Expand Up @@ -1215,6 +1220,23 @@ def recv(self, rlen):
self.buffer = buf[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):
self.send_cmd('flush_all')
self.expect('OK')
Expand Down