libzypp 17.37.17
|
#include <zypp-core/zyppng/io/socket.h>
Public Types | |
enum | SocketError { NoError , UnknownSocketError , InsufficientPermissions , InvalidSocketOptions , InsufficientRessources , UnsupportedSocketOptions , FailedSocketOperation , SocketAlreadyBound , SocketNotListening , AddressInUse , AddressNotAvailable , AddressIssue , OperationNotSupported , ConnectionTimeout , ConnectionDelayed , ConnectionRefused , ConnectionClosedByRemote , NetworkUnreachable , InternalError } |
enum | SocketState { InitialState , ConnectingState , ConnectedState , ListeningState , ClosingState , ClosedState } |
using | Ptr = std::shared_ptr<Socket> |
Public Types inherited from zyppng::IODevice | |
enum | OpenModeFlag { Closed = 0x0 , ReadOnly = 0x1 , WriteOnly = 0x2 , ReadWrite = ReadOnly | WriteOnly } |
using | Ptr = std::shared_ptr<IODevice> |
using | WeakPtr = std::weak_ptr<IODevice> |
Public Types inherited from zyppng::Base | |
using | Ptr = std::shared_ptr<Base> |
using | WeakPtr = std::weak_ptr<Base> |
Public Member Functions | |
~Socket () override | |
void | close () override |
int64_t | bytesPending () const override |
SocketState | state () const |
bool | bind (const std::shared_ptr< SockAddr > &addr) |
bool | listen (int backlog=50) |
Ptr | accept () |
bool | setBlocking (const bool set=true) |
void | disconnect () |
void | abort () |
bool | connect (std::shared_ptr< SockAddr > addr) |
bool | waitForConnected (int timeout=-1) |
bool | waitForAllBytesWritten (int timeout=-1) |
bool | waitForReadyRead (uint channel, int timeout=-1) override |
int | nativeSocket () const |
int | releaseSocket () |
SocketError | lastError () const |
SignalProxy< void()> | sigIncomingConnection () |
SignalProxy< void()> | sigConnected () |
SignalProxy< void()> | sigDisconnected () |
SignalProxy< void(Socket::SocketError)> | sigError () |
Public Member Functions inherited from zyppng::IODevice | |
ZYPP_DECLARE_FLAGS (OpenMode, OpenModeFlag) | |
IODevice () | |
void | setReadChannel (uint channel) |
uint | currentReadChannel () const |
int | readChannelCount () const |
bool | canRead () const |
bool | canWrite () const |
bool | isOpen () const |
ByteArray | readAll () |
ByteArray | read (int64_t maxSize) |
int64_t | read (char *buf, int64_t maxSize) |
virtual ByteArray | readLine (const int64_t maxSize=0) |
virtual int64_t | bytesAvailable () const |
int64_t | readBufferCount () const |
bool | canReadLine () const |
ByteArray | readAll (uint channel) |
ByteArray | read (uint channel, int64_t maxSize) |
int64_t | read (uint channel, char *buf, int64_t maxSize) |
ByteArray | channelReadUntil (uint channel, const char delim, int64_t maxSize=0) |
ByteArray | channelReadLine (uint channel, int64_t maxSize=0) |
int64_t | channelReadLine (uint channel, char *buf, const int64_t maxSize) |
virtual int64_t | bytesAvailable (uint channel) const |
int64_t | readBufferCount (uint channel) const |
virtual int64_t | channelReadUntil (uint channel, char *buf, const char delimiter, const int64_t maxSize) |
bool | canReadLine (uint channel) const |
bool | canReadUntil (uint channel, const char delim) const |
int64_t | write (const ByteArray &data) |
int64_t | write (const char *data, int64_t len) |
bool | waitForReadyRead (int timeout) |
SignalProxy< void()> | sigReadyRead () |
SignalProxy< void(uint)> | sigChannelReadyRead () |
SignalProxy< void(int64_t)> | sigBytesWritten () |
SignalProxy< void()> | sigAllBytesWritten () |
SignalProxy< void(uint) > | sigReadChannelFinished () |
Public Member Functions inherited from zyppng::Base | |
Base () | |
virtual | ~Base () |
WeakPtr | parent () const |
void | addChild (const Base::Ptr &child) |
void | removeChild (const Ptr &child) |
const std::unordered_set< Ptr > & | children () const |
std::thread::id | threadId () const |
template<typename T> | |
std::vector< std::weak_ptr< T > > | findChildren () const |
template<typename T> | |
std::shared_ptr< T > | shared_this () const |
template<typename T> | |
std::shared_ptr< T > | shared_this () |
template<typename T> | |
std::weak_ptr< T > | weak_this () const |
template<typename T> | |
std::weak_ptr< T > | weak_this () |
template<typename SenderFunc, typename ReceiverFunc> | |
auto | connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc) |
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker> | |
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > | connectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers) |
Static Public Member Functions | |
static Ptr | create (int domain, int type, int protocol) |
static Ptr | fromSocket (int fd, SocketState state) |
Static Public Member Functions inherited from zyppng::Base | |
template<typename Obj, typename Functor> | |
static decltype(auto) | make_base_slot (Obj *o, Functor &&f) |
template<typename SenderFunc, typename ReceiverFunc> | |
static auto | connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc) |
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker> | |
static auto | connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers) |
Protected Member Functions | |
Socket (int domain, int type, int protocol) | |
int64_t | rawBytesAvailable (uint channel=0) const override |
int64_t | writeData (const char *data, int64_t count) override |
int64_t | readData (uint channel, char *buffer, int64_t bufsize) override |
void | readChannelChanged (uint channel) override |
Protected Member Functions inherited from zyppng::IODevice | |
IODevice (IODevicePrivate &d) | |
virtual bool | open (const OpenMode mode) |
void | setReadChannelCount (uint channels) |
void | finishReadChannel (uint channel) |
Protected Member Functions inherited from zyppng::Base | |
Base (BasePrivate &dd) |
Additional Inherited Members | |
Protected Attributes inherited from zyppng::Base | |
std::unique_ptr< BasePrivate > | d_ptr |
Combines Sockets with the zypp event loop. Generally every socket type that is supported by the socket(2) API should work, however currently only Unix Domain sockets are tested.
The useage pattern of this class is similar to the socket(2) API, on the server endpoint one listening socket is created and bound to a adress to accept incoming connections. For every appected connections a connected socket instance is returned which can be used for communication with the peer.
using zyppng::Socket::Ptr = std::shared_ptr<Socket> |
|
protected |
|
static |
|
overridevirtual |
Closed the socket and disconnects from the peer. The disconnected signal will be emitted. This is similar to calling disconnect.
Reimplemented from zyppng::IODevice.
|
overridevirtual |
Returns the current number of bytes that are not yet written to the socket.
Implements zyppng::IODevice.
Socket::SocketState zyppng::Socket::state | ( | ) | const |
Returns the current state the socket is in, check SocketState for possible values.
bool zyppng::Socket::listen | ( | int | backlog = 50 | ) |
Socket::Ptr zyppng::Socket::accept | ( | ) |
This will set the socket into blocking mode. Can be used if there is no EventLoop running. (Make sure a EventDispatcher instance exists for the thread)
void zyppng::Socket::disconnect | ( | ) |
Starts to disconnect from the host, wait for the actual sigDisconnected signal to arrive before destroying the socket otherwise the connection is forcefully aborted
void zyppng::Socket::abort | ( | ) |
Starts the connection process to the given adress in addr. Returns true on success, if false is returned the current state should be checked if the connection was simply delayed. In that case the state is ConnectingState and error is set to ConnectionDelayed and the socket still tries to connect.
bool zyppng::Socket::waitForConnected | ( | int | timeout = -1 | ) |
bool zyppng::Socket::waitForAllBytesWritten | ( | int | timeout = -1 | ) |
|
overridevirtual |
Blocks the current event loop to wait until there are bytes available to read from the device
Implements zyppng::IODevice.
int zyppng::Socket::nativeSocket | ( | ) | const |
int zyppng::Socket::releaseSocket | ( | ) |
This will release the current socket and instantly transition into ClosedState. All unwritten data in the buffers will be discarded, so consider to use waitForAllBytesWritten before you call this function.
Socket::SocketError zyppng::Socket::lastError | ( | ) | const |
SignalProxy< void()> zyppng::Socket::sigIncomingConnection | ( | ) |
SignalProxy< void()> zyppng::Socket::sigConnected | ( | ) |
SignalProxy< void()> zyppng::Socket::sigDisconnected | ( | ) |
Signal is emitted always when the socket was closed. In the signal handler it is still possible to read all pending data in the read buffer, which will be discarded right after emitting the signal.
SignalProxy< void(Socket::SocketError)> zyppng::Socket::sigError | ( | ) |
|
static |
|
overrideprotectedvirtual |
Implements zyppng::IODevice.
|
overrideprotectedvirtual |
Implements zyppng::IODevice.
|
overrideprotectedvirtual |
Implements zyppng::IODevice.
|
overrideprotectedvirtual |
Implements zyppng::IODevice.