applied the except and raise fixers to the master branch to close the gap with py3
[nepi.git] / src / nepi / resources / ns3 / ns3server.py
index 076f26a..8b3cd79 100644 (file)
@@ -3,9 +3,8 @@
 #    Copyright (C) 2014 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -109,18 +108,14 @@ def close_socket(sock):
     except:
         pass
 
-def recv_msg(conn, ns3_wrapper):
+def recv_msg(conn):
     msg = []
     chunk = ''
 
     while '\n' not in chunk:
         try:
             chunk = conn.recv(1024)
-        except (OSError, socket.error), e:
-            import traceback
-            err = traceback.format_exc()
-            ns3_wrapper.logger.error(err) 
-
+        except (OSError, socket.error) as e:
             if e[0] != errno.EINTR:
                 raise
             # Ignore eintr errors
@@ -207,11 +202,11 @@ def run_server(socket_name, level = logging.INFO, ns_log = None,
 
     while not stop:
         conn, addr = sock.accept()
-        conn.settimeout(5)
+        conn.settimeout(30)
 
         try:
-            (msg_type, args, kwargs) = recv_msg(conn, ns3_wrapper)
-        except socket.timeout, e:
+            (msg_type, args, kwargs) = recv_msg(conn)
+        except socket.timeout as e:
             # Ingore time-out
             close_socket(conn)
             continue