Commit 4b3a29ff27b30c0ee556de57088ff9e683a9b1fd

Authored by Ian Foster
1 parent 1610fce59a
Exists in master

quick fixes to pinhole

Showing 1 changed file with 9 additions and 7 deletions Side-by-side Diff

scripts/pinhole.py View file @ 4b3a29f
... ... @@ -21,12 +21,15 @@
21 21 import signal
22 22 import os
23 23  
24   -running = True
  24 +#enable logging to file
  25 +#sys.stdout = open( 'pinhole.log', 'w' )
25 26  
  27 +
26 28 def log( s ):
27 29 print '%s:%s' % ( time.ctime(), s )
28 30 sys.stdout.flush()
29 31  
  32 +
30 33 class PipeThread( Thread ):
31 34 pipes = []
32 35 def __init__( self, source, sink ):
... ... @@ -40,7 +43,7 @@
40 43 log( '%s pipes active' % len( PipeThread.pipes ))
41 44  
42 45 def run( self ):
43   - while running:
  46 + while True:
44 47 try:
45 48 data = self.source.recv( 1024 )
46 49 if not data: break
... ... @@ -52,6 +55,7 @@
52 55 PipeThread.pipes.remove( self )
53 56 log( '%s pipes active' % len( PipeThread.pipes ))
54 57  
  58 +
55 59 class Pinhole( Thread ):
56 60 def __init__( self, port, newhost, newport ):
57 61 Thread.__init__( self )
... ... @@ -63,7 +67,7 @@
63 67 self.sock.listen(5)
64 68  
65 69 def run( self ):
66   - while running:
  70 + while True:
67 71 newsock, address = self.sock.accept()
68 72 log( 'Creating new session for %s %s ' % address )
69 73 fwd = socket( AF_INET, SOCK_STREAM )
70 74  
71 75  
... ... @@ -71,12 +75,9 @@
71 75 PipeThread( newsock, fwd ).start()
72 76 PipeThread( fwd, newsock ).start()
73 77  
74   -if __name__ == '__main__':
75 78  
  79 +if __name__ == '__main__':
76 80 print 'Starting Pinhole'
77   -
78   - import sys
79   - #sys.stdout = open( 'pinhole.log', 'w' )
80 81  
81 82 if len( sys.argv ) > 1:
82 83 port = newport = int( sys.argv[1] )