Changeset 711
- Timestamp:
- 11/04/07 18:09:10 (13 months ago)
- Files:
-
- 1 modified
-
tools/nsa/nsa.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tools/nsa/nsa.py
r710 r711 149 149 PORT = 8764 # Arbitrary non-privileged port 150 150 if sock == None: 151 # no socket yet, so lets create one 151 152 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 152 153 else: 153 154 self.sock = sock 154 155 156 # Allow reuse of address 155 157 self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 158 # Bind to specified host+port 156 159 self.sock.bind((HOST, PORT)) 160 # listen with backlog of 1 157 161 self.sock.listen(1) 158 162 … … 161 165 done = False 162 166 if self.sock: 167 # test for something on the port. 168 # the timeout can be set to something, this is just a non-blocking socket now 163 169 (r, w, e) = select.select([self.sock], [], [], 0) 164 170 if r: 171 # we have data so let's accept it 165 172 (client, addr) = self.sock.accept() 166 173 while not done: 167 174 data = None 168 175 try: 176 # Here, we wait until the client starts sending data. 177 # if we don't wait (in a blocking fashion) here, we'll 178 # get NOTREADY errors (we take care of those below with 179 # the if e.args[0] == 11 just in case). 169 180 data = client.recv(1024) 170 181 except socket.error, e: 182 # Socket not ready yet (err 11). Just try again. 171 183 if e.args[0] == 11: 172 184 pass 173 185 else: 174 186 raise e 187 # We recieved data? (no exception on recv?) 175 188 if data: 189 # Append 176 190 alldata += data 191 # We recieve 1024 max on the socket each recv, so 192 # if the len of data is less than 1024, there could 193 # possibly be more left. If not, we're done reading. 177 194 if len(data) < 1024: 178 195 done = True 196 # Close the connection so the client can terminate 179 197 client.close() 198 # Send the data to the channel 180 199 bot.say_it(alldata) 181 200
