/[anoncvs]/projects/dispense2/sql-edition/servers/DoorClient.py


UCC Code Repository

Contents of /projects/dispense2/sql-edition/servers/DoorClient.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download) (as text)
Thu Dec 23 16:02:02 2004 UTC (16 years, 4 months ago) by grahame
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +11 -4 lines
File MIME type: text/x-python
 * DoorClient.py; cleaned up and has an alarm timeout in case of
	 getting stuck

1 #!/usr/bin/python
2
3 from LATClient import LATClient
4 from select import select
5 import signal
6 import sys
7
8 def check_door_service(service, test_string="got wombles?"):
9 latclient = LATClient(service=sys.argv[1])
10 latclient.sock.send(test_string)
11 rfh, wfh = latclient.get_fh()
12 wfh.write(test_string)
13 wfh.flush()
14 rr, wr, er = select([rfh], [], [], 10.0)
15 if rfh not in rr: return "open"
16 recv = rfh.read(len(test_string))
17 if recv <> test_string: return "error"
18 return "closed"
19
20 if __name__ == '__main__':
21 result_codes = { 'open' : 0, 'closed' : 1, 'error' : 2, 'invalid args' : 3}
22 def return_result(result):
23 print result
24 sys.exit(result_codes[result])
25 def timeout(signum, frame):
26 return_result("error")
27 if len(sys.argv) <> 2: return_result('invalid args')
28 signal.signal(signal.SIGALRM, timeout)
29 signal.alarm(15)
30 return_result(check_door_service(sys.argv[1]))

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26