예제 #1
0
 def test_tcp(self):
     addr = ("127.0.0.1", get_free_port())
     assert not thisproc.connections(kind='tcp4')
     server, client = tcp_socketpair(AF_INET, addr=addr)
     with nested(closing(server), closing(client)):
         cons = thisproc.connections(kind='tcp4')
         self.assertEqual(len(cons), 2)
         self.assertEqual(cons[0].status, psutil.CONN_ESTABLISHED)
         self.assertEqual(cons[1].status, psutil.CONN_ESTABLISHED)
예제 #2
0
 def tcp_tcp_socketpair(self):
     addr = ("127.0.0.1", get_free_port())
     server, client = tcp_socketpair(socket.AF_INET, addr=addr)
     with contextlib.closing(server):
         with contextlib.closing(client):
             # Ensure they are connected and the positions are
             # correct.
             self.assertEqual(server.getsockname(), addr)
             self.assertEqual(client.getpeername(), addr)
             self.assertNotEqual(client.getsockname(), addr)
예제 #3
0
 def tcp_tcp_socketpair(self):
     addr = ("127.0.0.1", get_free_port())
     server, client = tcp_socketpair(socket.AF_INET, addr=addr)
     with contextlib.closing(server):
         with contextlib.closing(client):
             # Ensure they are connected and the positions are
             # correct.
             self.assertEqual(server.getsockname(), addr)
             self.assertEqual(client.getpeername(), addr)
             self.assertNotEqual(client.getsockname(), addr)
예제 #4
0
 def test_tcp(self):
     addr = ("127.0.0.1", get_free_port())
     server, client = tcp_socketpair(AF_INET, addr=addr)
     with nested(closing(server), closing(client)):
         cons = psutil.Process().connections(kind='all')
         server_conn, client_conn = self.distinguish_tcp_socks(cons, addr)
         self.check_socket(server, conn=server_conn)
         self.check_socket(client, conn=client_conn)
         self.assertEqual(server_conn.status, psutil.CONN_ESTABLISHED)
         self.assertEqual(client_conn.status, psutil.CONN_ESTABLISHED)
예제 #5
0
 def test_tcp(self):
     addr = ("127.0.0.1", get_free_port())
     assert not thisproc.connections(kind='tcp4')
     server, client = tcp_socketpair(AF_INET, addr=addr)
     try:
         cons = thisproc.connections(kind='tcp4')
         self.assertEqual(len(cons), 2)
         self.assertEqual(cons[0].status, psutil.CONN_ESTABLISHED)
         self.assertEqual(cons[1].status, psutil.CONN_ESTABLISHED)
         # May not be fast enough to change state so it stays
         # commenteed.
         # client.close()
         # cons = thisproc.connections(kind='all')
         # self.assertEqual(len(cons), 1)
         # self.assertEqual(cons[0].status, psutil.CONN_CLOSE_WAIT)
     finally:
         server.close()
         client.close()
예제 #6
0
 def test_tcp(self):
     addr = ("127.0.0.1", get_free_port())
     assert not thisproc.connections(kind='tcp4')
     server, client = tcp_socketpair(AF_INET, addr=addr)
     try:
         cons = thisproc.connections(kind='tcp4')
         self.assertEqual(len(cons), 2)
         self.assertEqual(cons[0].status, psutil.CONN_ESTABLISHED)
         self.assertEqual(cons[1].status, psutil.CONN_ESTABLISHED)
         # May not be fast enough to change state so it stays
         # commenteed.
         # client.close()
         # cons = thisproc.connections(kind='all')
         # self.assertEqual(len(cons), 1)
         # self.assertEqual(cons[0].status, psutil.CONN_CLOSE_WAIT)
     finally:
         server.close()
         client.close()
예제 #7
0
 def test_udp_v6(self):
     addr = ("::1", get_free_port())
     with closing(bind_socket(AF_INET6, SOCK_DGRAM, addr=addr)) as sock:
         conn = self.check_socket(sock)
         assert not conn.raddr
         self.assertEqual(conn.status, psutil.CONN_NONE)
예제 #8
0
 def test_tcp_v4(self):
     addr = ("127.0.0.1", get_free_port())
     with closing(bind_socket(AF_INET, SOCK_STREAM, addr=addr)) as sock:
         conn = self.check_socket(sock)
         assert not conn.raddr
         self.assertEqual(conn.status, psutil.CONN_LISTEN)
예제 #9
0
 def bind_socket(self):
     port = get_free_port()
     with contextlib.closing(bind_socket(addr=('', port))) as s:
         self.assertEqual(s.getsockname()[1], port)
예제 #10
0
 def test_udp_v6(self):
     addr = ("::1", get_free_port())
     with closing(bind_socket(AF_INET6, SOCK_DGRAM, addr=addr)) as sock:
         conn = self.check_socket(sock)
         assert not conn.raddr
         self.assertEqual(conn.status, psutil.CONN_NONE)
예제 #11
0
 def test_tcp_v4(self):
     addr = ("127.0.0.1", get_free_port())
     with closing(bind_socket(AF_INET, SOCK_STREAM, addr=addr)) as sock:
         conn = self.check_socket(sock)
         assert not conn.raddr
         self.assertEqual(conn.status, psutil.CONN_LISTEN)
예제 #12
0
 def bind_socket(self):
     port = get_free_port()
     with contextlib.closing(bind_socket(addr=('', port))) as s:
         self.assertEqual(s.getsockname()[1], port)
예제 #13
0
 def test_udp_v4(self):
     addr = ("127.0.0.1", get_free_port())
     with closing(bind_socket(addr, AF_INET, SOCK_DGRAM)) as sock:
         conn = self.check_socket(sock)
         assert not conn.raddr
         self.assertEqual(conn.status, psutil.CONN_NONE)
예제 #14
0
 def test_tcp_v6(self):
     addr = ("::1", get_free_port())
     with closing(bind_socket(addr, AF_INET6, SOCK_STREAM)) as sock:
         conn = self.check_socket(sock)
         assert not conn.raddr
         self.assertEqual(conn.status, psutil.CONN_LISTEN)