VWeb/Includes/SocketManager.h

41 lines
953 B
C
Raw Normal View History

#pragma once
#include "Socket.h"
#include <netinet/in.h>
namespace VWeb {
class SocketUtils {
public:
static bool MakeAsync(int socketId);
static bool Add(int socketId);
static bool Close(int socketId);
static bool WriteDone(int socketId);
static WriteState Write(SendData &);
};
class ServerConfig;
class SocketManager {
public:
explicit SocketManager(const Ref<ServerConfig> &);
~SocketManager();
Accept Handle();
bool SetSendListen(int socketID);
bool SetReadListen(int socketID);
Ref<ServerConfig> &GetServerConfig() { return m_ServerConfig; }
[[nodiscard]] int ID() const { return m_SocketID; }
[[nodiscard]] bool IsErrored() const { return m_IsErrored; }
void Init();
protected:
void Errored(const std::string &data);
int m_SocketID{};
Ref<ServerConfig> m_ServerConfig{};
struct sockaddr_in m_Address {
0
};
int m_AddressLength{sizeof(m_Address)};
bool m_IsErrored{false};
};
} // namespace VWeb