mirror of https://git.48k.eu/ogclient
#1056 add cleanup method and use it
add method to clean up interval socket state and use itmore_events
parent
7940887068
commit
c61964fa85
|
@ -47,6 +47,12 @@ class ogClient:
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
return self.state
|
return self.state
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
self.data = ""
|
||||||
|
self.content_len = 0
|
||||||
|
self.header_len = 0
|
||||||
|
self.trailer = False
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
print('connecting...')
|
print('connecting...')
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
@ -57,10 +63,7 @@ class ogClient:
|
||||||
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4)
|
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4)
|
||||||
|
|
||||||
self.state = State.CONNECTING
|
self.state = State.CONNECTING
|
||||||
self.data = ""
|
self.cleanup()
|
||||||
self.trailer = False
|
|
||||||
self.content_len = 0
|
|
||||||
self.header_len = 0
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.sock.connect((self.ip, self.port))
|
self.sock.connect((self.ip, self.port))
|
||||||
|
@ -121,12 +124,7 @@ class ogClient:
|
||||||
if self.trailer and (len(self.data) >= self.content_len + self.header_len):
|
if self.trailer and (len(self.data) >= self.content_len + self.header_len):
|
||||||
request.parser(self.data)
|
request.parser(self.data)
|
||||||
self.ogrest.process_request(request, self)
|
self.ogrest.process_request(request, self)
|
||||||
|
self.cleanup()
|
||||||
# Cleanup state information from request
|
|
||||||
self.data = ""
|
|
||||||
self.content_len = 0
|
|
||||||
self.header_len = 0
|
|
||||||
self.trailer = False
|
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.state = State.FORCE_DISCONNECTED
|
self.state = State.FORCE_DISCONNECTED
|
||||||
|
|
Loading…
Reference in New Issue