AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AWebsocket Class Reference

Websocket implementation. More...

Detailed Description

Websocket implementation.

Public Types

enum class  Opcode {
  CONTINUATION = 0x0 , TEXT = 0x1 , BINARY = 0x2 , CLOSE = 0x8 ,
  PING = 0x9 , PONG = 0xa
}
 
- Public Types inherited from ACurl
enum class  Http {
  VERSION_NONE , VERSION_1_0 , VERSION_1_1 , VERSION_2_0 ,
  VERSION_2TLS , VERSION_2_PRIOR_KNOWLEDGE , VERSION_3 = 30 , VERSION_LAST
}
 
enum class  ResponseCode {
  HTTP_100_CONTINUE = 100 , HTTP_101_SWITCHING_PROTOCOL = 101 , HTTP_102_PROCESSING = 102 , HTTP_103_EARLY_HINTS = 103 ,
  HTTP_200_OK = 200 , HTTP_201_CREATED = 201 , HTTP_202_ACCEPTED = 202 , HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203 ,
  HTTP_204_NO_CONTENT = 204 , HTTP_205_RESET_CONTENT = 205 , HTTP_206_PARTIAL_CONTENT = 206 , HTTP_300_MULTIPLE_CHOICE = 300 ,
  HTTP_301_MOVED_PERMANENTLY = 301 , HTTP_302_FOUND = 302 , HTTP_303_SEE_OTHER = 303 , HTTP_304_NOT_MODIFIED = 304 ,
  HTTP_305_USE_PROXY = 305 , HTTP_306_SWITCH_PROXY = 306 , HTTP_307_TEMPORARY_REDIRECT = 307 , HTTP_308_PERMANENT_REDIRECT = 308 ,
  HTTP_400_BAD_REQUEST = 400 , HTTP_401_UNAUTHORIZED = 401 , HTTP_402_PAYMENT_REQUIRED = 402 , HTTP_403_FORBIDDEN = 403 ,
  HTTP_404_NOT_FOUND = 404 , HTTP_405_METHOD_NOT_ALLOWED = 405 , HTTP_406_NOT_ACCEPTABLE = 406 , HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407 ,
  HTTP_408_REQUEST_TIMEOUT = 408 , HTTP_409_CONFLICT = 409 , HTTP_410_GONE = 410 , HTTP_411_LENGTH_REQUIRED = 411 ,
  HTTP_412_PRECONDITION_FAILED = 412 , HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413 , HTTP_414_REQUEST_URI_TOO_LONG = 414 , HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415 ,
  HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416 , HTTP_417_EXPECTATION_FAILED = 417 , HTTP_500_INTERNAL_SERVER_ERROR = 500 , HTTP_501_NOT_IMPLEMENTED = 501 ,
  HTTP_502_BAD_GATEWAY = 502 , HTTP_503_SERVICE_UNAVAILABLE = 503 , HTTP_504_GATEWAY_TIMEOUT = 504 , HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505
}
 
enum class  Method { HTTP_GET , HTTP_POST , HTTP_PUT , HTTP_DELETE }
 
using WriteCallback = std::function< size_t(AByteBufferView data)>
 A read callback. More...
 
using ReadCallback = std::function< std::size_t(char *dst, size_t maxLen)>
 A read callback. More...
 
using HeaderCallback = std::function< void(AByteBufferView)>
 
using ErrorCallback = std::function< void(const ErrorDescription &description)>
 

Public Member Functions

 AWebsocket (const AString &url, AString key=generateKeyString())
 
void write (const char *src, size_t size) override
 Writes exact size bytes to stream. Blocking (waiting for write all data) is allowed. More...
 
void close () override
 Breaks curl loop in the run() method, closing underlying curl connection. More...
 
- Public Member Functions inherited from ACurl
 ACurl (Builder &builder)
 
 ACurl (Builder &&builder) noexcept
 
 ACurl (ACurl &&o) noexcept
 
ACurloperator= (Builder &&o) noexcept
 
ACurloperator= (ACurl &&o) noexcept
 
int64_t getContentLength () const
 
int64_t getNumberOfBytesDownloaded () const
 
AString getContentType () const
 
void run ()
 
void * handle () const noexcept
 
ResponseCode getResponseCode () const
 
AString getErrorString () const noexcept
 
- Public Member Functions inherited from AObject
_< AObjectsharedPtr ()
 
_weak< AObjectweakPtr ()
 
void clearSignals () noexcept
 
template<AAnySignal Signal, ACompatibleSlotFor< Signal > Function>
void connect (Signal &signal, Function &&function)
 
void setSignalsEnabled (bool enabled)
 
bool isSignalsEnabled () const noexcept
 
template<ASignalInvokable T>
void operator^ (T &&t)
 
_< AAbstractThreadgetThread () const
 
bool isSlotsCallsOnlyOnMyThread () const noexcept
 
void setSlotsCallsOnlyOnMyThread (bool slotsCallsOnlyOnMyThread)
 
- Public Member Functions inherited from aui::noncopyable
 noncopyable (const noncopyable &)=delete
 
noncopyableoperator= (const noncopyable &)=delete
 
- Public Member Functions inherited from IOutputStream
template<typename T >
void write (const T &t)
 
template<typename T >
IOutputStreamoperator<< (const T &t)
 

Signals and public fields

emits connected
 
emits< AByteBufferreceived
 
emits< AStringwebsocketClosed
 
- Signals and public fields inherited from ACurl
emits< ErrorDescriptionfail
 Emitted on network error. More...
 
emits success
 Emitted on success. More...
 
emits closeRequested
 

Friends

class WebsocketTest_Receive1_Test
 
class WebsocketTest_Receive2_Test
 

Additional Inherited Members

- Static Public Member Functions inherited from AObject
static void disconnect ()
 
template<AAnySignal Signal, aui::derived_from< AObject > Object, ACompatibleSlotFor< Signal > Function>
static void connect (Signal &signal, Object *object, Function &&function)
 
template<AAnySignal Signal, aui::derived_from< AObject > Object, ACompatibleSlotFor< Signal > Function>
static void connect (Signal &signal, Object &object, Function &&function)
 
template<AAnySignal Signal, aui::derived_from< AObject > Object, ACompatibleSlotFor< Signal > Function>
static void connect (Signal &signal, _< Object > object, Function &&function)
 
static void moveToThread (aui::no_escape< AObject > object, _< AAbstractThread > thread)
 
- Protected Member Functions inherited from AObject
void setThread (_< AAbstractThread > thread)
 Set thread of the object.
 

Member Function Documentation

◆ close()

void AWebsocket::close ( )
overridevirtual

Breaks curl loop in the run() method, closing underlying curl connection.

curl does not have a function which immediately stops the transfer (see https://curl.se/docs/faq.html#How_do_I_stop_an_ongoing_transfe). The stop functionality is handled in ACurl by returning error code on all callbacks. close() function is non-blocking, and some time would be taken until the run() method finally returns.

After calling close() method, none of the result signals (like fail, success) will be called.

close() is non-blocking function.

close() is thread-safe.

Reimplemented from ACurl.

◆ write()

void AWebsocket::write ( const char *  src,
size_t  size 
)
overridevirtual

Writes exact size bytes to stream. Blocking (waiting for write all data) is allowed.

Sneaky exceptions
An implementation can throw any exception that subclasses AIOException.
Parameters
dstsource buffer
sizesource buffer's size. > 0

Implements IOutputStream.

#include <AUI/Curl/AWebsocket.h>


The documentation for this class was generated from the following files:
Inheritance diagram for AWebsocket:
Collaboration diagram for AWebsocket: