summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2019-12-12 18:03:11 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commit9eabc7f9a8933d3d3e88835173d45721c6ba3041 (patch)
tree44503c5ebba276f8ff5ba7e72e3f4960a86c7685
parentebd640a9c5d308c0ba115fea6c8cc0666010eab6 (diff)
Execute socket loop on run socket function
Ported code from main function to a client function for clearing the main loop.
-rw-r--r--main.py20
-rw-r--r--src/ogClient.py20
2 files changed, 21 insertions, 19 deletions
diff --git a/main.py b/main.py
index ce2346c..66b451f 100644
--- a/main.py
+++ b/main.py
@@ -12,25 +12,7 @@ def main():
client = ogClient(ip, int(port))
client.connect()
-
- while 1:
- sock = client.get_socket()
- state = client.get_state()
-
- if state == State.CONNECTING:
- readset = [ sock ]
- writeset = [ sock ]
- else:
- readset = [ sock ]
- writeset = [ ]
-
- readable, writable, exception = select.select(readset, writeset, [ ])
- if state == State.CONNECTING and sock in writable:
- client.connect2()
- elif state == State.RECEIVING and sock in readable:
- client.receive()
- else:
- print "bad state" + str(state)
+ client.run()
if __name__ == "__main__":
main()
diff --git a/src/ogClient.py b/src/ogClient.py
index 2c57730..05c243d 100644
--- a/src/ogClient.py
+++ b/src/ogClient.py
@@ -93,3 +93,23 @@ class ogClient:
self.data = ""
self.content_len = 0
self.trailer = False
+
+ def run(self):
+ while 1:
+ sock = self.get_socket()
+ state = self.get_state()
+
+ if state == State.CONNECTING:
+ readset = [ sock ]
+ writeset = [ sock ]
+ else:
+ readset = [ sock ]
+ writeset = [ ]
+
+ readable, writable, exception = select.select(readset, writeset, [ ])
+ if state == State.CONNECTING and sock in writable:
+ self.connect2()
+ elif state == State.RECEIVING and sock in readable:
+ self.receive()
+ else:
+ print "bad state" + str(state)