Exemplo n.º 1
0
def test_simple_tcp():
    from rpython.rlib import rthread
    sock = RSocket()
    try_ports = [1023] + range(20000, 30000, 437)
    for port in try_ports:
        print 'binding to port %d:' % (port,),
        try:
            sock.bind(INETAddress('127.0.0.1', port))
            print 'works'
            break
        except SocketError as e:   # should get a "Permission denied"
            print e
    else:
        raise e

    addr = INETAddress('127.0.0.1', port)
    assert addr.eq(sock.getsockname())
    sock.listen(1)
    s2 = RSocket(AF_INET, SOCK_STREAM)
    s2.settimeout(10.0) # test one side with timeouts so select is used, shouldn't affect test
    connected = [False] #thread-mutable list
    def connecting():
        try:
            s2.connect(addr)
            connected[0] = True
        finally:
            lock.release()
    lock = rthread.allocate_lock()
    lock.acquire(True)
    rthread.start_new_thread(connecting, ())
    print 'waiting for connection'
    fd1, addr2 = sock.accept()
    s1 = RSocket(fd=fd1)
    print 'connection accepted'
    lock.acquire(True)
    assert connected[0]
    print 'connecting side knows that the connection was accepted too'
    assert addr.eq(s2.getpeername())
    #assert addr2.eq(s2.getsockname())
    assert addr2.eq(s1.getpeername())

    s1.send('?')
    print 'sent one character'
    buf = s2.recv(100)
    assert buf == '?'
    print 'received ok'
    def sendstuff():
        s2.sendall('x'*50000)
    rthread.start_new_thread(sendstuff, ())
    buf = ''
    while len(buf) < 50000:
        data = s1.recv(50100)
        print 'recv returned %d bytes' % (len(data,))
        assert data
        buf += data
    assert buf == 'x'*50000
    print 'data received ok'
    s1.shutdown(SHUT_RDWR)
    s1.close()
    s2.close()
Exemplo n.º 2
0
def test_simple_tcp():
    from rpython.rlib import rthread
    sock = RSocket()
    try_ports = [1023] + range(20000, 30000, 437)
    for port in try_ports:
        print 'binding to port %d:' % (port,),
        try:
            sock.bind(INETAddress('127.0.0.1', port))
            print 'works'
            break
        except SocketError as e:   # should get a "Permission denied"
            print e
    else:
        raise e

    addr = INETAddress('127.0.0.1', port)
    assert addr.eq(sock.getsockname())
    sock.listen(1)
    s2 = RSocket(AF_INET, SOCK_STREAM)
    s2.settimeout(10.0) # test one side with timeouts so select is used, shouldn't affect test
    connected = [False] #thread-mutable list
    def connecting():
        try:
            s2.connect(addr)
            connected[0] = True
        finally:
            lock.release()
    lock = rthread.allocate_lock()
    lock.acquire(True)
    rthread.start_new_thread(connecting, ())
    print 'waiting for connection'
    fd1, addr2 = sock.accept()
    s1 = RSocket(fd=fd1)
    print 'connection accepted'
    lock.acquire(True)
    assert connected[0]
    print 'connecting side knows that the connection was accepted too'
    assert addr.eq(s2.getpeername())
    #assert addr2.eq(s2.getsockname())
    assert addr2.eq(s1.getpeername())

    s1.send('?')
    print 'sent one character'
    buf = s2.recv(100)
    assert buf == '?'
    print 'received ok'
    def sendstuff():
        s2.sendall('x'*50000)
    rthread.start_new_thread(sendstuff, ())
    buf = ''
    while len(buf) < 50000:
        data = s1.recv(50100)
        print 'recv returned %d bytes' % (len(data,))
        assert data
        buf += data
    assert buf == 'x'*50000
    print 'data received ok'
    s1.shutdown(SHUT_RDWR)
    s1.close()
    s2.close()
Exemplo n.º 3
0
 def __init__(self, space):
     self.rlock_count = 0
     self.rlock_owner = 0
     try:
         self.lock = rthread.allocate_lock()
     except rthread.error:
         raise wrap_thread_error(space, "cannot allocate lock")
Exemplo n.º 4
0
 def g():
     l = allocate_lock()
     ok1 = l.acquire(True)
     ok2 = l.acquire(False)
     l.release()
     ok3 = l.acquire(False)
     res = ok1 and not ok2 and ok3
     return res
Exemplo n.º 5
0
Arquivo: os_lock.py Projeto: Mu-L/pypy
 def __init__(self, space, w_active=None):
     self.rlock_count = 0
     self.rlock_owner = 0
     self.w_active = w_active  # dictionary 'threading._active'
     try:
         self.lock = rthread.allocate_lock()
     except rthread.error:
         raise wrap_thread_error(space, "cannot allocate lock")
Exemplo n.º 6
0
 def g():
     l = allocate_lock()
     ok1 = l.acquire(True)
     ok2 = l.acquire(False)
     l.release()
     ok3 = l.acquire(False)
     res = ok1 and not ok2 and ok3
     return res
Exemplo n.º 7
0
        def main(argv):
            for j in range(N_THREADS):
                lock = rthread.allocate_lock()
                lock.acquire(True)
                glob.my_locks.append(lock)

            for j in range(N_THREADS):
                rthread.start_new_thread(do_random_work, ())

            for j in range(N_THREADS):
                glob.my_locks[j].acquire(True)

            print "OK"
            return 0
