1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/object.hpp"
8 #include <boost/thread/mutex.hpp>
14 * Base class for connection-oriented sockets.
18 class Socket : public Object
21 DECLARE_PTR_TYPEDEFS(Socket);
31 std::pair<String, String> GetClientAddressDetails();
32 String GetClientAddress();
33 std::pair<String, String> GetPeerAddressDetails();
34 String GetPeerAddress();
36 size_t Read(void *buffer, size_t size);
37 size_t Write(const void *buffer, size_t size);
42 bool Poll(bool read, bool write, struct timeval *timeout = nullptr);
44 void MakeNonBlocking();
46 static void SocketPair(SOCKET s[2]);
49 void SetFD(SOCKET fd);
53 mutable boost::mutex m_SocketMutex;
56 SOCKET m_FD{INVALID_SOCKET}; /**< The socket descriptor. */
58 static std::pair<String, String> GetDetailsFromSockaddr(sockaddr *address, socklen_t len);
59 static String GetHumanReadableAddress(const std::pair<String, String>& socketDetails);
62 class socket_error : virtual public std::exception, virtual public boost::exception { };