mirror of https://git.48k.eu/ogclient
Execute socket loop on run socket function
Ported code from main function to a client function for clearing the main loop.more_events
parent
ebd640a9c5
commit
9eabc7f9a8
20
main.py
20
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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue