コード例 #1
0
from __future__ import division, absolute_import, print_function,\
 unicode_literals
import os
from nanomsg_wrappers import set_wrapper_choice, get_default_for_platform
WRAPPER = os.environ.get('NANOMSG_PY_TEST_WRAPPER', get_default_for_platform())
set_wrapper_choice(WRAPPER)

from nanomsg import (
    PAIR,
    Socket,
    create_message_buffer
)

from nanomsg.wrapper import (
    nn_send,
    nn_recv
)

SOCKET_ADDRESS = os.environ.get('NANOMSG_PY_TEST_ADDRESS', "inproc://a")
import time
BUFFER_SIZE = eval(os.environ.get('NANOMSG_PY_TEST_BUFFER_SIZE', "1024"))

msg = create_message_buffer(BUFFER_SIZE, 0)

DURATION = 10

print(('Working NANOMSG_PY_TEST_BUFFER_SIZE %d NANOMSG_PY_TEST_WRAPPER %r '
       'NANOMSG_PY_TEST_ADDRESS %r') % (BUFFER_SIZE, WRAPPER, SOCKET_ADDRESS))
count = 0
start_t = time.time()
with Socket(PAIR) as socket1:
コード例 #2
0
import unittest
import os
import uuid
import time

from nanomsg_wrappers import set_wrapper_choice, get_default_for_platform
set_wrapper_choice(os.environ.get('NANOMSG_PY_TEST_WRAPPER',
                                  get_default_for_platform()))

from nanomsg import (
    PAIR,
    DONTWAIT,
    SOL_SOCKET,
    SNDBUF,
    poll,
    Socket,
    NanoMsgAPIError
)

SOCKET_ADDRESS = os.environ.get('NANOMSG_PY_TEST_ADDRESS', "inproc://{0}".format(uuid.uuid4()))


class TestPoll(unittest.TestCase):
    def test_read_poll(self):
        with Socket(PAIR) as s1:
            with Socket(PAIR) as s2:
                s1.bind(SOCKET_ADDRESS)
                s2.connect(SOCKET_ADDRESS)
                r, _ = poll([s1, s2], [], 0)
                self.assertEqual(0, len(r), "Precondition nothing to read")
                sent = b'ABC'