libzypp 17.37.17
socket_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14
15#ifndef ZYPPNG_IO_SOCKET_P_DEFINED
16#define ZYPPNG_IO_SOCKET_P_DEFINED
17
21#include <zypp-core/zyppng/base/Timer>
22#include "iodevice_p.h"
23
24#include <variant>
25
26namespace zyppng {
27
29 {
31 public:
32
33 SocketPrivate( int domain, int type, int protocol, Socket &p ) : IODevicePrivate(p),
34 _domain(domain),
35 _type( type ),
36 _protocol( protocol )
37 { }
38
39 static Socket::Ptr wrapSocket( int fd, int domain, int type, int protocol, Socket::SocketState state );
40
41 bool initSocket () ;
42 void setError ( Socket::SocketError error, std::string &&err, bool emit = true );
43 bool handleConnectError ( int error );
44
45 bool transition ( Socket::SocketState newState );
47
48 bool connectToHost ();
49 void onSocketActivated ( int ev );
50 void onSocketActivatedSlot ( const SocketNotifier &, int ev ) {
51 return onSocketActivated(ev);
52 }
53 int64_t rawBytesAvailable () const;
55 bool writePendingData ();
56
58 int _type;
60 std::shared_ptr<SockAddr> _targetAddr;
61
62 int _socket = -1;
63 bool _borrowedSocket = false;
64
65 //error handling
66 bool _emittedErr = false;
68 std::string _errorDesc;
69
70 //signals
75
76
77 struct InitialState {
78 static constexpr Socket::SocketState type() { return Socket::InitialState; }
79 };
80
90
98
105
113
114 struct ClosedState {
115 static constexpr Socket::SocketState type() { return Socket::ClosedState; }
116 };
117 std::variant< InitialState, ConnectingState, ConnectedState, ListeningState, ClosingState, ClosedState > _state = InitialState();
118 };
119
120}
121
122#endif
IODevicePrivate(IODevice &p)
Definition iodevice.cc:5
std::shared_ptr< SocketNotifier > Ptr
Socket::SocketState state() const
Definition socket.cc:413
static Socket::Ptr wrapSocket(int fd, int domain, int type, int protocol, Socket::SocketState state)
Definition socket.cc:418
std::string _errorDesc
Definition socket_p.h:68
std::variant< InitialState, ConnectingState, ConnectedState, ListeningState, ClosingState, ClosedState > _state
Definition socket_p.h:117
SocketPrivate(int domain, int type, int protocol, Socket &p)
Definition socket_p.h:33
bool transition(Socket::SocketState newState)
Definition socket.cc:72
int64_t rawBytesAvailable() const
Definition socket.cc:202
bool readRawBytesToBuffer()
Definition socket.cc:210
bool handleConnectError(int error)
Definition socket.cc:300
Signal< void()> _disconnected
Definition socket_p.h:74
void onSocketActivated(int ev)
Definition socket.cc:343
std::shared_ptr< SockAddr > _targetAddr
Definition socket_p.h:60
Signal< void()> _connected
Definition socket_p.h:73
void setError(Socket::SocketError error, std::string &&err, bool emit=true)
Definition socket.cc:60
void onSocketActivatedSlot(const SocketNotifier &, int ev)
Definition socket_p.h:50
Signal< void()> _incomingConnection
Definition socket_p.h:72
Signal< void(Socket::SocketError)> _sigError
Definition socket_p.h:71
Socket::SocketError _error
Definition socket_p.h:67
@ ConnectingState
Definition socket.h:64
std::shared_ptr< Socket > Ptr
Definition socket.h:71
std::shared_ptr< Timer > Ptr
Definition timer.h:51
static constexpr Socket::SocketState type()
Definition socket_p.h:115
static constexpr Socket::SocketState type()
Definition socket_p.h:107
ClosingState(IOBuffer &&writeBuffer)
Definition socket.cc:17
SocketNotifier::Ptr _socketNotifier
Definition socket_p.h:110
static constexpr Socket::SocketState type()
Definition socket_p.h:94
SocketNotifier::Ptr _socketNotifier
Definition socket_p.h:95
SocketNotifier::Ptr _connectNotifier
Definition socket_p.h:87
static constexpr Socket::SocketState type()
Definition socket_p.h:85
static constexpr Socket::SocketState type()
Definition socket_p.h:78
SocketNotifier::Ptr _socketNotifier
Definition socket_p.h:103
static constexpr Socket::SocketState type()
Definition socket_p.h:102
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:98