实现一个简单的windows TCP服务端
#include <iostream>
#include <chrono>
#include <thread>
#include <array>
#include <io.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
#define SO_OPENTYPE 0x7008
#define SO_SYNCHRONOUS_NONALERT 0x20
using socket_t = SOCKET;
using ssize_t = __int64;
#define DEFAULT_BUFLEN 2048
int main()
{
time_t read_timeout_sec_ = 1;
time_t read_timeout_usec_ = 1000;
time_t write_timeout_sec_ = 1;
time_t write_timeout_usec_ = 1000;
WSADATA wsaData;
WSAStartup(0x0002, &wsaData);
int opt = SO_SYNCHRONOUS_NONALERT;
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char*)&opt, sizeof(opt));
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
std::atomic<socket_t> svr_sock_ = INVALID_SOCKET;
struct addrinfo hints;
struct addrinfo* result;