class EE::Network::SSL::SSLSocket

Overview

TLS over TCP socket implementation. More…

#include <sslsocket.hpp>

class SSLSocket: public EE::Network::TcpSocket {
public:
    // fields

    static std::string CertificatesPath;

    // construction

    SSLSocket(std::string hostname, bool validateCertificate, bool validateHostname, SSLSocket* restoreSession = NULL);
    virtual ~SSLSocket();

    // methods

    static bool init();
    static bool end();
    static bool isSupported();
    static SSLSocket* New(std::string hostname, bool validateCertificate, bool validateHostname, SSLSocket* restoreSession = NULL);
    virtual Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
    virtual void disconnect();
    virtual Status send(const void* data, std::size_t size);
    virtual Status receive(void* data, std::size_t size, std::size_t& received);
    virtual Status send(Packet& packet);
    virtual Status receive(Packet& packet);
    Status sslConnect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
    void sslDisconnect();
    Status tcpConnect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
    void tcpDisconnect();
    Status tcpReceive(void* data, std::size_t size, std::size_t& received);
    Status tcpSend(const void* data, std::size_t size, std::size_t& sent);
};

Inherited Members

public:
    // typedefs

    typedef std::function<void(const char*bytes, size_t n)> ReadFn;

    // enums

    enum {
        AnyPort = 0,
    };

    enum Status;

    // structs

    struct PendingPacket;

    // methods

    void setBlocking(bool blocking);
    bool isBlocking() const;
    static TcpSocket* New();
    unsigned short getLocalPort() const;
    IpAddress getRemoteAddress() const;
    unsigned short getRemotePort() const;
    virtual Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
    virtual void disconnect();
    virtual Status send(const void* data, std::size_t size);
    virtual Status send(const void* data, std::size_t size, std::size_t& sent);
    virtual Status receive(void* data, std::size_t size, std::size_t& received);
    virtual Status send(Packet& packet);
    virtual Status receive(Packet& packet);
    void setSendTimeout(const Time& timeout);
    void setReceiveTimeout(const Time& timeout);
    void startAsyncRead(ReadFn readFn = nullptr);

Detailed Documentation

TLS over TCP socket implementation.

Fields

static std::string CertificatesPath

This is the certificate location in the file system. If no certificate path is provided it will try to use the default CA bundle provided in most OSes. If no CA bundle is found on the current OS it will fallback to “assets/ca-bundle.pem”. The path can be inside of any open EE::System::Pack. This should be set before using any SSLSocket connection.

Methods

static bool isSupported()

Returns:

True when the library was compiled with SSL support.

virtual Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero)

Connect the socket to a remote peer In blocking mode, this function may take a while, especially if the remote peer is not reachable. The last parameter allows you to stop trying to connect after a given timeout. If the socket was previously connected, it is first disconnected.

Parameters:

remoteAddress

Address of the remote peer

remotePort

Port of the remote peer

timeout

Optional maximum time to wait

Returns:

Status code

See also:

Disconnect

virtual void disconnect()

Disconnect the socket from its remote peer This function gracefully closes the connection. If the socket is not connected, this function has no effect.

See also:

Connect

virtual Status send(const void* data, std::size_t size)

Send raw data to the remote peer To be able to handle partial sends over non-blocking sockets, use the send(const void*, std::size_t, std::size_t&) overload instead.

This function will fail if the socket is not connected.

Parameters:

data

Pointer to the sequence of bytes to send

size

Number of bytes to send

Returns:

Status code

See also:

Receive

virtual Status receive(void* data, std::size_t size, std::size_t& received)

Receive raw data from the remote peer In blocking mode, this function will wait until some bytes are actually received. This function will fail if the socket is not connected.

Parameters:

data

Pointer to the array to fill with the received bytes

size

Maximum number of bytes that can be received

received

This variable is filled with the actual number of bytes received

Returns:

Status code

See also:

Send

virtual Status send(Packet& packet)

Send a formatted packet of data to the remote peer.

In non-blocking mode, if this function returns sf::Socket::Partial, you must retry sending the same unmodified packet before sending anything else in order to guarantee the packet arrives at the remote peer uncorrupted.

This function will fail if the socket is not connected.

Parameters:

packet

Packet to send

Returns:

Status code

See also:

Receive

virtual Status receive(Packet& packet)

Receive a formatted packet of data from the remote peer In blocking mode, this function will wait until the whole packet has been received. This function will fail if the socket is not connected.

Parameters:

packet

Packet to fill with the received data

Returns:

Status code

See also:

Send