libzypp: zypp-core/ng/io/private/socket_p.h Source File

libzypp 17.38.14

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
18#include <zypp-core/ng/io/socket.h>
19#include <zypp-core/ng/io/private/iobuffer_p.h>
20#include <zypp-core/ng/base/socketnotifier.h>
21#include <zypp-core/ng/base/Timer>
22#include "iodevice_p.h"
23
24#include <variant>
25
26namespace zyppng {
27
28 class SocketPrivate : public IODevicePrivate
29 {
30 ZYPP_DECLARE_PUBLIC(Socket)
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;
67 Socket::SocketError _error = Socket::NoError;
68 std::string _errorDesc;
69
70 //signals
71 Signal< void(Socket::SocketError)> _sigError;
72 Signal< void()> _incomingConnection;
73 Signal< void()> _connected;
74 Signal< void()> _disconnected;
75
76
77 struct InitialState {
78 static constexpr Socket::SocketState type() { return Socket::InitialState; }
79 };
80
81 struct ConnectingState : public sigc::trackable {
82 NON_COPYABLE(ConnectingState);
83 ConnectingState() = default;
84
85 static constexpr Socket::SocketState type() { return Socket::ConnectingState; }
86
87 SocketNotifier::Ptr _connectNotifier;
88 Timer::Ptr _connectTimeout;
89 };
90
91 struct ConnectedState : public sigc::trackable {
92 NON_COPYABLE(ConnectedState);
93 ConnectedState() = default;
94 static constexpr Socket::SocketState type() { return Socket::ConnectedState; }
95 SocketNotifier::Ptr _socketNotifier;
96 IOBuffer _writeBuffer;
97 };
98
99 struct ListeningState : public sigc::trackable {
100 NON_COPYABLE(ListeningState);
101 ListeningState() = default;
102 static constexpr Socket::SocketState type() { return Socket::ListeningState; }
103 SocketNotifier::Ptr _socketNotifier;
104 };
105
106 struct ClosingState {
107 static constexpr Socket::SocketState type() { return Socket::ClosingState; }
108 ClosingState( IOBuffer &&writeBuffer );
109
110 SocketNotifier::Ptr _socketNotifier;
111 IOBuffer _writeBuffer;
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
zyppng::IOBuffer
Definition iobuffer_p.h:10
zyppng::IODevicePrivate::IODevicePrivate
IODevicePrivate(IODevice &p)
Definition iodevice.cc:5
zyppng::Signal
Definition signals.h:151
zyppng::SocketNotifier
Definition socketnotifier.h:69
zyppng::SocketNotifier::Ptr
std::shared_ptr< SocketNotifier > Ptr
Definition socketnotifier.h:73
zyppng::SocketPrivate::_type
int _type
Definition socket_p.h:58
zyppng::SocketPrivate::state
Socket::SocketState state() const
Definition socket.cc:413
zyppng::SocketPrivate::_domain
int _domain
Definition socket_p.h:57
zyppng::SocketPrivate::wrapSocket
static Socket::Ptr wrapSocket(int fd, int domain, int type, int protocol, Socket::SocketState state)
Definition socket.cc:418
zyppng::SocketPrivate::_errorDesc
std::string _errorDesc
Definition socket_p.h:68
zyppng::SocketPrivate::_protocol
int _protocol
Definition socket_p.h:59
zyppng::SocketPrivate::initSocket
bool initSocket()
Definition socket.cc:21
zyppng::SocketPrivate::_state
std::variant< InitialState, ConnectingState, ConnectedState, ListeningState, ClosingState, ClosedState > _state
Definition socket_p.h:117
zyppng::SocketPrivate::SocketPrivate
SocketPrivate(int domain, int type, int protocol, Socket &p)
Definition socket_p.h:33
zyppng::SocketPrivate::connectToHost
bool connectToHost()
Definition socket.cc:143
zyppng::SocketPrivate::transition
bool transition(Socket::SocketState newState)
Definition socket.cc:72
zyppng::SocketPrivate::rawBytesAvailable
int64_t rawBytesAvailable() const
Definition socket.cc:202
zyppng::SocketPrivate::readRawBytesToBuffer
bool readRawBytesToBuffer()
Definition socket.cc:210
zyppng::SocketPrivate::handleConnectError
bool handleConnectError(int error)
Definition socket.cc:300
zyppng::SocketPrivate::_disconnected
Signal< void()> _disconnected
Definition socket_p.h:74
zyppng::SocketPrivate::onSocketActivated
void onSocketActivated(int ev)
Definition socket.cc:343
zyppng::SocketPrivate::_targetAddr
std::shared_ptr< SockAddr > _targetAddr
Definition socket_p.h:60
zyppng::SocketPrivate::_connected
Signal< void()> _connected
Definition socket_p.h:73
zyppng::SocketPrivate::setError
void setError(Socket::SocketError error, std::string &&err, bool emit=true)
Definition socket.cc:60
zyppng::SocketPrivate::onSocketActivatedSlot
void onSocketActivatedSlot(const SocketNotifier &, int ev)
Definition socket_p.h:50
zyppng::SocketPrivate::writePendingData
bool writePendingData()
Definition socket.cc:253
zyppng::SocketPrivate::_socket
int _socket
Definition socket_p.h:62
zyppng::SocketPrivate::_incomingConnection
Signal< void()> _incomingConnection
Definition socket_p.h:72
zyppng::SocketPrivate::_borrowedSocket
bool _borrowedSocket
Definition socket_p.h:63
zyppng::SocketPrivate::_emittedErr
bool _emittedErr
Definition socket_p.h:66
zyppng::SocketPrivate::_sigError
Signal< void(Socket::SocketError)> _sigError
Definition socket_p.h:71
zyppng::SocketPrivate::_error
Socket::SocketError _error
Definition socket_p.h:67
zyppng::Socket
Definition socket.h:36
zyppng::Socket::SocketError
SocketError
Definition socket.h:40
zyppng::Socket::NoError
@ NoError
Definition socket.h:41
zyppng::Socket::SocketState
SocketState
Definition socket.h:62
zyppng::Socket::ConnectedState
@ ConnectedState
Definition socket.h:65
zyppng::Socket::ClosedState
@ ClosedState
Definition socket.h:68
zyppng::Socket::ConnectingState
@ ConnectingState
Definition socket.h:64
zyppng::Socket::InitialState
@ InitialState
Definition socket.h:63
zyppng::Socket::ListeningState
@ ListeningState
Definition socket.h:66
zyppng::Socket::ClosingState
@ ClosingState
Definition socket.h:67
zyppng::Socket::Ptr
std::shared_ptr< Socket > Ptr
Definition socket.h:71
zyppng::Timer::Ptr
std::shared_ptr< Timer > Ptr
Definition timer.h:51
iobuffer_p.h
iodevice_p.h
zyppng
Definition MediaNetworkRequestExecutor.h:16
socket.h
socketnotifier.h
zyppng::SocketPrivate::ClosedState
Definition socket_p.h:114
zyppng::SocketPrivate::ClosedState::type
static constexpr Socket::SocketState type()
Definition socket_p.h:115
zyppng::SocketPrivate::ClosingState::_writeBuffer
IOBuffer _writeBuffer
Definition socket_p.h:111
zyppng::SocketPrivate::ClosingState::type
static constexpr Socket::SocketState type()
Definition socket_p.h:107
zyppng::SocketPrivate::ClosingState::ClosingState
ClosingState(IOBuffer &&writeBuffer)
Definition socket.cc:17
zyppng::SocketPrivate::ClosingState::_socketNotifier
SocketNotifier::Ptr _socketNotifier
Definition socket_p.h:110
zyppng::SocketPrivate::ConnectedState::type
static constexpr Socket::SocketState type()
Definition socket_p.h:94
zyppng::SocketPrivate::ConnectedState::ConnectedState
ConnectedState()=default
zyppng::SocketPrivate::ConnectedState::NON_COPYABLE
NON_COPYABLE(ConnectedState)
zyppng::SocketPrivate::ConnectedState::_socketNotifier
SocketNotifier::Ptr _socketNotifier
Definition socket_p.h:95
zyppng::SocketPrivate::ConnectedState::_writeBuffer
IOBuffer _writeBuffer
Definition socket_p.h:96
zyppng::SocketPrivate::ConnectingState::_connectNotifier
SocketNotifier::Ptr _connectNotifier
Definition socket_p.h:87
zyppng::SocketPrivate::ConnectingState::NON_COPYABLE
NON_COPYABLE(ConnectingState)
zyppng::SocketPrivate::ConnectingState::_connectTimeout
Timer::Ptr _connectTimeout
Definition socket_p.h:88
zyppng::SocketPrivate::ConnectingState::ConnectingState
ConnectingState()=default
zyppng::SocketPrivate::ConnectingState::type
static constexpr Socket::SocketState type()
Definition socket_p.h:85
zyppng::SocketPrivate::InitialState
Definition socket_p.h:77
zyppng::SocketPrivate::InitialState::type
static constexpr Socket::SocketState type()
Definition socket_p.h:78
zyppng::SocketPrivate::ListeningState::ListeningState
ListeningState()=default
zyppng::SocketPrivate::ListeningState::NON_COPYABLE
NON_COPYABLE(ListeningState)
zyppng::SocketPrivate::ListeningState::_socketNotifier
SocketNotifier::Ptr _socketNotifier
Definition socket_p.h:103
zyppng::SocketPrivate::ListeningState::type
static constexpr Socket::SocketState type()
Definition socket_p.h:102
ZYPP_DECLARE_PUBLIC
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:91