icinga2/lib/base/socket.hpp
Yonas Habteab 91c7e60df8 Replace all existing copyright headers with SPDX headers
I've used the following command to replace the original copyright header
lines in a C-style comment block:

```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```

For files that use shell-style comments (#) like CMakeLists.txt, I've
used this command:

```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```

And for SQL files:

```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
2026-02-04 14:00:05 +01:00

67 lines
1.3 KiB
C++

// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SOCKET_H
#define SOCKET_H
#include "base/i2-base.hpp"
#include "base/object.hpp"
#include <mutex>
namespace icinga
{
/**
* Base class for connection-oriented sockets.
*
* @ingroup base
*/
class Socket : public Object
{
public:
DECLARE_PTR_TYPEDEFS(Socket);
Socket() = default;
Socket(SOCKET fd);
~Socket() override;
SOCKET GetFD() const;
void Close();
std::pair<String, String> GetClientAddressDetails();
String GetClientAddress();
std::pair<String, String> GetPeerAddressDetails();
String GetPeerAddress();
size_t Read(void *buffer, size_t size);
size_t Write(const void *buffer, size_t size);
void Listen();
Socket::Ptr Accept();
bool Poll(bool read, bool write, struct timeval *timeout = nullptr);
void MakeNonBlocking();
static void SocketPair(SOCKET s[2]);
protected:
void SetFD(SOCKET fd);
int GetError() const;
mutable std::mutex m_SocketMutex;
private:
SOCKET m_FD{INVALID_SOCKET}; /**< The socket descriptor. */
static std::pair<String, String> GetDetailsFromSockaddr(sockaddr *address, socklen_t len);
static String GetHumanReadableAddress(const std::pair<String, String>& socketDetails);
};
class socket_error : virtual public std::exception, virtual public boost::exception { };
}
#endif /* SOCKET_H */