import zmq

from crankycoin import config, logger


class Queue(object):

    QUEUE_BIND_IN = config['user']['queue_bind_in']
    QUEUE_BIND_OUT = config['user']['queue_bind_out']
    QUEUE_PROCESSING_WORKERS = config['user']['queue_processing_workers']

    @classmethod
    def start_queue(cls):
        try:
            context = zmq.Context(1)
            # Socket facing producers
            frontend = context.socket(zmq.PULL)
            frontend.bind(cls.QUEUE_BIND_IN)
            # Socket facing consumers
            backend = context.socket(zmq.PUSH)
            backend.bind(cls.QUEUE_BIND_OUT)

            zmq.proxy(frontend, backend)

        except Exception as e:
            logger.error("could not start queue: %s", e.message)
            raise

    @classmethod
    def enqueue(cls, msg):
        context = zmq.Context()
        socket = context.socket(zmq.PUSH)
        socket.connect(cls.QUEUE_BIND_IN)
        socket.send_json(msg)

    @classmethod
    def dequeue(cls):
        context = zmq.Context()
        socket = context.socket(zmq.PULL)
        socket.connect(cls.QUEUE_BIND_OUT)
        return socket.recv_json()

@@ -1,12 +1,23 @@
+import sys%0A
 import zmq%0A%0A
@@ -55,16 +55,48 @@
 logger%0A%0A
+WIN32 = 'win32' in sys.platform%0A
 %0Aclass Q
@@ -109,17 +109,16 @@
 bject):%0A
-%0A
     QUEU
@@ -164,46 +164,155 @@
 in'%5D
-%0A    QUEUE_BIND_OUT = config%5B'user'%5D%5B'
+ if not WIN32 else config%5B'user'%5D%5B'win_queue_bind_in'%5D%0A    QUEUE_BIND_OUT = config%5B'user'%5D%5B'queue_bind_out'%5D if not WIN32 else config%5B'user'%5D%5B'win_
 queu
@@ -886,16 +886,8 @@
 %22, e
-.message
 )%0A  

Fix `protocol not supported` on Windows