95 lines
5.5 KiB
C++
95 lines
5.5 KiB
C++
|
/***
|
||
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||
|
|
||
|
File: BaseSocket.hpp
|
||
|
Date: 2022-2-1
|
||
|
Author: Reece
|
||
|
***/
|
||
|
#pragma once
|
||
|
|
||
|
#include "BaseChannel.hpp"
|
||
|
|
||
|
#include "PlatformSocket.hpp"
|
||
|
|
||
|
namespace Aurora::IO::Net
|
||
|
{
|
||
|
#define IMPLEMENT_IBASICSOCKET(access) \
|
||
|
bool GetLocalEndpoint(ConnectionEndpoint &out) override \
|
||
|
{ \
|
||
|
return access GetLocalEndpoint(out); \
|
||
|
} \
|
||
|
\
|
||
|
bool IsActive() override \
|
||
|
{ \
|
||
|
return access IsActive(); \
|
||
|
} \
|
||
|
Error_t GetLastError() override \
|
||
|
{ \
|
||
|
return access GetLastError(); \
|
||
|
} \
|
||
|
void Shutdown() override \
|
||
|
{ \
|
||
|
access Shutdown(); \
|
||
|
} \
|
||
|
AuSPtr<IBasicSocketPrivateContext> SetContext(const AuSPtr<IBasicSocketPrivateContext> &newContext) override \
|
||
|
{ \
|
||
|
return access SetContext(newContext); \
|
||
|
} \
|
||
|
AuSPtr<IBasicSocketPrivateContext> GetContext() override \
|
||
|
{ \
|
||
|
return access GetContext(); \
|
||
|
} \
|
||
|
SocketStat GetStats() override \
|
||
|
{ \
|
||
|
return access GetStats(); \
|
||
|
} \
|
||
|
EUnderlyingModel GetThreadModel() override \
|
||
|
{ \
|
||
|
return access GetThreadModel(); \
|
||
|
}
|
||
|
|
||
|
#define IMPLEMENT_IBASICSOCKETTHREADED(access) \
|
||
|
bool PumpRead() override \
|
||
|
{ \
|
||
|
return access PumpRead(); \
|
||
|
} \
|
||
|
bool PumpWrite() override \
|
||
|
{ \
|
||
|
return access PumpWrite(); \
|
||
|
} \
|
||
|
bool Pump() override \
|
||
|
{ \
|
||
|
return access Pump(); \
|
||
|
} \
|
||
|
void Run(int idx, AuUInt32 timeout) override \
|
||
|
{ \
|
||
|
access Run(idx, timeout); \
|
||
|
}
|
||
|
|
||
|
struct BaseSocket : public ISocket
|
||
|
{
|
||
|
BaseSocket() : channel_(this)
|
||
|
{}
|
||
|
|
||
|
PlatformSocket_t &ToPlatformSocket();
|
||
|
BaseChannel &ToChannel();
|
||
|
|
||
|
bool PumpRead() override;
|
||
|
bool PumpWrite() override;
|
||
|
bool Pump() override;
|
||
|
|
||
|
void Run(int idx, AuUInt32 timeout) override;
|
||
|
|
||
|
bool GetRemoteEndpoint(ConnectionEndpoint &out) override
|
||
|
{
|
||
|
return channel_.GetRemoteEndpoint(out);
|
||
|
}
|
||
|
|
||
|
IMPLEMENT_IBASICSOCKET(osSocket_.)
|
||
|
IMPLEMENT_PLATFORM_PROXY(channel_.)
|
||
|
private:
|
||
|
|
||
|
PlatformSocket_t osSocket_;
|
||
|
BaseChannel channel_;
|
||
|
};
|
||
|
}
|