chore(WebSocket): docs

This commit is contained in:
Günter Obiltschnig 2024-11-16 18:42:38 +01:00
parent 6b2a8abd96
commit 63b4bfd8ba
2 changed files with 38 additions and 4 deletions

View File

@ -49,6 +49,11 @@ class Net_API WebSocket: public StreamSocket
/// Note that special frames like PING must be handled at /// Note that special frames like PING must be handled at
/// application level. In the case of a PING, a PONG message /// application level. In the case of a PING, a PONG message
/// must be returned. /// must be returned.
///
/// Once connected, a WebSocket can be put into non-blocking
/// mode, by calling setBlocking(false).
/// Please refer to the sendFrame() and receiveFrame() documentation
/// for non-blocking behavior.
{ {
public: public:
enum Mode enum Mode
@ -244,11 +249,15 @@ public:
/// Values from the FrameFlags, FrameOpcodes and SendFlags enumerations /// Values from the FrameFlags, FrameOpcodes and SendFlags enumerations
/// can be specified in flags. /// can be specified in flags.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent.
/// less than the number of bytes specified.
/// ///
/// Certain socket implementations may also return a negative /// If the WebSocket is non-blocking and the frame could not
/// value denoting a certain condition. /// be sent in full, returns -1. In this case, the call
/// to sendFrame() must be repeated with exactly the same
/// parameters as soon as the socket becomes writable again
/// (see select() or poll()).
/// The value of length is returned after the complete
/// frame has been sent.
int receiveFrame(void* buffer, int length, int& flags); int receiveFrame(void* buffer, int length, int& flags);
/// Receives a frame from the socket and stores it /// Receives a frame from the socket and stores it
@ -278,6 +287,14 @@ public:
/// ///
/// The frame flags and opcode (FrameFlags and FrameOpcodes) /// The frame flags and opcode (FrameFlags and FrameOpcodes)
/// is stored in flags. /// is stored in flags.
///
/// In case of a non-blocking socket, may return -1, even
/// if a partial frame has been received.
/// In this case, receiveFrame() should be called again as
/// soon as more data becomes available (see select() or poll()).
/// Eventually, receiveFrame() will return the complete frame.
/// The given buffer will not be modified until the full frame has
/// been received.
int receiveFrame(Poco::Buffer<char>& buffer, int& flags); int receiveFrame(Poco::Buffer<char>& buffer, int& flags);
/// Receives a frame from the socket and stores it /// Receives a frame from the socket and stores it
@ -320,6 +337,14 @@ public:
/// called on the buffer beforehand, if the expectation is that /// called on the buffer beforehand, if the expectation is that
/// the received data is stored starting at the beginning of the /// the received data is stored starting at the beginning of the
/// buffer. /// buffer.
///
/// In case of a non-blocking socket, may return -1, even
/// if a partial frame has been received.
/// In this case, receiveFrame() should be called again as
/// soon as more data becomes available (see select() or poll()).
/// Eventually, receiveFrame() will return the complete frame.
/// The given buffer will not be modified until the full frame has
/// been received.
Mode mode() const; Mode mode() const;
/// Returns WS_SERVER if the WebSocket is a server-side /// Returns WS_SERVER if the WebSocket is a server-side

View File

@ -42,12 +42,21 @@ public:
// StreamSocketImpl // StreamSocketImpl
virtual int sendBytes(const void* buffer, int length, int flags); virtual int sendBytes(const void* buffer, int length, int flags);
/// Sends a WebSocket protocol frame. /// Sends a WebSocket protocol frame.
///
/// See WebSocket::sendFrame() for more information, including
/// behavior if set to non-blocking.
virtual int receiveBytes(void* buffer, int length, int flags); virtual int receiveBytes(void* buffer, int length, int flags);
/// Receives a WebSocket protocol frame. /// Receives a WebSocket protocol frame.
///
/// See WebSocket::receiveFrame() for more information, including
/// behavior if set to non-blocking.
virtual int receiveBytes(Poco::Buffer<char>& buffer, int flags = 0, const Poco::Timespan& span = 0); virtual int receiveBytes(Poco::Buffer<char>& buffer, int flags = 0, const Poco::Timespan& span = 0);
/// Receives a WebSocket protocol frame. /// Receives a WebSocket protocol frame.
///
/// See WebSocket::receiveFrame() for more information, including
/// behavior if set to non-blocking.
virtual SocketImpl* acceptConnection(SocketAddress& clientAddr); virtual SocketImpl* acceptConnection(SocketAddress& clientAddr);
virtual void connect(const SocketAddress& address); virtual void connect(const SocketAddress& address);