In the question Python - non-blocking sockets using selectors the following code is used:
events = selectors.EVENT_READ | selectors.EVENT_WRITE
The values of event_read or event_write flags are not mentioned nor explained at https://docs.python.org/3/library/selectors.html. Neither is an explanation give in the select() module or given at https://realpython.com/python-sockets/. It would be appreciated to emphasize on this particular part or provide reading material that explains this in much more detail than provided by python docs or the realpython link.
In relation, during service connection this is used: if mask & selectors.EVENT_READ:
I can imaging that the evaluation can be 1 & 1 or 2 & 2 and in both cases the code within the if-statement is executed. So if the expression evaluates 3 & 1 it would not execute, right?
The code:
def service_connection(key, mask):
sock = key.fileobj
data = key.data
if mask & selectors.EVENT_READ:
recv_data = sock.recv(1024)
if recv_data:
data.outb += recv_data
else:
print('closing connection to', data.addr)
sel.unregister(sock)
sock.close()
if mask & selectors.EVENT_WRITE:
if data.outb:
print('echoing', repr(data.outb), 'to', data.addr)
sent = sock.send(data.outb)
data.outb = data.outb[sent:]