AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AWebsocket Class Reference

Websocket implementation.

#include <AUI/Curl/AWebsocket.h>

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.
 
using WriteCallbackV2 = std::function<size_t(ACurl& curl, AByteBufferView data)>
 A read callback.
 
using ReadCallback = std::function<std::size_t(char* dst, size_t maxLen)>
 A read callback.
 
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.
 
void close () override
 Breaks curl loop in the run() method, closing underlying curl connection.
 
- 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 ()
 
template<typename Connectable, ACompatibleSlotFor< Connectable > Function>
decltype(auto) connect (const Connectable &connectable, Function &&function)
 Connects signal or property to slot of "this" object.
 
void setSignalsEnabled (bool enabled)
 
bool isSignalsEnabled () const noexcept
 
template<ASignalInvokable T>
void operator^ (T &&t) noexcept
 
_< AAbstractThreadgetThread () const
 
bool isSlotsCallsOnlyOnMyThread () const noexcept
 
void setSlotsCallsOnlyOnMyThread (bool slotsCallsOnlyOnMyThread)
 
- Public Member Functions inherited from AObjectBase
 AObjectBase (AObjectBase &&rhs) noexcept
 
 AObjectBase (const AObjectBase &rhs) noexcept
 
AObjectBaseoperator= (const AObjectBase &rhs) noexcept
 
AObjectBaseoperator= (AObjectBase &&rhs) noexcept
 
- 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.
 
emits success
 Emitted on success.
 
emits closeRequested
 

Additional Inherited Members#

- Static Public Member Functions inherited from AObject
static void disconnect ()
 
template<AAnySignal Signal, aui::derived_from< AObjectBase > Object, ACompatibleSlotFor< Signal > Function>
static decltype(auto) connect (const Signal &signal, Object *object, Function &&function)
 Connects signal to the slot of the specified object.
 
template<AAnyProperty Property, aui::derived_from< AObjectBase > Object, typename Function>
static decltype(auto) connect (const Property &property, Object *object, Function &&function)
 Connects property to the slot of the specified object.
 
template<APropertyReadable PropertySource, APropertyWritable PropertyDestination>
requires requires { { *propertySource } -> aui::convertible_to<std::decay_t<decltype(*propertyDestination)>>; }
static void connect (PropertySource &&propertySource, PropertyDestination &&propertyDestination)
 Connects source property to the destination property.
 
template<APropertyWritable PropertySource, APropertyWritable PropertyDestination>
requires requires { { *propertySource } -> aui::convertible_to<std::decay_t<decltype(*propertyDestination)>>; { *propertyDestination } -> aui::convertible_to<std::decay_t<decltype(*propertySource)>>; }
static void biConnect (PropertySource &&propertySource, PropertyDestination &&propertyDestination)
 Connects source property to the destination property and opposite (bidirectionally).
 
template<AAnySignalOrProperty Connectable, aui::derived_from< AObjectBase > Object, ACompatibleSlotFor< Connectable > Function>
static decltype(auto) connect (const Connectable &connectable, Object &object, Function &&function)
 Connects signal or property to the slot of the specified object.
 
template<AAnySignalOrProperty Connectable, aui::derived_from< AObjectBase > Object, ACompatibleSlotFor< Connectable > Function>
static decltype(auto) connect (const Connectable &connectable, _< Object > object, Function &&function)
 Connects signal or property to the slot of the specified object.
 
template<AAnySignalOrProperty Connectable, aui::derived_from< AObjectBase > Object, typename Function>
static decltype(auto) connect (const Connectable &connectable, ASlotDef< Object *, Function > slotDef)
 Connects signal to the slot of the specified object. Slot is packed to single argument.
 
template<AAnyProperty Property, typename Object, ACompatibleSlotFor< Property > Function>
requires (!aui::derived_from<Object, AObject>)
static void connect (const Property &property, _< Object > object, Function &&function)
 Connects signal or property to the slot of the specified non-AObject type.
 
static void moveToThread (aui::no_escape< AObject > object, _< AAbstractThread > thread)
 
- Static Public Attributes inherited from AObject
static constexpr AObjectBaseGENERIC_OBSERVER = nullptr
 Indicates that a connection should not be explicitly linked to receiver's lifetime.
 
- Static Public Attributes inherited from AObjectBase
static ASpinlockMutex SIGNAL_SLOT_GLOBAL_SYNC
 
- Protected Member Functions inherited from AObject
void setThread (_< AAbstractThread > thread)
 Set thread of the object.
 
- Protected Member Functions inherited from AObjectBase
void clearAllIngoingConnections () noexcept
 
virtual void handleSlotException (std::exception_ptr exception)
 Called then an exception has thrown during slot processing of the signal emitted by this object.
 

Member Function Documentation#

◆ close()#

void AWebsocket::close ( )
overridevirtual

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
Sneaky exceptions
An implementation can throw any exception that subclasses AIOException.
Parameters
srcsource buffer
sizesource buffer's size. > 0

Implements IOutputStream.