| 11 | WantReadError = Exception #overwritten when ssl is used |
| 12 | |
| 13 | class SecureSocketConnection: |
| 14 | def __init__(self, connection): |
| 15 | self.__dict__["connection"] = connection |
| 16 | |
| 17 | def __getattr__(self, name): |
| 18 | return getattr(self.__dict__["connection"], name) |
| 19 | |
| 20 | def __setattr__(self, name, value): |
| 21 | setattr(self.__dict__["connection"], name, value) |
| 22 | |
| 23 | def shutdown(self, how=1): |
| 24 | self.__dict__["connection"].shutdown() |
| 25 | |
| 26 | def accept(self): |
| 27 | connection, address = self.__dict__["connection"].accept() |
| 28 | return SecureSocketConnection(connection), address |
| 29 | |
| 30 | def send(self, buff): |
| 31 | try: |
| 32 | return self.__dict__["connection"].send(buff) |
| 33 | except WantReadError: |
| 34 | sleep(0.1) |
| 35 | return self.send(buff) |
| 36 | |
| 37 | def recv(self, buff): |
| 38 | try: |
| 39 | return self.__dict__["connection"].recv(buff) |
| 40 | except WantReadError: |
| 41 | sleep(0.1) |
| 42 | return self.recv(buff) |
| 43 | |
| 44 | class Socket(TSocket): |
| 45 | def __init__(self, host='localhost', port=7228, ssl=False): |