3.3.2 Connection objects
Connection objects have the following methods:
- accept()
-
Call the accept method of the underlying socket and set up SSL on the
returned socket, using the Context object supplied to this Connection object at
creation. Returns a pair
(conn, address)
. where conn
is the new Connection object created, and address is as returned by the
socket's accept.
- bind(address)
-
Call the bind method of the underlying socket.
- close()
-
Call the close method of the underlying socket. Note: If you want
correct SSL closure, you need to call the shutdown method first.
- connect(address)
-
Call the connect method of the underlying socket and set up SSL on the
socket, using the Context object supplied to this Connection object at
creation.
- connect_ex(address)
-
Call the connect_ex method of the underlying socket and set up SSL on
the socket, using the Context object supplied to this Connection object at
creation. Note that if the connect_ex method of the socket doesn't
return 0, SSL won't be initialized.
- do_handshake()
-
Perform an SSL handshake (usually called after renegotiate or one of
set_accept_state or set_accept_state). This can raise the
same exceptions as send and recv.
- fileno()
-
Retrieve the file descriptor number for the underlying socket.
- listen(backlog)
-
Call the listen method of the underlying socket.
- get_app_data()
-
Retrieve application data as set by set_app_data.
- get_cipher_list()
-
Retrieve the list of ciphers used by the Connection object. WARNING: This API
has changed. It used to take an optional parameter and just return a string,
but not it returns the entire list in one go.
- get_context()
-
Retrieve the Context object associated with this Connection.
- get_peer_certificate()
-
Retrieve the other side's certificate (if any)
- getpeername()
-
Call the getpeername method of the underlying socket.
- getsockname()
-
Call the getsockname method of the underlying socket.
- getsockopt(level, optname[, buflen])
-
Call the getsockopt method of the underlying socket.
- pending()
-
Retrieve the number of bytes that can be safely read from the SSL buffer
(not the underlying transport buffer).
- recv(bufsize)
-
Receive data from the Connection. The return value is a string representing the
data received. The maximum amount of data to be received at once, is specified
by bufsize.
- renegotiate()
-
Renegotiate the SSL session. Call this if you wish to change cipher suites or
anything like that.
- send(string)
-
Send the string data to the Connection.
- sendall(string)
-
Send all of the string data to the Connection. This calls send
repeatedly until all data is sent. If an error occurs, it's impossible to tell
how much data has been sent.
- set_accept_state()
-
Set the connection to work in server mode. The handshake will be handled
automatically by read/write.
- set_app_data(data)
-
Associate data with this Connection object. data can be retrieved
later using the get_app_data method.
- set_connect_state()
-
Set the connection to work in client mode. The handshake will be handled
automatically by read/write.
- setblocking(flag)
-
Call the setblocking method of the underlying socket.
- setsockopt(level, optname, value)
-
Call the setsockopt method of the underlying socket.
- shutdown()
-
Send the shutdown message to the Connection. Returns true if the shutdown
message exchange is completed and false otherwise (in which case you call
recv() or send() when the connection becomes
readable/writeable.
- get_shutdown()
-
Get the shutdown state of the Connection. Returns a bitvector of either or
both of SENT_SHUTDOWN and RECEIVED_SHUTDOWN.
- set_shutdown(state)
-
Set the shutdown state of the Connection. state is a bitvector of
either or both of SENT_SHUTDOWN and RECEIVED_SHUTDOWN.
- sock_shutdown(how)
-
Call the shutdown method of the underlying socket.
- state_string()
-
Retrieve a verbose string detailing the state of the Connection.
- want_read()
-
Checks if more data has to be read from the transport layer to complete an
operation.
- want_write()
-
Checks if there is data to write to the transport layer to complete an
operation.