-
Notifications
You must be signed in to change notification settings - Fork 0
/
MsgRelay.py
49 lines (33 loc) · 1.21 KB
/
MsgRelay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Function that TcpConnector schedules on the ThreadPool's WorkQ to receive requests from a connected client, queue
the request on the service Worker's MsgQ, and attempt to service the request (if the Conc is not already assigned
to another thread).
See also TcpConnector.py and Conc.py.
'''
from CorpsMsg import *
import sys
from logging import debug, error
def MsgRelay(MsgHdlr, TheAddr2Conc):
MsgBody = None
try:
MsgBody = MsgHdlr.rec_msg()
except:
debug(f'MsgRelay: Exception\n\t{sys.exc_info()[1]}')
MsgHdlr.close()
return
if MsgBody == None:
debug(f'MsgRelay: Error receiving Request')
MsgHdlr.close()
return
assert type(MsgBody) == CorpsRequest, "MsgRelay: MsgBody type not CorpsRequest"
assert MsgBody.MsgType == CorpsMsgType.ConcRequ, 'MsgRelay: Msg Type not ConcRequ'
MsgBody.MsgHdlr = MsgHdlr # Conc will need this to return response to Client
try:
aConc = TheAddr2Conc.getConc(MsgBody.ServerAddr)
except:
error(f'MsgRelay: Exception {MsgBody.ServerAddr} Not Found\n\t{sys.exc_info()[1]}')
MsgHdlr.close()
return
aConc.MsgQ.put(MsgBody)
aConc.main()
return