Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TLS_cyassl by
TLSConnection.h@0:815067fd66c9, 2013-09-12 (annotated)
- Committer:
- feb11
- Date:
- Thu Sep 12 16:37:08 2013 +0000
- Revision:
- 0:815067fd66c9
- Child:
- 2:63ad554f6ca4
initial import
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
feb11 | 0:815067fd66c9 | 1 | #ifndef TLSCONNECTION_H |
feb11 | 0:815067fd66c9 | 2 | #define TLSCONNECTION_H |
feb11 | 0:815067fd66c9 | 3 | |
feb11 | 0:815067fd66c9 | 4 | #include "Socket.h" |
feb11 | 0:815067fd66c9 | 5 | #include "Endpoint.h" |
feb11 | 0:815067fd66c9 | 6 | #include "ssl.h" |
feb11 | 0:815067fd66c9 | 7 | |
feb11 | 0:815067fd66c9 | 8 | /** This class provides a user-friendly interface for the |
feb11 | 0:815067fd66c9 | 9 | axTLS library. |
feb11 | 0:815067fd66c9 | 10 | */ |
feb11 | 0:815067fd66c9 | 11 | class TLSConnection : public Socket, public Endpoint |
feb11 | 0:815067fd66c9 | 12 | { |
feb11 | 0:815067fd66c9 | 13 | public : |
feb11 | 0:815067fd66c9 | 14 | |
feb11 | 0:815067fd66c9 | 15 | TLSConnection(); |
feb11 | 0:815067fd66c9 | 16 | |
feb11 | 0:815067fd66c9 | 17 | /** This function tries to establish a TLS connection |
feb11 | 0:815067fd66c9 | 18 | with the given host. |
feb11 | 0:815067fd66c9 | 19 | It will first try to establish a TCP connection on |
feb11 | 0:815067fd66c9 | 20 | port 443 with the host. Then, it runs the TLS |
feb11 | 0:815067fd66c9 | 21 | handshake protocol. |
feb11 | 0:815067fd66c9 | 22 | |
feb11 | 0:815067fd66c9 | 23 | \param host A valid hostname (e.g. "mbed.org") |
feb11 | 0:815067fd66c9 | 24 | \return True if it managed to establish a connection |
feb11 | 0:815067fd66c9 | 25 | with the host. False otherwise. |
feb11 | 0:815067fd66c9 | 26 | */ |
feb11 | 0:815067fd66c9 | 27 | bool connect(const char *host); |
feb11 | 0:815067fd66c9 | 28 | |
feb11 | 0:815067fd66c9 | 29 | /** Indicates whether a connection is established or not. |
feb11 | 0:815067fd66c9 | 30 | |
feb11 | 0:815067fd66c9 | 31 | \return true if a connection is established, otherwise |
feb11 | 0:815067fd66c9 | 32 | returns false. |
feb11 | 0:815067fd66c9 | 33 | */ |
feb11 | 0:815067fd66c9 | 34 | bool is_connected(void); |
feb11 | 0:815067fd66c9 | 35 | |
feb11 | 0:815067fd66c9 | 36 | /** Sends some data to the host. This method does not return |
feb11 | 0:815067fd66c9 | 37 | until length bytes have been sent. |
feb11 | 0:815067fd66c9 | 38 | |
feb11 | 0:815067fd66c9 | 39 | \param data A pointer to some data |
feb11 | 0:815067fd66c9 | 40 | \param length Number of bytes to send |
feb11 | 0:815067fd66c9 | 41 | \return Number of bytes sent, or -1 if an error occured. |
feb11 | 0:815067fd66c9 | 42 | */ |
feb11 | 0:815067fd66c9 | 43 | int send_all(char *data, int length); |
feb11 | 0:815067fd66c9 | 44 | |
feb11 | 0:815067fd66c9 | 45 | /** Receive some data from the host. |
feb11 | 0:815067fd66c9 | 46 | |
feb11 | 0:815067fd66c9 | 47 | \param data |
feb11 | 0:815067fd66c9 | 48 | \param length Maximum number of bytes to receive |
feb11 | 0:815067fd66c9 | 49 | \return Number of bytes read in range 0..length, or -1 |
feb11 | 0:815067fd66c9 | 50 | if an error occured. |
feb11 | 0:815067fd66c9 | 51 | */ |
feb11 | 0:815067fd66c9 | 52 | int receive(char *data, int length); |
feb11 | 0:815067fd66c9 | 53 | |
feb11 | 0:815067fd66c9 | 54 | /** Close the connection. |
feb11 | 0:815067fd66c9 | 55 | |
feb11 | 0:815067fd66c9 | 56 | \param shutdown |
feb11 | 0:815067fd66c9 | 57 | \return True if the connection was closed with success, |
feb11 | 0:815067fd66c9 | 58 | false otherwise. If no connection was established, |
feb11 | 0:815067fd66c9 | 59 | returns true immediately. |
feb11 | 0:815067fd66c9 | 60 | */ |
feb11 | 0:815067fd66c9 | 61 | bool close(bool shutdown = true); |
feb11 | 0:815067fd66c9 | 62 | |
feb11 | 0:815067fd66c9 | 63 | private : |
feb11 | 0:815067fd66c9 | 64 | |
feb11 | 0:815067fd66c9 | 65 | bool _is_connected; |
feb11 | 0:815067fd66c9 | 66 | |
feb11 | 0:815067fd66c9 | 67 | CYASSL_CTX *_ssl_ctx; |
feb11 | 0:815067fd66c9 | 68 | CYASSL *_ssl; |
feb11 | 0:815067fd66c9 | 69 | }; |
feb11 | 0:815067fd66c9 | 70 | |
feb11 | 0:815067fd66c9 | 71 | #endif |
feb11 | 0:815067fd66c9 | 72 | |
feb11 | 0:815067fd66c9 | 73 |