AuroraRuntime/Source/IO/Net/AuNetSocketServer.NT.cpp
Reece Wilson 67905a4192 [+] Network + Protocol + TLS - Initial Commit
=============================================================================
Network ]====================================================================
=============================================================================

[+] Added (very) early Aurora::IO::Net implementation
[+] AuNet::EHostnameType
[+] AuNet::EIPProtocol
[+] AuNet::ENetworkError
[+] AuNet::ETransportProtocol
[+] AuNet::INetInterface
[+] AuNet::INetSrvDatagram
[+] AuNet::INetSrvResolve
[+] AuNet::INetSrvSockets
[+] AuNet::INetSrvWorkers
[+] AuNet::INetWorker
[+] AuNet::IPAddress
[+] AuNet::IResolver
[+] AuNet::ISocket
[+] AuNet::IResolver
[+] AuNet::ISocketBase
[+] AuNet::ISocketChannel
[+] AuNet::ISocketDriver
[+] AuNet::ISocketDriverFactory
[+] AuNet::ISocketServer
[+] AuNet::ISocketServerDriver
[+] AuNet::NetEndpoint
[+] AuNet::NetError
[+] AuNet::NetHostname
(+implementation)

=============================================================================
Protocol ]===================================================================
=============================================================================

[+] IProtocolInterceptor
[+] IProtocolInterceptorEx
[+] IProtocolStack
(+implementation)

=============================================================================
TLS ]========================================================================
=============================================================================

[+] ITLSContext
[+] TLSProtocolRecv
[+] TLSProtocolSend
(+implementation)

=============================================================================
IO Bug Fixes ]===============================================================
=============================================================================

[*] IOProcessor::SubmitIOWorkItem should signal the CvEvent, forcing at least once future tick (wont optimize with if in tick & not yet dispatched work items)
[*] Split IOPipeWork in into IOPipeProcessor header
[+] IOPipeWork::GetBuffer (internal reallocation)
[*] Harden against IAsyncTransactions without a loop source
[*] Missing null `if (processor->listener)` in IOProcessor
[*] Solved some soft-lock conditions under Linux's LoopQueue (added deferred commits)
[*] Quick hack: IOProcessor::HasItems() should OR the early can-tick check function.

=============================================================================
Other ]======================================================================
=============================================================================

[+] Linux: LSSignalCatcher
[+] `static void AuResetMember(Aurora::Memory::ByteBuffer &ref)` for AuROXTL
[*] Attempt to enforce a normalization and don't overwrite-readptr-under-istreamwriters policy in ByteBuffer_ReadWrite (circular buffers)
[*] Bad ECC ctors

=============================================================================
Known issues ]===============================================================
=============================================================================

> Linux net is nowhere near done
> UDP socket emulation layer isn't implemented
> Ciphersuite API is a stub
> Private key API is a stub
> ...therefore no TLS servers
> Missing thread safety precautions under net
> Net implementation is still beri early
2022-08-28 20:02:06 +01:00

122 lines
3.7 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetSocketServer.NT.cpp
Date: 2022-8-22
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetSocketServer.hpp"
#include "AuNetError.hpp"
#include "AuNetEndpoint.hpp"
namespace Aurora::IO::Net
{
SocketServerImpl::SocketServerImpl(NetInterface *pInterface,
NetWorker *pWorker,
const AuSPtr<ISocketServerDriver> &pDriver,
const AuSPtr<ISocketDriverFactory> &pSocketDriverFactory,
AuUInt32 maxConnections) :
SocketServer(pInterface,
pWorker,
pDriver,
pSocketDriverFactory,
maxConnections),
Socket(pInterface,
pWorker,
AuSPtr<ISocketDriver>{},
-1),
acceptOperation_(pInterface, this),
pSocketDriverFactory_(pSocketDriverFactory)
{
}
void SocketServerImpl::DoNonblockingReadTick()
{
if (!this->acceptOperation_.DoTick())
{
SysPushErrorIO("Accept tick failed");
this->SendFinalize();
}
}
bool SocketServerImpl::InitSocket(const NetEndpoint &localAddress)
{
this->pSocketDriver_ = AuDynamicCast<SocketServerImpl>(this->SharedFromThis());
this->localEndpoint_ = localAddress;
if (!this->SendPreestablish())
{
SysPushErrorIO("Preestablish drop");
return false;
}
this->osHandle_ = ::WSASocketW(
IPToDomain(localAddress),
TransportToPlatformType(localAddress),
IPPROTO_IP,
nullptr,
0,
WSA_FLAG_OVERLAPPED
);
if (this->osHandle_ == -1)
{
NetError error;
NetError_SetCurrent(error);
this->SendErrorNoStream(error);
return false;
}
return true;
}
bool SocketServerImpl::ImplBind()
{
if (::bind(this->osHandle_,
(SOCKADDR *)this->localEndpoint_.hint, this->endpointSize_) != 0)
{
NetError error;
NetError_SetCurrent(error);
this->SendErrorNoStream(error);
return false;
}
return true;
}
bool SocketServerImpl::ImplListen()
{
/*
Picking 512 because....
"The maximum length of the queue of pending connections. If set to SOMAXCONN, the underlying service provider responsible for socket s
will set the backlog to a maximum reasonable value. If set to SOMAXCONN_HINT(N) (where N is a number), the backlog value will be N,
adjusted to be within the range (200, 65535). Note that SOMAXCONN_HINT can be used to set the backlog to a larger value than possible
with SOMAXCONN." - MSDN
"the backlog value will be N, adjusted to be within the range (200, 65535)." - MSDN
"If the backlog argument is greater than the value in /proc/sys/net/core/somaxconn, then it is silently capped to that value.
Since Linux 5.4, the default in this file is 4096" - da man pages
We need a sane number between the two. 512 seems reasonable
*/
if (::listen(this->osHandle_, 512) != 0)
{
NetError error;
NetError_SetCurrent(error);
this->SendErrorNoStream(error);
return false;
}
return true;
}
bool SocketServerImpl::BeginAcceptLoop()
{
return this->acceptOperation_.DoTick();
}
void SocketServerImpl::DetroyServer()
{
}
}