libzypp  17.35.12
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/zyppng/io/IODevice>
19 #include <zypp-core/zyppng/io/SockAddr>
20 #include <zypp-core/zyppng/base/Signals>
21 
22 namespace zyppng {
23 
24  class SocketPrivate;
25 
35  class Socket : public IODevice
36  {
38  public:
39 
40  enum SocketError {
60  };
61 
62  enum SocketState {
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 
190 
196 
204 
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 #endif
void close() override
Definition: socket.cc:665
static Ptr create(int domain, int type, int protocol)
Definition: socket.cc:458
bool listen(int backlog=50)
Definition: socket.cc:509
bool setBlocking(const bool set=true)
Definition: socket.cc:597
bool bind(const std::shared_ptr< SockAddr > &addr)
Definition: socket.cc:463
SignalProxy< void()> sigIncomingConnection()
Definition: socket.cc:872
void abort()
Definition: socket.cc:659
~Socket() override
Definition: socket.cc:453
bool waitForAllBytesWritten(int timeout=-1)
Definition: socket.cc:759
Ptr accept()
Definition: socket.cc:538
int nativeSocket() const
Definition: socket.cc:638
SignalProxy< void()> sigConnected()
Definition: socket.cc:877
int64_t readData(uint channel, char *buffer, int64_t bufsize) override
Definition: socket.cc:811
void readChannelChanged(uint channel) override
Definition: socket.cc:846
void disconnect()
Definition: socket.cc:670
SocketState state() const
Definition: socket.cc:867
static Ptr fromSocket(int fd, SocketState state)
Definition: socket.cc:564
int64_t writeData(const char *data, int64_t count) override
Definition: socket.cc:687
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:87
int64_t bytesPending() const override
Definition: socket.cc:855
bool connect(std::shared_ptr< SockAddr > addr)
Definition: socket.cc:619
SignalProxy< void(Socket::SocketError)> sigError()
Definition: socket.cc:887
bool waitForConnected(int timeout=-1)
Definition: socket.cc:741
int64_t rawBytesAvailable(uint channel=0) const override
Definition: socket.cc:443
SocketError lastError() const
Definition: socket.cc:653
Socket(int domain, int type, int protocol)
Definition: socket.cc:439
bool waitForReadyRead(uint channel, int timeout=-1) override
Definition: socket.cc:792
int releaseSocket()
Definition: socket.cc:644
SignalProxy< void()> sigDisconnected()
Definition: socket.cc:882
std::shared_ptr< Base > Ptr
Definition: base.h:65