AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AAbstractSocket.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <AUI/Network.h>
15
16
17
18#include "AInet4Address.h"
19#include "AUI/Common/AString.h"
20
25class API_AUI_NETWORK AAbstractSocket
26{
27private:
28 int mHandle = 0;
29 AInet4Address mSelfAddress;
30
31
32protected:
33 static AString getErrorString();
34
35 [[nodiscard]] inline int getHandle() const
36 {
37 return mHandle;
38 }
39
40 static void handleError(const AString& message, int code);
41
42
43 AAbstractSocket(int handle, const AInet4Address& selfAddress)
44 : mHandle(handle),
45 mSelfAddress(selfAddress)
46 {
47 }
48
52 void init();
53
58 void bind(uint16_t bindingPort);
59
60
64 virtual int createSocket() = 0;
65
66public:
68 AAbstractSocket(const AAbstractSocket&) = delete;
69
70 virtual ~AAbstractSocket();
71
72 void close();
73 void setTimeout(int secs);
74
75 const AInet4Address& getAddress() const {
76 return mSelfAddress;
77 }
78};
Base class for all sockets.
Definition: AAbstractSocket.h:26
virtual int createSocket()=0
Create socket handle. Use ::socket()
Represents an ipv4 address with port.
Definition: AInet4Address.h:25
Represents a Unicode character string.
Definition: AString.h:37