Line data Source code
1 : // Copyright 2025 Accenture. 2 : 3 : #pragma once 4 : 5 : #include <platform/estdint.h> 6 : 7 : namespace tcp 8 : { 9 : /** 10 : * interface for classes that want to receive data from a AbstractSocket 11 : * 12 : * \see AbstractSocket 13 : */ 14 : class IDataListener 15 : { 16 : public: 17 : IDataListener(IDataListener const&) = delete; 18 : IDataListener& operator=(IDataListener const&) = delete; 19 : 20 : /** 21 : * ErrorCodes used by IDataListener 22 : */ 23 : enum class ErrorCode : uint8_t 24 : { 25 : /** TCP connection was closed, i.e. by a FIN packet */ 26 : ERR_CONNECTION_CLOSED, 27 : /** TCP connection was reset, i.e. by a RST packet */ 28 : ERR_CONNECTION_RESET, 29 : /** TCP connection was timed out */ 30 : ERR_CONNECTION_TIMED_OUT, 31 : /** unknown error */ 32 : ERR_UNKNOWN 33 : }; 34 : 35 : /** 36 : * default constructor 37 : */ 38 2 : IDataListener() = default; 39 : 40 : /** 41 : * Callback that gets called when data has been received. 42 : * \param length Number of bytes available to read. 43 : * 44 : * \note 45 : * It is not required to read the data immediately from within this callback, the socket 46 : * will store the data and the next dataReceived callback will have a larger length 47 : * parameter. However, keep in mind that TCP has a WINDOW_SIZE. If data is not read from 48 : * the socket and length becomes WINDOW_SIZE, not further dataReceived callback will 49 : * occur because the sender cannot send any more data as the window size is zero. 50 : */ 51 : virtual void dataReceived(uint16_t length) = 0; 52 : 53 : /** 54 : * Callback that gets called when the registered AbstractTCPSocket got closed by peer 55 : * request. 56 : * \param status ErrorCode indication why connection was closed 57 : */ 58 : virtual void connectionClosed(ErrorCode status) = 0; 59 : }; 60 : 61 : } // namespace tcp