2022-08-28 19:02:06 +00:00
|
|
|
/***
|
|
|
|
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;
|
2023-11-29 13:55:01 +00:00
|
|
|
struct SocketServer;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
struct SocketBase : virtual ISocket, AuEnableSharedFromThis<SocketBase>
|
|
|
|
{
|
|
|
|
friend struct SocketServerAcceptReadOperation;
|
|
|
|
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
2023-11-29 13:55:01 +00:00
|
|
|
struct NetWorker *pWorker,
|
|
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
|
|
AuUInt osHandle,
|
|
|
|
AuSPtr<ISocketServer> pParent,
|
|
|
|
SocketServer *pParent2);
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
|
|
struct NetWorker *pWorker,
|
|
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
|
|
const NetEndpoint &endpoint);
|
|
|
|
|
2023-01-26 21:43:19 +00:00
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
|
|
struct NetWorker *pWorker,
|
|
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
|
|
const AuPair<NetHostname, AuUInt16> &endpoint,
|
|
|
|
AuNet::ETransportProtocol eProtocol);
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
SocketBase(struct NetInterface *pInterface,
|
|
|
|
struct NetWorker *pWorker,
|
|
|
|
const AuSPtr<ISocketDriver> &pSocketDriver,
|
|
|
|
const NetSocketConnectMany &connectMany);
|
|
|
|
|
|
|
|
virtual ~SocketBase();
|
|
|
|
|
2023-01-26 21:43:19 +00:00
|
|
|
bool TryStartResolve();
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
bool ConnectNext();
|
|
|
|
bool Connect(const NetEndpoint &endpoint);
|
|
|
|
|
|
|
|
AuUInt ToPlatformHandle() override;
|
|
|
|
|
|
|
|
AuSPtr<ISocketDriver> GetUserDriver() override;
|
|
|
|
|
2023-12-04 21:11:32 +00:00
|
|
|
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
2023-11-29 13:55:01 +00:00
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
const NetEndpoint &GetRemoteEndpoint() override;
|
|
|
|
const NetEndpoint &GetLocalEndpoint() override;
|
|
|
|
|
|
|
|
const NetError &GetError() override;
|
2023-11-29 13:55:01 +00:00
|
|
|
|
|
|
|
AuSPtr<ISocketServer> GetSocketServer() override;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
void ConnectFinished();
|
|
|
|
void ConnectFailed(const NetError &error);
|
|
|
|
|
|
|
|
void DoMain();
|
|
|
|
|
|
|
|
void SendErrorNoStream(const NetError &error);
|
|
|
|
void SendErrorBeginShutdown(const NetError &error);
|
|
|
|
void SendOnData();
|
|
|
|
|
2023-02-04 19:43:01 +00:00
|
|
|
void RejectAllListeners();
|
|
|
|
void CompleteAllListeners();
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
virtual AuSPtr<ISocketChannel> ToChannel() override;
|
|
|
|
|
|
|
|
|
|
|
|
virtual void Destroy() override;
|
|
|
|
|
|
|
|
void ShutdownLite();
|
|
|
|
|
|
|
|
INetWorker *ToWorker();
|
|
|
|
NetWorker *ToWorkerEx();
|
|
|
|
|
2022-12-16 17:18:12 +00:00
|
|
|
bool SendPreestablish(struct SocketServer *pServer = nullptr);
|
2022-08-28 19:02:06 +00:00
|
|
|
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;
|
2023-01-26 21:43:19 +00:00
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
virtual void CloseSocket() = 0;
|
2023-01-26 21:43:19 +00:00
|
|
|
virtual void RenewSocket() = 0;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
AuUInt endpointSize_ {};
|
|
|
|
|
|
|
|
bool bHasFinalized_ {};
|
2022-11-18 04:15:05 +00:00
|
|
|
bool bHasEnded {};
|
2023-01-26 21:43:19 +00:00
|
|
|
bool bResolving_ {};
|
2022-11-18 04:15:05 +00:00
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
protected:
|
2023-01-26 21:43:19 +00:00
|
|
|
AuUInt osHandle_ {};
|
2022-08-28 19:02:06 +00:00
|
|
|
|
2023-02-04 19:43:01 +00:00
|
|
|
friend struct NetWriteQueue;
|
|
|
|
friend struct SocketChannelOutput;
|
2023-12-01 14:49:30 +00:00
|
|
|
friend struct SocketChannel;
|
2023-02-04 19:43:01 +00:00
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
NetEndpoint remoteEndpoint_;
|
|
|
|
NetEndpoint localEndpoint_;
|
2023-11-29 13:55:01 +00:00
|
|
|
AuWPtr<ISocketServer> wpParent_ {};
|
|
|
|
SocketServer *wpParent2_ {};
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
bool bForceFailConstruct_ {};
|
|
|
|
|
|
|
|
bool bHasRemoteMany_ {};
|
|
|
|
NetSocketConnectMany connectMany_;
|
|
|
|
NetWorker *pWorker_;
|
|
|
|
NetInterface *pInterface_;
|
|
|
|
SocketChannel socketChannel_;
|
|
|
|
AuSPtr<ISocketDriver> pSocketDriver_;
|
2023-07-29 07:02:47 +00:00
|
|
|
AuSPtr<IIOHandle> osHandleOwner_;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
NetError error_;
|
|
|
|
|
|
|
|
bool bHasErrored_ {};
|
|
|
|
bool bHasConnected_ {};
|
2023-01-26 21:43:19 +00:00
|
|
|
bool bHasPreestablished_ {};
|
|
|
|
AuString resolveLater {};
|
2022-08-28 19:02:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
#include "AuNetSocket.NT.hpp"
|
|
|
|
#else
|
|
|
|
#include "AuNetSocket.Unix.hpp"
|
|
|
|
#endif
|