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

libzypp 17.38.14

socket.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_DEFINED
16#define ZYPPNG_IO_SOCKET_DEFINED
17
18#include <zypp-core/ng/io/IODevice>
19#include <zypp-core/ng/io/SockAddr>
20#include <zypp-core/ng/base/Signals>
21
22namespace zyppng {
23
24 class SocketPrivate;
25
35 class Socket : public IODevice
36 {
37 ZYPP_DECLARE_PRIVATE(Socket)
38 public:
39
40 enum SocketError {
41 NoError,
42 UnknownSocketError,
43 InsufficientPermissions,
44 InvalidSocketOptions,
45 InsufficientRessources,
46 UnsupportedSocketOptions,
47 FailedSocketOperation,
48 SocketAlreadyBound,
49 SocketNotListening,
50 AddressInUse,
51 AddressNotAvailable,
52 AddressIssue,
53 OperationNotSupported,
54 ConnectionTimeout,
55 ConnectionDelayed,
56 ConnectionRefused,
57 ConnectionClosedByRemote,
58 NetworkUnreachable,
59 InternalError
60 };
61
62 enum SocketState {
63 InitialState,
64 ConnectingState,
65 ConnectedState,
66 ListeningState,
67 ClosingState,
68 ClosedState
69 };
70
71 using Ptr = std::shared_ptr<Socket>;
72
79 static Ptr create ( int domain, int type, int protocol );
80 ~Socket() override;
81
87 void close() override;
88
92 int64_t bytesPending() const override;
93
98 SocketState state () const;
99
103 bool bind ( const std::shared_ptr<SockAddr> &addr );
104
108 bool listen ( int backlog = 50 );
109
115 Ptr accept ();
116
121 bool setBlocking ( const bool set = true );
122
123
129 void disconnect ();
130
135 void abort ();
136
143 bool connect ( std::shared_ptr<SockAddr> addr );
144
149 bool waitForConnected ( int timeout = -1 );
150
157 bool waitForAllBytesWritten ( int timeout = -1 );
158
164 bool waitForReadyRead ( uint channel, int timeout = -1 ) override;
165
169 int nativeSocket () const;
170
178 int releaseSocket ();
179
183 SocketError lastError () const;
184
189 SignalProxy<void ()> sigIncomingConnection ();
190
195 SignalProxy<void ()> sigConnected ();
196
203 SignalProxy<void ()> sigDisconnected ();
204
209 SignalProxy<void (Socket::SocketError)> sigError ();
210
211
216 static Ptr fromSocket ( int fd, SocketState state );
217
218 protected:
219 Socket ( int domain, int type, int protocol );
220
221
222 // IODevice interface
223 protected:
224 int64_t rawBytesAvailable( uint channel = 0 ) const override;
225 int64_t writeData(const char *data, int64_t count) override;
226 int64_t readData( uint channel, char *buffer, int64_t bufsize ) override;
227 void readChannelChanged ( uint channel ) override;
228 };
229
230 ZYPP_FWD_DECL_REFS( Socket );
231
232}
233#endif
zyppng::Base::data
void * data(uint32_t quark)
Definition base.cc:82
zyppng::IODevice::IODevice
IODevice()
Definition iodevice.cc:10
zyppng::SignalProxy
Definition signals.h:325
zyppng::SocketPrivate
Definition socket_p.h:29
zyppng::Socket
Definition socket.h:36
zyppng::Socket::lastError
SocketError lastError() const
Definition socket.cc:653
zyppng::Socket::sigConnected
SignalProxy< void()> sigConnected()
Definition socket.cc:877
zyppng::Socket::abort
void abort()
Definition socket.cc:659
zyppng::Socket::close
void close() override
Definition socket.cc:665
zyppng::Socket::connect
bool connect(std::shared_ptr< SockAddr > addr)
Definition socket.cc:619
zyppng::Socket::fromSocket
static Ptr fromSocket(int fd, SocketState state)
Definition socket.cc:564
zyppng::Socket::SocketError
SocketError
Definition socket.h:40
zyppng::Socket::InternalError
@ InternalError
Definition socket.h:59
zyppng::Socket::ConnectionDelayed
@ ConnectionDelayed
Definition socket.h:55
zyppng::Socket::AddressNotAvailable
@ AddressNotAvailable
Definition socket.h:51
zyppng::Socket::UnknownSocketError
@ UnknownSocketError
Definition socket.h:42
zyppng::Socket::AddressInUse
@ AddressInUse
Definition socket.h:50
zyppng::Socket::NoError
@ NoError
Definition socket.h:41
zyppng::Socket::SocketNotListening
@ SocketNotListening
Definition socket.h:49
zyppng::Socket::AddressIssue
@ AddressIssue
Definition socket.h:52
zyppng::Socket::OperationNotSupported
@ OperationNotSupported
Definition socket.h:53
zyppng::Socket::ConnectionRefused
@ ConnectionRefused
Definition socket.h:56
zyppng::Socket::UnsupportedSocketOptions
@ UnsupportedSocketOptions
Definition socket.h:46
zyppng::Socket::InsufficientRessources
@ InsufficientRessources
Definition socket.h:45
zyppng::Socket::InsufficientPermissions
@ InsufficientPermissions
Definition socket.h:43
zyppng::Socket::InvalidSocketOptions
@ InvalidSocketOptions
Definition socket.h:44
zyppng::Socket::ConnectionTimeout
@ ConnectionTimeout
Definition socket.h:54
zyppng::Socket::SocketAlreadyBound
@ SocketAlreadyBound
Definition socket.h:48
zyppng::Socket::NetworkUnreachable
@ NetworkUnreachable
Definition socket.h:58
zyppng::Socket::FailedSocketOperation
@ FailedSocketOperation
Definition socket.h:47
zyppng::Socket::ConnectionClosedByRemote
@ ConnectionClosedByRemote
Definition socket.h:57
zyppng::Socket::readChannelChanged
void readChannelChanged(uint channel) override
Definition socket.cc:846
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::waitForReadyRead
bool waitForReadyRead(uint channel, int timeout=-1) override
Definition socket.cc:792
zyppng::Socket::nativeSocket
int nativeSocket() const
Definition socket.cc:638
zyppng::Socket::disconnect
void disconnect()
Definition socket.cc:670
zyppng::Socket::releaseSocket
int releaseSocket()
Definition socket.cc:644
zyppng::Socket::create
static Ptr create(int domain, int type, int protocol)
Definition socket.cc:458
zyppng::Socket::sigDisconnected
SignalProxy< void()> sigDisconnected()
Definition socket.cc:882
zyppng::Socket::sigIncomingConnection
SignalProxy< void()> sigIncomingConnection()
Definition socket.cc:872
zyppng::Socket::waitForAllBytesWritten
bool waitForAllBytesWritten(int timeout=-1)
Definition socket.cc:759
zyppng::Socket::listen
bool listen(int backlog=50)
Definition socket.cc:509
zyppng::Socket::sigError
SignalProxy< void(Socket::SocketError)> sigError()
Definition socket.cc:887
zyppng::Socket::Socket
Socket(int domain, int type, int protocol)
Definition socket.cc:439
zyppng::Socket::setBlocking
bool setBlocking(const bool set=true)
Definition socket.cc:597
zyppng::Socket::writeData
int64_t writeData(const char *data, int64_t count) override
Definition socket.cc:687
zyppng::Socket::accept
Ptr accept()
Definition socket.cc:538
zyppng::Socket::bytesPending
int64_t bytesPending() const override
Definition socket.cc:855
zyppng::Socket::~Socket
~Socket() override
Definition socket.cc:453
zyppng::Socket::waitForConnected
bool waitForConnected(int timeout=-1)
Definition socket.cc:741
zyppng::Socket::Ptr
std::shared_ptr< Socket > Ptr
Definition socket.h:71
zyppng::Socket::bind
bool bind(const std::shared_ptr< SockAddr > &addr)
Definition socket.cc:463
zyppng::Socket::readData
int64_t readData(uint channel, char *buffer, int64_t bufsize) override
Definition socket.cc:811
zyppng::Socket::rawBytesAvailable
int64_t rawBytesAvailable(uint channel=0) const override
Definition socket.cc:443
zyppng::Socket::state
SocketState state() const
Definition socket.cc:867
zyppng
Definition MediaNetworkRequestExecutor.h:16
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:80
ZYPP_FWD_DECL_REFS
#define ZYPP_FWD_DECL_REFS(T)
Definition zyppglobal.h:112