libzypp  17.35.12
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 
26 namespace 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 );
46  Socket::SocketState state () const;
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;
54  bool readRawBytesToBuffer ();
55  bool writePendingData ();
56 
57  int _domain;
58  int _type;
59  int _protocol;
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 
81  struct ConnectingState : public sigc::trackable {
83  ConnectingState() = default;
84 
85  static constexpr Socket::SocketState type() { return Socket::ConnectingState; }
86 
89  };
90 
91  struct ConnectedState : public sigc::trackable {
93  ConnectedState() = default;
94  static constexpr Socket::SocketState type() { return Socket::ConnectedState; }
97  };
98 
99  struct ListeningState : public sigc::trackable {
101  ListeningState() = default;
102  static constexpr Socket::SocketState type() { return Socket::ListeningState; }
104  };
105 
106  struct ClosingState {
107  static constexpr Socket::SocketState type() { return Socket::ClosingState; }
108  ClosingState( IOBuffer &&writeBuffer );
109 
112  };
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
std::shared_ptr< SockAddr > _targetAddr
Definition: socket_p.h:60
static constexpr Socket::SocketState type()
Definition: socket_p.h:85
std::string _errorDesc
Definition: socket_p.h:68
Signal< void(Socket::SocketError)> _sigError
Definition: socket_p.h:71
Socket::SocketState state() const
Definition: socket.cc:413
static constexpr Socket::SocketState type()
Definition: socket_p.h:78
std::shared_ptr< SocketNotifier > Ptr
SocketNotifier::Ptr _socketNotifier
Definition: socket_p.h:110
static constexpr Socket::SocketState type()
Definition: socket_p.h:115
SocketNotifier::Ptr _connectNotifier
Definition: socket_p.h:87
SocketNotifier::Ptr _socketNotifier
Definition: socket_p.h:95
std::shared_ptr< Socket > Ptr
Definition: socket.h:71
void onSocketActivated(int ev)
Definition: socket.cc:343
SocketPrivate(int domain, int type, int protocol, Socket &p)
Definition: socket_p.h:33
bool readRawBytesToBuffer()
Definition: socket.cc:210
Signal< void()> _connected
Definition: socket_p.h:73
SocketNotifier::Ptr _socketNotifier
Definition: socket_p.h:103
static constexpr Socket::SocketState type()
Definition: socket_p.h:94
ClosingState(IOBuffer &&writeBuffer)
Definition: socket.cc:17
int64_t rawBytesAvailable() const
Definition: socket.cc:202
std::shared_ptr< Timer > Ptr
Definition: timer.h:51
std::variant< InitialState, ConnectingState, ConnectedState, ListeningState, ClosingState, ClosedState > _state
Definition: socket_p.h:117
static Socket::Ptr wrapSocket(int fd, int domain, int type, int protocol, Socket::SocketState state)
Definition: socket.cc:418
void setError(Socket::SocketError error, std::string &&err, bool emit=true)
Definition: socket.cc:60
static constexpr Socket::SocketState type()
Definition: socket_p.h:107
Socket::SocketError _error
Definition: socket_p.h:67
Signal< void()> _incomingConnection
Definition: socket_p.h:72
bool transition(Socket::SocketState newState)
Definition: socket.cc:72
Signal< void()> _disconnected
Definition: socket_p.h:74
#define ZYPP_DECLARE_PUBLIC(Class)
Definition: zyppglobal.h:98
sigc::trackable trackable
Definition: signals.h:181
bool handleConnectError(int error)
Definition: socket.cc:300
bool writePendingData()
Definition: socket.cc:253
void onSocketActivatedSlot(const SocketNotifier &, int ev)
Definition: socket_p.h:50
static constexpr Socket::SocketState type()
Definition: socket_p.h:102