Python socket.SO_TYPE() Examples
The following are code examples for showing how to use socket.SO_TYPE(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.
def is_socket(fd): """ Determine whether the file descriptor is a socket. :param fd: The file descriptor to interrogate. :return: ``True`` iff the file descriptor is a socket; otherwise ``False``. Query the socket type of `fd`. If there is no error, the file is a socket. """ result = False file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW) try: socket_type = file_socket.getsockopt( socket.SOL_SOCKET, socket.SO_TYPE) except socket.error as exc: exc_errno = exc.args if exc_errno == errno.ENOTSOCK: # Socket operation on non-socket. pass else: # Some other socket error. result = True else: # No error getting socket type. result = True return result