(listener, mux, handlers)
| 178 | |
| 179 | |
| 180 | def onaccept(listener, mux, handlers): |
| 181 | global _extra_fd |
| 182 | try: |
| 183 | sock,srcip = listener.accept() |
| 184 | except socket.error, e: |
| 185 | if e.args[0] in [errno.EMFILE, errno.ENFILE]: |
| 186 | debug1('Rejected incoming connection: too many open files!\n') |
| 187 | # free up an fd so we can eat the connection |
| 188 | os.close(_extra_fd) |
| 189 | try: |
| 190 | sock,srcip = listener.accept() |
| 191 | sock.close() |
| 192 | finally: |
| 193 | _extra_fd = os.open('/dev/null', os.O_RDONLY) |
| 194 | return |
| 195 | else: |
| 196 | raise |
| 197 | dstip = original_dst(sock) |
| 198 | debug1('Accept: %s:%r -> %s:%r.\n' % (srcip[0],srcip[1], |
| 199 | dstip[0],dstip[1])) |
| 200 | if dstip[1] == listener.getsockname()[1] and islocal(dstip[0]): |
| 201 | debug1("-- ignored: that's my address!\n") |
| 202 | sock.close() |
| 203 | return |
| 204 | chan = mux.next_channel() |
| 205 | if not chan: |
| 206 | log('warning: too many open channels. Discarded connection.\n') |
| 207 | sock.close() |
| 208 | return |
| 209 | mux.send(chan, ssnet.CMD_CONNECT, '%s,%s' % dstip) |
| 210 | outwrap = MuxWrapper(mux, chan) |
| 211 | handlers.append(Proxy(SockWrapper(sock, sock), outwrap)) |
| 212 | |
| 213 | |
| 214 | dnsreqs = {} |
no test coverage detected