From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0106.ocn.ad.jp (mogw0106.ocn.ad.jp [118.23.109.80]) by dpdk.org (Postfix) with ESMTP id 7D5DC2BD8 for ; Wed, 23 May 2018 22:12:09 +0200 (CEST) Received: from mf-smf-ucb020c3 (mf-smf-ucb020c3.ocn.ad.jp [153.153.66.135]) by mogw0106.ocn.ad.jp (Postfix) with ESMTP id 25FFF7C278; Thu, 24 May 2018 05:12:08 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb027 ([153.149.142.101]) by mf-smf-ucb020c3 with ESMTP id La6lfsuks0tw2La7EfXQWu; Thu, 24 May 2018 05:12:08 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.166]) by ntt.pod01.mv-mta-ucb027 with id pwC81x0013c2f7501wC8nJ; Wed, 23 May 2018 20:12:08 +0000 Received: from localhost.localdomain (p5164-ipngn8501marunouchi.tokyo.ocn.ne.jp [153.214.228.164]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Thu, 24 May 2018 05:12:07 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com Cc: spp@dpdk.org, Yasufumi Ogawa Date: Thu, 24 May 2018 05:11:49 +0900 Message-Id: <20180523201150.23042-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523201150.23042-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180515012004.8726-1-ogawa.yasufumi@lab.ntt.co.jp> <20180523201150.23042-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH v2 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: Wed, 23 May 2018 20:12:10 -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 bffdcee..e524e84 100644 --- a/src/controller/conn_thread.py +++ b/src/controller/conn_thread.py @@ -55,7 +55,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( @@ -95,7 +95,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 @@ -105,7 +105,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) @@ -138,7 +138,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 @@ -239,7 +240,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 6bd9cb0..dc6eb34 100644 --- a/src/controller/shell.py +++ b/src/controller/shell.py @@ -142,7 +142,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 @@ -155,7 +155,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) @@ -233,7 +233,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