AuroraRuntime/Source/IO/Net/AuNetSocketServer.hpp

109 lines
3.3 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetSocketServer.hpp
Date: 2022-8-22
Author: Reece
***/
#pragma once
#include "AuNetSocket.hpp"
#if defined(AURORA_COMPILER_MSVC)
#pragma warning(disable: 4250)
#endif
#include "AuNetSocketServerLimits.hpp"
namespace Aurora::IO::Net
{
struct SocketServer;
struct SocketBase;
struct SocketServer : virtual Socket, virtual ISocketDriver, virtual ISocketServer
{
SocketServer(struct NetInterface *pInterface,
struct NetWorker *pWorker,
const AuSPtr<ISocketServerDriver> &pDriver,
const AuSPtr<ISocketDriverFactory> &pFactory,
AuUInt32 uMaxConnections,
AuUInt32 uDefaultInputStreamSize,
bool bMultiThreaded);
void Init(const NetEndpoint &localAddress);
void Listen(const NetEndpoint &localAddress, bool bBind = true, bool bListen = true);
void Accept();
AuSPtr<ISocketServerDriver> GetServerDriver() override;
AuSPtr<ISocketDriverFactory> GetFactory();
AuSPtr<ISocketServerLimits> GetLimits() override;
AuList<AuSPtr<ISocket>> GetChildren() override;
AuUInt32 GetSessionCount() override;
virtual void FinishConstructAsync() override;
virtual void Shutdown(bool bNow) override;
virtual void Destroy() override;
void ScheduleAcceptTick();
virtual void DoNonblockingReadTick() = 0;
virtual bool InitSocket(const NetEndpoint &localAddress) = 0;
virtual bool ImplBind() = 0;
virtual bool ImplListen() = 0;
virtual bool BeginAcceptLoop() = 0;
virtual void DetroyServer() = 0;
const bool bMultiThreaded;
const AuUInt32 uDefaultInputStreamSize;
AuUInt32 uBacklog { 512 };
protected:
// INTERFACE: base os socket
virtual bool PrepareConnectOperations() override;
virtual bool UpdateLocalEndpoint() override;
virtual bool UpdateRemoteEndpoint() override;
virtual bool TryBindAnyLocal() override;
virtual bool ConnectOverlapped() override;
virtual bool ConnectNonblocking() override;
virtual bool ConnectBlocking() override;
// INTERFACE: SOCKET DRIVER (for redirecting callbacks)
bool OnPreestablish(const AuSPtr<ISocket> &pInforming) override;
void OnEstablish() override;
virtual void OnStreamUpdated() override;
virtual void OnFatalErrorReported(const NetError &error) override;
virtual void OnEnd() override;
virtual void OnFinalize() override;
//
void OnNotifyChildCreated(SocketBase *pSocket);
void OnNotifyChildRemoved(SocketBase *pSocket);
private:
friend struct SocketBase;
AuSPtr<ISocketServerDriver> pDriver_;
AuUInt32 uMaxConnections_;
AuSPtr<ISocketDriverFactory> pFactory_;
NetSocketServerLimits serverLimits_;
AuMutex childrenMutex;
AuList<SocketBase *> childrenSockets;
};
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
#include "AuNetSocketServer.NT.hpp"
#else
#include "AuNetSocketServer.Unix.hpp"
#endif