| 893 | import fcntl |
| 894 | |
| 895 | class file_wrapper: |
| 896 | # Here we override just enough to make a file |
| 897 | # look like a socket for the purposes of asyncore. |
| 898 | # The passed fd is automatically os.dup()'d |
| 899 | |
| 900 | def __init__(self, fd): |
| 901 | self.fd = os.dup(fd) |
| 902 | |
| 903 | def recv(self, *args): |
| 904 | return os.read(self.fd, *args) |
| 905 | |
| 906 | def send(self, *args): |
| 907 | return os.write(self.fd, *args) |
| 908 | |
| 909 | def getsockopt(self, level, optname, buflen=None): |
| 910 | if (level == socket.SOL_SOCKET and |
| 911 | optname == socket.SO_ERROR and |
| 912 | not buflen): |
| 913 | return 0 |
| 914 | raise NotImplementedError("Only asyncore specific behaviour " |
| 915 | "implemented.") |
| 916 | |
| 917 | read = recv |
| 918 | write = send |
| 919 | |
| 920 | def close(self): |
| 921 | os.close(self.fd) |
| 922 | |
| 923 | def fileno(self): |
| 924 | return self.fd |
| 925 | |
| 926 | class file_dispatcher(dispatcher): |
| 927 | |