(listener, method, mux, handlers)
| 495 | |
| 496 | |
| 497 | def onaccept_tcp(listener, method, mux, handlers): |
| 498 | global _extra_fd |
| 499 | try: |
| 500 | sock, srcip = listener.accept() |
| 501 | except socket.error as e: |
| 502 | if e.args[0] in [errno.EMFILE, errno.ENFILE]: |
| 503 | debug1('Rejected incoming connection: too many open files!') |
| 504 | # free up an fd so we can eat the connection |
| 505 | os.close(_extra_fd) |
| 506 | try: |
| 507 | sock, srcip = listener.accept() |
| 508 | sock.close() |
| 509 | finally: |
| 510 | _extra_fd = os.open(os.devnull, os.O_RDONLY) |
| 511 | return |
| 512 | else: |
| 513 | raise |
| 514 | |
| 515 | dstip = method.get_tcp_dstip(sock) |
| 516 | debug1('Accept TCP: %s:%r -> %s:%r.' % (srcip[0], srcip[1], |
| 517 | dstip[0], dstip[1])) |
| 518 | if dstip[1] == sock.getsockname()[1] and islocal(dstip[0], sock.family): |
| 519 | debug1("-- ignored: that's my address!") |
| 520 | sock.close() |
| 521 | return |
| 522 | chan = mux.next_channel() |
| 523 | if not chan: |
| 524 | log('warning: too many open channels. Discarded connection.') |
| 525 | sock.close() |
| 526 | return |
| 527 | mux.send(chan, ssnet.CMD_TCP_CONNECT, b'%d,%s,%d' % |
| 528 | (sock.family, dstip[0].encode("ASCII"), dstip[1])) |
| 529 | outwrap = MuxWrapper(mux, chan) |
| 530 | handlers.append(Proxy(SockWrapper(sock, sock), outwrap)) |
| 531 | expire_connections(time.time(), mux) |
| 532 | |
| 533 | |
| 534 | def udp_done(chan, data, method, sock, dstip): |
nothing calls this directly
no test coverage detected