diff mbox

[v4,17/29] wpaspy: add debug support for Ctrl UDP class

Message ID 1456479524-14185-18-git-send-email-janusz.dziedzic@tieto.com
State Superseded
Headers show

Commit Message

Janusz.Dziedzic@tieto.com Feb. 26, 2016, 9:38 a.m. UTC
Add debug support for Ctrl class. This is
useful for debuging purpose for UDP connection.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
 wpaspy/wpaspy.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/wpaspy/wpaspy.py b/wpaspy/wpaspy.py
index 30bb652..76ac785 100644
--- a/wpaspy/wpaspy.py
+++ b/wpaspy/wpaspy.py
@@ -10,7 +10,9 @@  import os
 import stat
 import socket
 import select
+import logging
 
+logger = logging.getLogger()
 counter = 0
 
 class Ctrl:
@@ -54,7 +56,7 @@  class Ctrl:
                 self.cookie = reply
                 self.port = port
             except:
-                print "connect exception ", path, str(port)
+                logger.debug("connect exception " + str(path) + "/" + str(port))
                 if self.s != None:
                     self.s.close()
                 raise
@@ -79,12 +81,13 @@  class Ctrl:
 
     def request(self, cmd, timeout=10):
         if self.udp == True:
+            logger.debug(self.path + "/" + str(self.port) + " request: " + cmd)
             self.s.sendto(self.cookie + cmd, self.sockaddr)
         else:
             self.s.send(cmd)
         [r, w, e] = select.select([self.s], [], [], timeout)
         if r:
-            return self.s.recv(4096)
+            return self.recv()
         raise Exception("Timeout on waiting response")
 
     def attach(self):
@@ -115,4 +118,6 @@  class Ctrl:
 
     def recv(self):
         res = self.s.recv(4096)
+        if self.udp == True:
+           logger.debug(self.path + "/" + str(self.port) + " recv: " + res)
         return res