From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0220.ocn.ad.jp (mogw0220.ocn.ad.jp [114.147.58.26]) by dpdk.org (Postfix) with ESMTP id 180531C6AF for ; Tue, 15 May 2018 03:20:15 +0200 (CEST) Received: from mf-smf-ucb033c2 (mf-smf-ucb033c2.ocn.ad.jp [153.153.66.225]) by mogw0220.ocn.ad.jp (Postfix) with ESMTP id 9F0121A0216; Tue, 15 May 2018 10:20:13 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb029 ([153.149.230.163]) by mf-smf-ucb033c2 with ESMTP id IOdBfqUMDSNiFIOdRfWN4W; Tue, 15 May 2018 10:20:13 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.135]) by ntt.pod01.mv-mta-ucb029 with id mRLD1x0092vuoep01RLDnn; Tue, 15 May 2018 01:20:13 +0000 Received: from localhost.localdomain (p5164-ipngn8501marunouchi.tokyo.ocn.ne.jp [153.214.228.164]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Tue, 15 May 2018 10:20:13 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Tue, 15 May 2018 10:20:03 +0900 Message-Id: <20180515012004.8726-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515012004.8726-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180515012004.8726-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 2/3] controller: fix encoding for socket X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 May 2018 01:20:15 -0000 From: Yasufumi Ogawa For python3, it is required to treat str and bytes explicitly for sending and receiving messages via socket. SPP controller has several socket interfaces between primary and secondary processes. It means that messages must be encoded before sending or decoded after receiving vise versa. Signed-off-by: Yasufumi Ogawa --- src/controller/conn_thread.py | 11 ++++++----- src/controller/shell.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py index 8b2f8cd..2ec4e2a 100644 --- a/src/controller/conn_thread.py +++ b/src/controller/conn_thread.py @@ -56,7 +56,7 @@ class ConnectionThread(threading.Thread): # 1024 stands for bytes of data to be received data = self.conn.recv(1024) if data: - msg = "%s" % data + msg = "%s" % data.decode('utf-8') spp_common.SEC2MAIN[self.client_id].put(msg) else: spp_common.SEC2MAIN[self.client_id].put( @@ -96,7 +96,7 @@ class AcceptThread(threading.Thread): """Get client_id from client""" try: - conn.send("_get_client_id") + conn.send(b'_get_client_id') except KeyError: return -1 @@ -106,7 +106,7 @@ class AcceptThread(threading.Thread): if logger is not None: logger.debug("data: %s" % data) - client_id = int(data.strip('\0')) + client_id = int(data.decode('utf-8').strip('\0')) if client_id < 0 or client_id > spp_common.MAX_SECONDARY: logger.debug("Failed to get client_id: %d" % client_id) @@ -139,7 +139,8 @@ class AcceptThread(threading.Thread): if free_client_id < 0: return -1 - conn.send("_set_client_id %u" % free_client_id) + msg = "_set_client_id %u" % free_client_id + conn.send(msg.encode('utf-8')) data = conn.recv(1024) return free_client_id @@ -240,7 +241,7 @@ class PrimaryThread(threading.Thread): data = conn.recv(1024) if data: spp_common.PRIMARY2MAIN.put( - "recv:%s:{%s}" % (str(addr), data)) + "recv:%s:{%s}" % (str(addr), data.decode('utf-8'))) else: spp_common.PRIMARY2MAIN.put("closing:" + str(addr)) conn.close() diff --git a/src/controller/shell.py b/src/controller/shell.py index b04cc62..137c42b 100644 --- a/src/controller/shell.py +++ b/src/controller/shell.py @@ -143,7 +143,7 @@ class Shell(cmd.Cmd, object): """Send command to primary process""" if spp_common.PRIMARY: - spp_common.MAIN2PRIMARY.put(command) + spp_common.MAIN2PRIMARY.put(command.encode('utf-8')) recv = spp_common.PRIMARY2MAIN.get(True) print(recv) return self.CMD_OK, recv @@ -156,7 +156,7 @@ class Shell(cmd.Cmd, object): """Send command to secondary process with sec_id""" if sec_id in spp_common.SECONDARY_LIST: - spp_common.MAIN2SEC[sec_id].put(command) + spp_common.MAIN2SEC[sec_id].put(command.encode('utf-8')) recv = spp_common.SEC2MAIN[sec_id].get(True) if command == 'status': self.print_sec_status(recv) @@ -234,7 +234,7 @@ class Shell(cmd.Cmd, object): if (rcmd == spp_common.REMOTE_COMMAND): param = result + '\n' + message - spp_common.RCMD_RESULT_QUEUE.put(param) + spp_common.RCMD_RESULT_QUEUE.put(param.encode('utf-8')) else: if logger is not None: logger.debug("unknown remote command = %s" % rcmd) -- 2.17.0