import files that are relative to the source as nepi.full.path
[nepi.git] / src / nepi / resources / ns3 / ns3server.py
index 5f756ae..0149f50 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
@@ -18,7 +17,7 @@
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 
 import base64
-import cPickle
+import pickle
 import errno
 import logging
 import os
@@ -27,7 +26,7 @@ import sys
 
 from optparse import OptionParser, SUPPRESS_HELP
 
-from ns3wrapper import NS3Wrapper
+from nepi.resources.ns3.ns3wrapper import NS3Wrapper
 
 class NS3WrapperMessage:
     CREATE = "CREATE"
@@ -116,7 +115,7 @@ def recv_msg(conn):
     while '\n' not in chunk:
         try:
             chunk = conn.recv(1024)
-        except (OSError, socket.error), e:
+        except (OSError, socket.error) as e:
             if e[0] != errno.EINTR:
                 raise
             # Ignore eintr errors
@@ -137,9 +136,9 @@ def recv_msg(conn):
 
     def decode(item):
         item = base64.b64decode(item).rstrip()
-        return cPickle.loads(item)
+        return pickle.loads(item)
 
-    decoded = map(decode, msg.split("|"))
+    decoded = [ decode(x) for x in msg.split("|") ]
 
     # decoded message
     dmsg_type = decoded.pop(0)
@@ -149,7 +148,7 @@ def recv_msg(conn):
     return (dmsg_type, dargs, dkwargs)
 
 def send_reply(conn, reply):
-    encoded = base64.b64encode(cPickle.dumps(reply))
+    encoded = base64.b64encode(pickle.dumps(reply))
     conn.send("%s\n" % encoded)
 
 def get_options():
@@ -203,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)
-        except socket.timeout, e:
+        except socket.timeout as e:
             # Ingore time-out
             close_socket(conn)
             continue