3.3.2 Connection objects
Keywords: pyOpenSSL

###
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_client_ca_list`()
  Retrieve the list of preferred client certificate issuers sent by the server as `OpenSSL.crypto.X509Name` objects.

  If this is a client `Connection`, the list will be empty until the connection with the server is established.

  If this is a server `Connection`, return the list of certificate authorities that will be sent or has been sent to the client, as controlled by this `Connection`'s `Context`.

  New in version 0.10.

`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.

`bio_write`(bytes)
  If the Connection was created with a memory BIO, this method can be used to add bytes to the read end of that memory BIO. The Connection can then read the bytes (for example, in response to a call to `recv`).

`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.

`bio_read`(bufsize)
  If the Connection was created with a memory BIO, this method can be used to read bytes from the write end of that memory BIO. Many Connection methods will add bytes which must be read in this manner or the buffer will eventually fill up and the Connection will be able to take no further actions.

`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.

`bio_shutdown`()
  If the Connection was created with a memory BIO, this method can be used to indicate that ``end of file'' has been reached on the read end of that memory BIO.

`state_string`()
  Retrieve a verbose string detailing the state of the Connection.

`client_random`()
  Retrieve the random value used with the client hello message.

`server_random`()
  Retrieve the random value used with the server hello message.

`master_key`()
  Retrieve the value of the master key for this session.

`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.