class io.WebSocket

class WebSocket {
    // fields

    io.SslState* readonly m_sslState;
    io.WebSocketHandshake const* readonly m_handshakeRequest;
    io.WebSocketHandshake const* readonly m_handshakeResponse;
    io.WebSocketEvents readonly volatile m_activeEvents;
    std.Error const* readonly volatile m_ioError;
    bool readonly m_isOpen;

    // properties

    io.SocketAddress const property m_address;
    io.SocketAddress const property m_peerAddress;
    io.WebSocketHandshakeHeaders const* autoget property m_extraHeaders;
    size_t autoget property m_incomingFrameSizeLimit;
    size_t autoget property m_incomingMessageSizeLimit;
    size_t autoget property m_outgoingFragmentationThreshold;
    size_t autoget property m_readBlockSize;
    size_t autoget property m_readBufferSize;
    size_t autoget property m_writeBufferSize;
    io.WebSocketOptions autoget property m_options;

    // construction

    construct();
    destruct();

    // methods

    bool errorcode open(
        io.AddressFamily family,
        bool isSecure = false
    );

    bool errorcode open(
        io.SocketAddress const* address,
        bool isSecure = false
    );

    void close();

    bool errorcode connect(
        io.SocketAddress const* address,
        string_t resource,
        string_t host
    );

    bool errorcode listen(size_t backlog = 0);

    io.WebSocket* errorcode accept(
        io.SocketAddress* address = null,
        bool isSuspended = false
    );

    void unsuspend();

    bool errorcode serverHandshake(
        uint_t statusCode,
        string_t reasonPhrase
    );

    bool errorcode serverHandshake();

    size_t errorcode read(
        io.WebSocketFrameOpcode* opcode,
        void* p,
        size_t size
    );

    size_t errorcode read(
        void* p,
        size_t size
    );

    size_t errorcode write(
        io.WebSocketFrameOpcode opcode,
        void const* p,
        size_t size
    );

    size_t errorcode writeText(string_t text);

    size_t errorcode writeBinary(
        void const* p,
        size_t size
    );

    size_t errorcode writePing(
        void const* p,
        size_t size
    );

    size_t errorcode writePing();

    size_t errorcode writePong(
        void const* p,
        size_t size
    );

    size_t errorcode writePong();
    size_t errorcode writeClose();

    long errorcode wait(
        io.WebSocketEvents eventMask,
        void function* handler(io.WebSocketEvents triggeredEvents)
    );

    bool errorcode cancelWait(long handle);

    io.WebSocketEvents blockingWait(
        io.WebSocketEvents eventMask,
        uint_t timeout = -1
    );

    io.WebSocketEvents async asyncWait(io.WebSocketEvents eventMask);

    // aliases

    alias dispose = close;
};