2017-05-25 23:04:33 +02:00
|
|
|
import Queue
|
2017-06-21 12:16:33 +02:00
|
|
|
import sys
|
2017-05-25 23:04:33 +02:00
|
|
|
import threading
|
2017-05-27 19:09:21 +02:00
|
|
|
import time
|
2017-05-25 23:04:33 +02:00
|
|
|
|
2017-05-27 19:09:21 +02:00
|
|
|
import addresses
|
2017-05-25 23:04:33 +02:00
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
from debug import logger
|
|
|
|
from helper_threading import StoppableThread
|
|
|
|
from inventory import Inventory
|
|
|
|
from network.connectionpool import BMConnectionPool
|
2017-05-27 19:09:21 +02:00
|
|
|
from network.bmproto import BMProto
|
2017-07-06 19:45:36 +02:00
|
|
|
from queues import receiveDataQueue
|
2017-05-25 23:04:33 +02:00
|
|
|
import protocol
|
2017-05-29 14:35:08 +02:00
|
|
|
import state
|
2017-05-25 23:04:33 +02:00
|
|
|
|
|
|
|
class ReceiveQueueThread(threading.Thread, StoppableThread):
|
|
|
|
def __init__(self):
|
|
|
|
threading.Thread.__init__(self, name="ReceiveQueueThread")
|
|
|
|
self.initStop()
|
|
|
|
self.name = "ReceiveQueueThread"
|
2017-05-29 00:24:07 +02:00
|
|
|
logger.info("init receive queue thread")
|
2017-05-25 23:04:33 +02:00
|
|
|
|
|
|
|
def run(self):
|
2017-05-29 14:35:08 +02:00
|
|
|
while not self._stopped and state.shutdown == 0:
|
2017-07-06 19:45:36 +02:00
|
|
|
try:
|
2017-07-08 06:54:25 +02:00
|
|
|
dest = receiveDataQueue.get(block=True, timeout=1)
|
2017-07-06 19:45:36 +02:00
|
|
|
receiveDataQueue.task_done()
|
|
|
|
except Queue.Empty:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if self._stopped:
|
|
|
|
break
|
2017-07-08 06:54:25 +02:00
|
|
|
|
2017-07-06 19:45:36 +02:00
|
|
|
# cycle as long as there is data
|
|
|
|
# methods should return False if there isn't enough data, or the connection is to be aborted
|
2017-07-08 06:54:25 +02:00
|
|
|
|
|
|
|
# state_* methods should return False if there isn't enough data,
|
|
|
|
# or the connection is to be aborted
|
|
|
|
|
|
|
|
try:
|
|
|
|
BMConnectionPool().inboundConnections[dest].process()
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
except AttributeError:
|
|
|
|
logger.error("Unknown state %s, ignoring", connection.state)
|
|
|
|
|
|
|
|
try:
|
|
|
|
BMConnectionPool().outboundConnections[dest].process()
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
except AttributeError:
|
|
|
|
logger.error("Unknown state %s, ignoring", connection.state)
|
|
|
|
|
2017-07-06 19:45:36 +02:00
|
|
|
try:
|
2017-07-08 06:54:25 +02:00
|
|
|
BMConnectionPool().udpSockets[dest].process()
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2017-07-06 19:45:36 +02:00
|
|
|
except AttributeError:
|
|
|
|
logger.error("Unknown state %s, ignoring", connection.state)
|