Exemplo n.º 8
0
    def __init__(self, manager, uv_loop, name=None, checkpoints=0):
        assert checkpoints != 0, "No, you can't create a zero-checkpoint vat"
        self.checkpoints = checkpoints

        self._manager = manager
        self.uv_loop = uv_loop

        if name is not None:
            self.name = name

        self._callbacks = []

        self._pendingLock = allocate_lock()
        self._pending = []
Exemplo n.º 9
0
    def __init__(self, manager, uv_loop, name=None, checkpoints=0):
        assert checkpoints != 0, "No, you can't create a zero-checkpoint vat"
        self.checkpoints = checkpoints

        self._manager = manager
        self.uv_loop = uv_loop

        if name is not None:
            self.name = name

        self._callbacks = []

        self._pendingLock = allocate_lock()
        self._pending = []
Exemplo n.º 10
0
def _get_netdb_lock_thread():
    if _lock_cache.lock is None:
        _lock_cache.lock = rthread.allocate_lock()
    return _lock_cache.lock
Exemplo n.º 11
0
 def setup(space):
     if bootstrapper.lock is None:
         try:
             bootstrapper.lock = rthread.allocate_lock()
         except rthread.error:
             raise wrap_thread_error(space, "can't allocate bootstrap lock")
Exemplo n.º 12
0
    assert addr.eq(sock.getsockname())
    sock.listen(1)
    s2 = RSocket(AF_INET, SOCK_STREAM)
    s2.settimeout(
        10.0
    )  # test one side with timeouts so select is used, shouldn't affect test
    connected = [False]  #thread-mutable list

    def connecting():
        try:
            s2.connect(addr)
            connected[0] = True
        finally:
            lock.release()

    lock = rthread.allocate_lock()
    lock.acquire(True)
    rthread.start_new_thread(connecting, ())
    print 'waiting for connection'
    fd1, addr2 = sock.accept()
    s1 = RSocket(fd=fd1)
    print 'connection accepted'
    lock.acquire(True)
    assert connected[0]
    print 'connecting side knows that the connection was accepted too'
    assert addr.eq(s2.getpeername())
    #assert addr2.eq(s2.getsockname())
    assert addr2.eq(s1.getpeername())

    s1.send('?')
    print 'sent one character'
Exemplo n.º 13
0
 def init(self):
     if not self._is_inited:
         self._is_inited = True
         self._lock = rthread.allocate_lock()
         rgil.gil_allocate()
         invoke_around_extcall(before_external_call, after_external_call)
Exemplo n.º 14
0
 def init(self):
     if not self._is_inited:
         self._lock = rthread.allocate_lock()
         self._is_inited = True
         rgil.allocate()
Exemplo n.º 15
0
 def __init__(self, space):
     self.space = space
     try:
         self.lock = rthread.allocate_lock()
     except rthread.error:
         raise wrap_thread_error(space, "out of resources")
Exemplo n.º 16
0
 def init(self):
     if not self._is_inited:
         self._is_inited = True
         self._lock = rthread.allocate_lock()
         rgil.gil_allocate()
         invoke_around_extcall(before_external_call, after_external_call)
Exemplo n.º 17
0
    else:
        raise e

    addr = INETAddress('127.0.0.1', port)
    assert addr.eq(sock.getsockname())
    sock.listen(1)
    s2 = RSocket(AF_INET, SOCK_STREAM)
    s2.settimeout(10.0) # test one side with timeouts so select is used, shouldn't affect test
    connected = [False] #thread-mutable list
    def connecting():
        try:
            s2.connect(addr)
            connected[0] = True
        finally:
            lock.release()
    lock = rthread.allocate_lock()
    lock.acquire(True)
    rthread.start_new_thread(connecting, ())
    print 'waiting for connection'
    fd1, addr2 = sock.accept()
    s1 = RSocket(fd=fd1)
    print 'connection accepted'
    lock.acquire(True)
    assert connected[0]
    print 'connecting side knows that the connection was accepted too'
    assert addr.eq(s2.getpeername())
    #assert addr2.eq(s2.getsockname())
    assert addr2.eq(s1.getpeername())

    s1.send('?')
    print 'sent one character'
Exemplo n.º 18
0
 def __init__(self, space):
     self.space = space
     try:
         self.lock = rthread.allocate_lock()
     except rthread.error:
         raise wrap_thread_error(space, "out of resources")
Exemplo n.º 19
0
def _create_lock():
    return Lock(rthread.allocate_lock())
Exemplo n.º 20
0
 def setup(space):
     if bootstrapper.lock is None:
         try:
             bootstrapper.lock = rthread.allocate_lock()
         except rthread.error:
             raise wrap_thread_error(space, "can't allocate bootstrap lock")
Exemplo n.º 21
0
def _create_lock():
    return Lock(rthread.allocate_lock())
Exemplo n.º 22
0
 def init(self):
     if not self._is_inited:
         self._lock = rthread.allocate_lock()
         self._is_inited = True
         rgil.allocate()
Exemplo n.º 23
0
def _get_netdb_lock_thread():
    if _lock_cache.lock is None:
        _lock_cache.lock = rthread.allocate_lock()
    return _lock_cache.lock