AuroraRuntime/Source/IO/Net/AuNetResolver.Unix.hpp

85 lines
2.1 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetResolver.Unix.hpp
Date: 2022-8-26
Author: Reece
***/
#pragma once
#include "AuNetSocketOverlappedOperation.hpp"
#include "AuNetSocket.hpp"
#if !defined(EAI_AGAIN)
#define EAI_AGAIN -3
#endif
#if !defined(EAI_MEMORY)
#define EAI_MEMORY -10
#endif
#if !defined(EAI_SYSTEM)
#define EAI_SYSTEM -11
#endif
struct glibc_aicb
{
const char * ar_name { };
const char * ar_service { };
const struct addrinfo *ar_request { };
struct addrinfo * ar_result { };
int reserved[10] { };
};
namespace Aurora::IO::Net
{
struct Socket;
struct ThreadLocalCaughtCompletion;
struct NetResolver :
SocketOverlappedOperation,
IResolver,
AuEnableSharedFromThis<NetResolver>
{
NetResolver(const AuSPtr<INetWorker> &pWorker);
NetResolver(const AuSPtr<INetWorker> &pWorker,
const AuSPtr<AuAsync::PromiseCallback<AuList<IPAddress>, NetError>> &pCompletion);
~NetResolver();
bool bA {};
bool bAAAA {};
AuString hostname;
bool Start();
bool StartStandard();
void SetCompletion(const AuSPtr<AuAsync::PromiseCallback<AuList<IPAddress>, NetError>> &callback);
void OnOverlappedComplete() override;
void OnOverlappedFailure(const NetError &error) override;
bool HasFinished() override;
void Cancel() override;
const NetError &GetError() override;
bool UnpackEarly();
bool Unpack();
AuSPtr<Loop::ILSEvent> pEvent;
private:
AuSPtr<INetWorker> pWorker_;
AuList<IPAddress> processedIps_;
AuSPtr<AuAsync::PromiseCallback<AuList<IPAddress>, NetError>> pCompletion_;
bool bHasCompleted_ {};
bool bHasUnpackedEarly {};
NetError error_;
addrinfo infoEx { };
bool bForceError_ {};
glibc_aicb gnuAsyncOperation {}; // freetarded
bool CheckAsync();
friend struct ThreadLocalCaughtCompletion;
};
void InitFreetardedResolver();
}