[rfc] pool test

This commit is contained in:
Swann 2019-01-25 17:28:53 +01:00
parent fe6de66581
commit 551b1a8401
No known key found for this signature in database
GPG Key ID: B02D0B41F8B6D2EE
3 changed files with 21 additions and 3 deletions

View File

@ -35,6 +35,8 @@ def main():
world.add_component(
session, net_components.NetworkInterface(context=instance_context))
world.add_component(
session, net_components.User(role=instance_role))
# A dummy main loop:
try:
@ -42,7 +44,6 @@ def main():
# Call world.process() to run all Processors.
world.process()
time.sleep(1)
except KeyboardInterrupt:
return

View File

@ -24,8 +24,10 @@ class NetworkInterface:
self.host = host
self.context = context
self.socket = context.socket(socket_type)
self.poller = zmq.Poller()
#TODO: Is this right to it here?
self.poller.register(self.socket, zmq.POLLIN)
self.socket.bind("{}://{}:{}".format(protocol,host,port))
class Property:

View File

@ -13,6 +13,8 @@ class NetworkSystem(esper.Processor):
def __init__(self):
super().__init__()
# Initialize poll set
# TODO: Use zmq_poll..
def process(self):
@ -22,4 +24,17 @@ class NetworkSystem(esper.Processor):
net_interface.socket.send(b"Waiting server response")
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