- 7980970A1D40B7A348A8FED795896D0CFA4568E3B4464768A0EA118EFDE16645BCDF2E934BA1ED42BC1D7708BCCB9EF28F0645C13CBDC80754D00D8DD47A6729+ EDA2C9E8930F8207A7588763084768F494B4CAD89C6CCCEC07E9C7412AE8CE238A07B970A7F937048B7CAE1F5D7D92CF67ED88E9802A7694CE0CB274D9A81DD3logotron/bot.py(14 . 7)(14 . 7)
13 ##############################################################################
14
15 # Version. If changing this program, always set this to same # as in MANIFEST
16 Ver = 596907
17 Ver = 597604
18
19 ##############################################################################
20
(129 . 15)(129 . 32)
22 # Used to compute 'uptime'
23 time_last_conn = datetime.now()
24
25 # Init socket:
26 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
27
28 # Set keepalive:
29 sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
30 # Socket will be here:
31 sock = None;
32
33 # Initially we are not connected to anything
34 connected = False
35
36 def init_socket():
37 global sock
38 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
39
40 # Disable Nagle's algorithm for transmit operations
41 sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
42 # Disable Nagle's algorithm for receive operation, Linux-only
43 try:
44 sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_QUICKACK, 1)
45 except Exception as e:
46 logging.warning(e)
47
48 connected = False
49
50 def deinit_socket():
51 global connected
52 global sock
53 sock.close()
54 connected = False
55
56 # Connect to given host:port; return whether connected
57 def connect(host, port):
58 logging.info("Connecting to %s:%s" % (host, port))
(176 . 7)(193 . 7)
60 sock.send(message.encode("utf-8"))
61 except (socket.timeout, socket.error) as e:
62 logging.warning("Socket could not send! Disconnecting.")
63 connected = False
64 deinit_socket()
65 return False
66 except Exception as e:
67 logging.exception(e)
(227 . 6)(244 . 10)
69 def irc():
70 global connected
71 global time_last_conn
72 global sock
73
74 # Initialize a socket
75 init_socket()
76
77 # Connect to one among the specified servers, in given priority :
78 while not connected:
(254 . 20)(275 . 20)
80 try:
81 data = sock.recv(Buf_Size)
82 except socket.timeout as e:
83 logging.debug("Listen timed out")
84 logging.debug("Receive timed out")
85 continue
86 except socket.error as e:
87 logging.warning("Listen socket error, disconnecting.")
88 connected = False
89 logging.warning("Receive socket error, disconnecting.")
90 deinit_socket()
91 continue
92 except Exception as e:
93 logging.exception(e)
94 connected = False
95 deinit_socket()
96 continue
97 else:
98 if len(data) == 0:
99 logging.warning("Listen socket closed, disconnecting.")
100 connected = False
101 logging.warning("Receive socket closed, disconnecting.")
102 deinit_socket()
103 continue
104 try:
105 try: