Jamie Reece Wilson
2717178681
[+] INetInterface::SetWorkersService [+] INetInterface::SetResolveService [+] INetInterface::SetDatagramService [+] INetInterface::SetInterfacesService [*] Refactor: INetAdapter::GetStatus -> INetAdapter::GetAdapterStatus [*] Refactor: const NetError &ISocketBase::GetError() -> AuOptional<const NetError &> ISocketBase::GetError() [*] Refactor: INetAdapter to return const references of IPAddresses
165 lines
4.4 KiB
C++
165 lines
4.4 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuNetSocket.hpp
|
|
Date: 2022-8-16
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
#include "AuNetSocketChannel.hpp"
|
|
#include "AuNetSocketConnectOperation.hpp"
|
|
|
|
namespace Aurora::IO::FS
|
|
{
|
|
struct FileHandle;
|
|
}
|
|
|
|
namespace Aurora::IO::Net
|
|
{
|
|
struct NetInterface;
|
|
struct NetWorker;
|
|
struct SocketBase;
|
|
struct SocketConnectOperation;
|
|
struct SocketServerAcceptReadOperation;
|
|
struct SocketServer;
|
|
|
|
struct SocketBase : virtual ISocket, AuEnableSharedFromThis<SocketBase>
|
|
{
|
|
friend struct SocketServerAcceptReadOperation;
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
struct NetWorker *pWorker,
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
AuUInt osHandle,
|
|
AuSPtr<ISocketServer> pParent,
|
|
SocketServer *pParent2);
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
struct NetWorker *pWorker,
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
const NetEndpoint &endpoint);
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
struct NetWorker *pWorker,
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
const AuPair<NetHostname, AuUInt16> &endpoint,
|
|
AuNet::ETransportProtocol eProtocol);
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
struct NetWorker *pWorker,
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
const NetSocketConnectMany &connectMany);
|
|
|
|
virtual ~SocketBase();
|
|
|
|
bool TryStartResolve();
|
|
|
|
bool ConnectNext();
|
|
bool Connect(const NetEndpoint &endpoint);
|
|
|
|
AuUInt ToPlatformHandle() override;
|
|
|
|
AuSPtr<ISocketDriver> GetUserDriver() override;
|
|
|
|
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
|
|
|
const NetEndpoint &GetRemoteEndpoint() override;
|
|
const NetEndpoint &GetLocalEndpoint() override;
|
|
|
|
AuOptional<const NetError &> GetError() override;
|
|
|
|
AuSPtr<ISocketServer> GetSocketServer() override;
|
|
|
|
void ConnectFinished();
|
|
void ConnectFailed(const NetError &error);
|
|
|
|
void DoMain();
|
|
|
|
void SendErrorNoStream(const NetError &error);
|
|
void SendErrorBeginShutdown(const NetError &error);
|
|
void SendOnData();
|
|
|
|
void RejectAllListeners();
|
|
void CompleteAllListeners();
|
|
|
|
virtual AuSPtr<ISocketChannel> ToChannel() override;
|
|
|
|
|
|
virtual void Destroy() override;
|
|
|
|
void ShutdownLite();
|
|
|
|
INetWorker *ToWorker();
|
|
NetWorker *ToWorkerEx();
|
|
|
|
bool SendPreestablish(struct SocketServer *pServer = nullptr);
|
|
void SendEnd();
|
|
void SendFinalize();
|
|
|
|
bool IsValid();
|
|
|
|
SocketConnectOperation connectOperation;
|
|
|
|
virtual void UpdateNagleAnyThread(bool bDisableNagle) = 0;
|
|
|
|
virtual void FinishConstructAsync() = 0;
|
|
|
|
virtual bool PrepareConnectOperations() = 0;
|
|
|
|
virtual bool MakeNonblocking() = 0;
|
|
|
|
virtual bool UpdateLocalEndpoint() = 0;
|
|
virtual bool UpdateRemoteEndpoint() = 0;
|
|
|
|
virtual bool TryBindAnyLocal() = 0;
|
|
|
|
virtual bool ConnectOverlapped() = 0;
|
|
virtual bool ConnectNonblocking() = 0;
|
|
virtual bool ConnectBlocking() = 0;
|
|
|
|
virtual void CloseSocket() = 0;
|
|
virtual void RenewSocket() = 0;
|
|
|
|
AuUInt endpointSize_ {};
|
|
|
|
bool bHasFinalized_ {};
|
|
bool bHasEnded {};
|
|
bool bResolving_ {};
|
|
|
|
protected:
|
|
AuUInt osHandle_ {};
|
|
|
|
friend struct NetWriteQueue;
|
|
friend struct SocketChannelOutput;
|
|
friend struct SocketChannel;
|
|
|
|
NetEndpoint remoteEndpoint_;
|
|
NetEndpoint localEndpoint_;
|
|
AuWPtr<ISocketServer> wpParent_ {};
|
|
SocketServer *wpParent2_ {};
|
|
|
|
bool bForceFailConstruct_ {};
|
|
|
|
bool bHasRemoteMany_ {};
|
|
NetSocketConnectMany connectMany_;
|
|
NetWorker *pWorker_;
|
|
NetInterface *pInterface_;
|
|
SocketChannel socketChannel_;
|
|
AuSPtr<ISocketDriver> pSocketDriver_;
|
|
AuSPtr<IIOHandle> osHandleOwner_;
|
|
|
|
NetError error_;
|
|
|
|
bool bHasErrored_ {};
|
|
bool bHasConnected_ {};
|
|
bool bHasPreestablished_ {};
|
|
AuString resolveLater {};
|
|
};
|
|
}
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
#include "AuNetSocket.NT.hpp"
|
|
#else
|
|
#include "AuNetSocket.Unix.hpp"
|
|
#endif |