debuggers.hg

view tools/python/xen/web/unix.py @ 4655:a838a908e38e

bitkeeper revision 1.1327.2.2 (4267a9b3MhPpljnjQ5IbfLdzcW2K3w)

Remove twisted from the HTTP server and replace with a
threaded server. Add classes to provide tcp and unix servers
using threads instead of twisted. Remove use of twisted from
the consoles, event server and HTTP resources

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Apr 21 13:25:07 2005 +0000 (2005-04-21)
parents
children 7719c5e6954d
line source
1 import sys
2 import socket
3 import os
5 from connection import *
6 from protocol import *
8 class UnixServerConnection(SocketServerConnection):
9 pass
11 class UnixListener(SocketListener):
13 def __init__(self, path, factory, backlog=None):
14 SocketListener.__init__(self, factory, backlog=backlog)
15 self.path = path
17 def createSocket(self):
18 try:
19 os.unlink(self.path)
20 except SystemExit:
21 raise
22 except Exception, ex:
23 pass
24 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
25 sock.bind(self.path)
26 return sock
28 def acceptConnection(self, sock, protocol, addr):
29 return UnixServerConnection(sock, protocol, addr, self)
31 class UnixClientConnection(SocketClientConnection):
33 def __init__(self, addr, connector):
34 SocketClientConnection.__init__(self, connector)
35 self.addr = addr
37 def createSocket(self):
38 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
39 return sock
41 class UnixConnector(SocketConnector):
43 def __init__(self, path, factory, timeout=None):
44 SocketConnector.__init__(self, factory)
45 self.addr = path
46 self.timeout = timeout
48 def getDestination(self):
49 return self.addr
51 def connectTransport(self):
52 self.transport = UnixClientConnection(self.addr, self)
53 self.transport.connect(self.timeout)
55 def listenUNIX(path, factory, backlog=None):
56 l = UnixListener(path, factory, backlog=backlog)
57 l.startListening()
58 return l
60 def connectUNIX(path, factory, timeout=None):
61 c = UnixConnector(path, factory, timeout=timeout)
62 c.connect()
63 return c
65 def main(argv):
66 path = "/tmp/test-foo"
67 if argv[1] == "client":
68 c = connectUNIX(path, TestClientFactory())
69 print "client:", c
70 else:
71 s = listenUNIX(path, TestServeractory())
72 print "server:", s
74 if __name__ == "__main__":
75 main(sys.argv)