[rfc] pool test
This commit is contained in:
parent
fe6de66581
commit
551b1a8401
3
main.py
3
main.py
@ -35,6 +35,8 @@ def main():
|
|||||||
|
|
||||||
world.add_component(
|
world.add_component(
|
||||||
session, net_components.NetworkInterface(context=instance_context))
|
session, net_components.NetworkInterface(context=instance_context))
|
||||||
|
world.add_component(
|
||||||
|
session, net_components.User(role=instance_role))
|
||||||
|
|
||||||
# A dummy main loop:
|
# A dummy main loop:
|
||||||
try:
|
try:
|
||||||
@ -42,7 +44,6 @@ def main():
|
|||||||
# Call world.process() to run all Processors.
|
# Call world.process() to run all Processors.
|
||||||
world.process()
|
world.process()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -24,8 +24,10 @@ class NetworkInterface:
|
|||||||
self.host = host
|
self.host = host
|
||||||
self.context = context
|
self.context = context
|
||||||
self.socket = context.socket(socket_type)
|
self.socket = context.socket(socket_type)
|
||||||
|
self.poller = zmq.Poller()
|
||||||
|
|
||||||
#TODO: Is this right to it here?
|
#TODO: Is this right to it here?
|
||||||
|
self.poller.register(self.socket, zmq.POLLIN)
|
||||||
self.socket.bind("{}://{}:{}".format(protocol,host,port))
|
self.socket.bind("{}://{}:{}".format(protocol,host,port))
|
||||||
|
|
||||||
class Property:
|
class Property:
|
||||||
|
@ -13,6 +13,8 @@ class NetworkSystem(esper.Processor):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
# Initialize poll set
|
||||||
|
|
||||||
|
|
||||||
# TODO: Use zmq_poll..
|
# TODO: Use zmq_poll..
|
||||||
def process(self):
|
def process(self):
|
||||||
@ -22,4 +24,17 @@ class NetworkSystem(esper.Processor):
|
|||||||
net_interface.socket.send(b"Waiting server response")
|
net_interface.socket.send(b"Waiting server response")
|
||||||
|
|
||||||
if user.role is net_components.Role.SERVER:
|
if user.role is net_components.Role.SERVER:
|
||||||
net_interface.socket.recv(b"Waiting server response")
|
print("Server loops")
|
||||||
|
try:
|
||||||
|
socks = dict(net_interface.poller.poll())
|
||||||
|
print("test")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
break
|
||||||
|
if net_interface.socket in socks:
|
||||||
|
message = net_interface.socket.recv()
|
||||||
|
|
||||||
|
print("test")
|
||||||
|
# process task
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user