This module provides socket operations and some related functions. The API of the functions and classes matches the API of the corresponding items in standard socket module exactly, but the synchronous functions in this module only block the current greenlet and let the others run.
For convenience, exceptions (like error and timeout) as well as the constants from socket module are imported into this module.
Connect to address and return the socket object.
Convenience function. Connect to address (a 2-tuple (host, port)) and return the socket object. Passing the optional timeout parameter will set the timeout on the socket instance before attempting to connect. If no timeout is supplied, the global default timeout setting returned by getdefaulttimeout() is used.
Some approximation of socket.getaddrinfo() implemented using gevent.dns.
If host is not a string, does not has any dots or is a numeric IP address, then the standard socket.getaddrinfo() is called.
Otherwise, calls either resolve_ipv4() or resolve_ipv6() and formats the result the way socket.getaddrinfo() does it.
Differs in the following ways:
Additionally, supports evdns_flags keyword arguments (default 0) that is passed to dns functions.
socket.gethostbyname() implemented using gevent.dns.
Differs in the following ways:
bind(address)
Bind the socket to a local address. For IP sockets, the address is a pair (host, port); the host must refer to the local host. For raw packet sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])
fileno() -> integer
Return the integer file descriptor of the socket.
getpeername() -> address info
Return the address of the remote endpoint. For IP sockets, the address info is a pair (hostaddr, port).
getsockname() -> address info
Return the address of the local endpoint. For IP sockets, the address info is a pair (hostaddr, port).
getsockopt(level, option[, buffersize]) -> value
Get a socket option. See the Unix manual for level and option. If a nonzero buffersize argument is given, the return value is a string of that length; otherwise it is an integer.
listen(backlog)
Enable a server to accept connections. The backlog argument must be at least 1; it specifies the number of unaccepted connection that the system will allow before refusing new connections.
setsockopt(level, option, value)
Set a socket option. See the Unix manual for level and option. The value argument can either be an integer or a string.
shutdown(flag)
Shut down the reading side of the socket (flag == SHUT_RD), the writing side of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).
dup() -> socket object
Return a new socket object connected to the same system resource.