#pragma once
#include "Common/Net/SocketCompat.h"
enum class SocketState {
Unused = 0,
UsedNetInet,
UsedProAdhoc,
};
const char *SocketStateToString(SocketState state);
struct InetSocket {
SOCKET sock;
SocketState state;
int domain;
int type;
int protocol;
bool nonblocking;
std::string addr;
int port;
};
class SocketManager {
public:
enum {
VALID_INET_SOCKET_COUNT = 256,
MIN_VALID_INET_SOCKET = 1,
};
InetSocket *CreateSocket(int *index, int *returned_errno, SocketState state, int domain, int type, int protocol);
InetSocket *AdoptSocket(int *index, SOCKET hostSocket, const InetSocket *derive);
bool GetInetSocket(int sock, InetSocket **inetSocket);
SOCKET GetHostSocketFromInetSocket(int sock);
bool Close(InetSocket *inetSocket);
void CloseAll();
const InetSocket *Sockets() {
return inetSockets_;
}
private:
InetSocket inetSockets_[VALID_INET_SOCKET_COUNT];
};
extern SocketManager g_socketManager;