Updated sock.recv & timeouts

This commit is contained in:
Dionysus 2023-05-22 17:33:41 -04:00
parent 98b10c89ad
commit f2a6c8f217
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

View File

@ -77,10 +77,20 @@ class IRC(object):
self.sock = ctx.wrap_socket(self.sock) self.sock = ctx.wrap_socket(self.sock)
def listen(self): def listen(self):
buffer = str()
last = time.time()
while True: while True:
try: try:
data = self.sock.recv(2048).decode('utf-8') data = self.sock.recv(1024).decode('utf-8')
for line in (line for line in data.split('\r\n') if line): buffer += data
if data:
last = time.time()
else:
if time.time() - last > 120:
break
while '\r\n' in buffer:
line = buffer.split('\r\n')[0]
buffer = buffer.split('\r\n', 1)[1]
print('[~] - ' + line) print('[~] - ' + line)
if len(line.split()) >= 2: if len(line.split()) >= 2:
Events.handle(line) Events.handle(line)