2022-08-28 19:02:06 +00:00
|
|
|
/***
|
|
|
|
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
|
|
|
|
|
2023-11-29 13:55:01 +00:00
|
|
|
#include "AuNetSocketServerLimits.hpp"
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
namespace Aurora::IO::Net
|
|
|
|
{
|
|
|
|
struct SocketServer;
|
2023-11-29 13:55:01 +00:00
|
|
|
struct SocketBase;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
struct SocketServer : virtual Socket, virtual ISocketDriver, virtual ISocketServer
|
|
|
|
{
|
|
|
|
SocketServer(struct NetInterface *pInterface,
|
|
|
|
struct NetWorker *pWorker,
|
|
|
|
const AuSPtr<ISocketServerDriver> &pDriver,
|
|
|
|
const AuSPtr<ISocketDriverFactory> &pFactory,
|
2022-12-16 17:18:12 +00:00
|
|
|
AuUInt32 uMaxConnections,
|
|
|
|
AuUInt32 uDefaultInputStreamSize,
|
2022-12-12 23:50:05 +00:00
|
|
|
bool bMultiThreaded);
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
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();
|
2023-11-29 13:55:01 +00:00
|
|
|
AuSPtr<ISocketServerLimits> GetLimits() override;
|
|
|
|
AuList<AuSPtr<ISocket>> GetChildren() override;
|
2023-11-30 02:40:30 +00:00
|
|
|
AuUInt32 GetSessionCount() override;
|
2023-12-01 14:49:30 +00:00
|
|
|
AuSPtr<ISocketStats> GetServerRecvStats() override;
|
|
|
|
AuSPtr<ISocketStats> GetServerSendStats() override;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
virtual void FinishConstructAsync() override;
|
|
|
|
|
2022-11-18 04:15:05 +00:00
|
|
|
virtual void Shutdown(bool bNow) override;
|
2022-08-28 19:02:06 +00:00
|
|
|
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;
|
2022-11-17 20:56:41 +00:00
|
|
|
|
2022-12-12 23:50:05 +00:00
|
|
|
const bool bMultiThreaded;
|
2022-12-16 17:18:12 +00:00
|
|
|
const AuUInt32 uDefaultInputStreamSize;
|
2023-11-29 13:55:01 +00:00
|
|
|
AuUInt32 uBacklog { 512 };
|
2022-08-28 19:02:06 +00:00
|
|
|
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;
|
|
|
|
|
2023-11-29 13:55:01 +00:00
|
|
|
//
|
|
|
|
void OnNotifyChildCreated(SocketBase *pSocket);
|
|
|
|
void OnNotifyChildRemoved(SocketBase *pSocket);
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
private:
|
2023-11-29 13:55:01 +00:00
|
|
|
friend struct SocketBase;
|
2023-12-01 14:49:30 +00:00
|
|
|
friend struct SocketChannel;
|
2023-11-29 13:55:01 +00:00
|
|
|
|
2023-12-01 14:49:30 +00:00
|
|
|
SocketStats sendStats_;
|
|
|
|
SocketStats recvStats_;
|
2022-08-28 19:02:06 +00:00
|
|
|
AuSPtr<ISocketServerDriver> pDriver_;
|
|
|
|
AuUInt32 uMaxConnections_;
|
|
|
|
AuSPtr<ISocketDriverFactory> pFactory_;
|
2023-11-29 13:55:01 +00:00
|
|
|
NetSocketServerLimits serverLimits_;
|
|
|
|
AuMutex childrenMutex;
|
|
|
|
AuList<SocketBase *> childrenSockets;
|
2022-08-28 19:02:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
#include "AuNetSocketServer.NT.hpp"
|
|
|
|
#else
|
|
|
|
#include "AuNetSocketServer.Unix.hpp"
|
|
|
|
#endif
|