Files
CPP_Core/Socket_old/Socket_p.h
T
2026-06-16 10:56:40 +08:00

50 lines
1.0 KiB
C++

#ifndef SOCKET_P_H
#define SOCKET_P_H
#include "Socket.h"
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
namespace {
struct InitializeWinsock {
InitializeWinsock() {
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
std::cerr << "WSAStartup failed." << std::endl;
}
}
~InitializeWinsock() { WSACleanup(); }
} Temp;
} // namespace
namespace Psc {}
#define socklen_t int
#else
#include <arpa/inet.h>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <stdexcept>
#include <sys/select.h>
#include <sys/socket.h>
#include <unistd.h>
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
#define SOCKET_ERROR -1
#endif
namespace Psc::socket {
void log_error(BaseLogger *logger, const std::string &POS,
Psc::socket::Socket_FD fd, const std::string &MSG);
}
#define LOG_FD_ERROR(fd, MSG) log_error(socket_logger, LOG_POS, fd, MSG);
#define LOG_FD_Debug(fd, MSG) log_error(socket_logger, LOG_POS, fd, MSG);
#endif