From: JINMEI Tatuya Date: Tue, 5 Jun 2012 01:16:09 +0000 (-0700) Subject: [1513] refactoring: extract socket send operation into a separate method. X-Git-Tag: trac2351_base~226^2~59^2~7^2~1^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=93d4730a6135e573efdcd4fe0780119e5d343093;p=thirdparty%2Fkea.git [1513] refactoring: extract socket send operation into a separate method. this will make the planned implementation for this ticket simpler, and will also help further unrelated extensions such as TCP support. --- diff --git a/src/bin/ddns/ddns.py.in b/src/bin/ddns/ddns.py.in index 63429404f5..4901c16d4a 100755 --- a/src/bin/ddns/ddns.py.in +++ b/src/bin/ddns/ddns.py.in @@ -371,11 +371,32 @@ class DDNSServer: msg.to_wire(self.__response_renderer, tsig_ctx) else: msg.to_wire(self.__response_renderer) + + return self.__send_response(sock, self.__response_renderer.get_data(), + remote_addr) + + def __send_response(self, sock, data, dest): + '''Send DDNS response to the client. + + Right now, this is a straightforward subroutine of handle_request(), + but is intended to be extended evetually so that it can handle more + comlicated operations for TCP (which requires asynchronous write). + Further, when we support multiple requests over a single TCP + connection, this method may even be shared by multiple methods. + + Parameters: + sock: (python socket) the socket to which the response should be sent. + data: (binary) the response data + dest: (python socket address) the destion address to which the response + should be sent. + + Return: True if the send operation succeds; otherwise False. + + ''' try: - sock.sendto(self.__response_renderer.get_data(), remote_addr) + sock.sendto(data, dest) except socket.error as ex: - logger.error(DDNS_RESPONSE_SOCKET_ERROR, - ClientFormatter(remote_addr), ex) + logger.error(DDNS_RESPONSE_SOCKET_ERROR, ClientFormatter(dest), ex) return False return True