From 27b253d06e42e5a79ce00508d8bdade6f53724d4 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Fri, 16 Dec 2016 15:17:41 +0900 Subject: BGPSpeaker/net_ctrl: Move _send_*_response() function This patch moves _send_*_response() function into RpcSession class to use socket wrapper methods for maintaining the connection state safely. Signed-off-by: IWASE Yusuke Signed-off-by: FUJITA Tomonori --- ryu/services/protocols/bgp/net_ctrl.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/ryu/services/protocols/bgp/net_ctrl.py b/ryu/services/protocols/bgp/net_ctrl.py index 342e2efe..400032c8 100644 --- a/ryu/services/protocols/bgp/net_ctrl.py +++ b/ryu/services/protocols/bgp/net_ctrl.py @@ -156,6 +156,16 @@ class RpcSession(Activity): for msg in self._unpacker: return msg + def _send_error_response(self, request, err_msg): + rpc_msg = self.create_error_response(request[RPC_IDX_MSG_ID], + str(err_msg)) + return self._sendall(rpc_msg) + + def _send_success_response(self, request, result): + rpc_msg = self.create_success_response(request[RPC_IDX_MSG_ID], + result) + return self._sendall(rpc_msg) + def send_notification(self, method, params): rpc_msg = self.create_notification(method, params) return self._sendall(rpc_msg) @@ -177,10 +187,9 @@ class RpcSession(Activity): if msg[0] == RPC_MSG_REQUEST: try: result = _handle_request(msg) - _send_success_response(self, self._socket, msg, result) + self._send_success_response(msg, result) except BGPSException as e: - _send_error_response(self, self._socket, msg, - e.message) + self._send_error_response(msg, e.message) elif msg[0] == RPC_MSG_RESPONSE: _handle_response(msg) elif msg[0] == RPC_MSG_NOTIFY: @@ -384,17 +393,5 @@ def _handle_request(request): raise ApiException(desc='Invalid type for RPC parameter.') -def _send_success_response(rpc_session, sock, request, result): - response = rpc_session.create_success_response(request[RPC_IDX_MSG_ID], - result) - sock.sendall(response) - - -def _send_error_response(rpc_session, sock, request, emsg): - response = rpc_session.create_error_response(request[RPC_IDX_MSG_ID], - str(emsg)) - sock.sendall(response) - - # Network controller singleton NET_CONTROLLER = _NetworkController() -- cgit v1.2.3