AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AAbstractSocket.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 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#include "AInet4Address.h"
   17#include "AUI/Common/AString.h"
   18
   23class API_AUI_NETWORK AAbstractSocket {
   24private:
   25    int mHandle = 0;
   26    AInet4Address mSelfAddress;
   27
   28protected:
   29    static AString getErrorString();
   30
   31    [[nodiscard]] inline int getHandle() const { return mHandle; }
   32
   33    static void handleError(const AString& message, int code);
   34
   35    AAbstractSocket(int handle, const AInet4Address& selfAddress) : mHandle(handle), mSelfAddress(selfAddress) {}
   36
   40    void init();
   41
   46    void bind(uint16_t bindingPort);
   47
   51    virtual int createSocket() = 0;
   52
   53public:
   54    AAbstractSocket();
   55    AAbstractSocket(const AAbstractSocket&) = delete;
   56
   57    virtual ~AAbstractSocket();
   58
   59    void close();
   60    void setTimeout(int secs);
   61
   62    const AInet4Address& getAddress() const { return mSelfAddress; }
   63};
void bind(uint16_t bindingPort)
Binds socket for port. Used for ATcpServerSocket and AUdpSocket.
virtual int createSocket()=0
Creates socket handle.
void init()
Initialise socket.
Represents an ipv4 address with port.
Definition AInet4Address.h:25
Represents a Unicode character string.
Definition AString.h:38