libzypp  17.32.5
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;
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:663
static Ptr create(int domain, int type, int protocol)
Definition: socket.cc:456
bool listen(int backlog=50)
Definition: socket.cc:507
bool setBlocking(const bool set=true)
Definition: socket.cc:595
bool bind(const std::shared_ptr< SockAddr > &addr)
Definition: socket.cc:461
SignalProxy< void()> sigIncomingConnection()
Definition: socket.cc:870
void abort()
Definition: socket.cc:657
~Socket() override
Definition: socket.cc:451
bool waitForAllBytesWritten(int timeout=-1)
Definition: socket.cc:757
Ptr accept()
Definition: socket.cc:536
int nativeSocket() const
Definition: socket.cc:636
SignalProxy< void()> sigConnected()
Definition: socket.cc:875
int64_t readData(uint channel, char *buffer, int64_t bufsize) override
Definition: socket.cc:809
int64_t bytesPending() const
Definition: socket.cc:853
void readChannelChanged(uint channel) override
Definition: socket.cc:844
void disconnect()
Definition: socket.cc:668
SocketState state() const
Definition: socket.cc:865
static Ptr fromSocket(int fd, SocketState state)
Definition: socket.cc:562
int64_t writeData(const char *data, int64_t count) override
Definition: socket.cc:685
bool connect(std::shared_ptr< SockAddr > addr)
Definition: socket.cc:617
ZYPP_DECLARE_PRIVATE(Socket)
SignalProxy< void(Socket::SocketError)> sigError()
Definition: socket.cc:885
bool waitForConnected(int timeout=-1)
Definition: socket.cc:739
int64_t rawBytesAvailable(uint channel=0) const override
Definition: socket.cc:441
SocketError lastError() const
Definition: socket.cc:651
Socket(int domain, int type, int protocol)
Definition: socket.cc:437
bool waitForReadyRead(uint channel, int timeout=-1) override
Definition: socket.cc:790
int releaseSocket()
Definition: socket.cc:642
SignalProxy< void()> sigDisconnected()
Definition: socket.cc:880
std::shared_ptr< Base > Ptr
Definition: base.h:65