155 lines
4.1 KiB
C++
155 lines
4.1 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 SocketBase : virtual ISocket, AuEnableSharedFromThis<SocketBase>
|
|
{
|
|
friend struct SocketServerAcceptReadOperation;
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
struct NetWorker *pWorker,
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
AuUInt osHandle);
|
|
|
|
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;
|
|
|
|
const NetEndpoint &GetRemoteEndpoint() override;
|
|
const NetEndpoint &GetLocalEndpoint() override;
|
|
|
|
const NetError &GetError() 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;
|
|
|
|
NetEndpoint remoteEndpoint_;
|
|
NetEndpoint localEndpoint_;
|
|
|
|
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 |