头文件platform.h
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
//windows
#if defined(WIN32) || defined(WIN64)
#define WINDOWS_FAMILY
#pragma warning(disable : 4786)
#pragma warning(disable : 4996)
#endif
//c/c++
#include <stddef.h>
#include <errno.h>
#include <iostream>
#include <string>
#ifdef WINDOWS_FAMILY //Windows api
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#ifdef WINDOWS_FAMILY
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <string.h>
#include <typeinfo.h>
#include <tchar.h>
#endif
#else //Linux api
#include <sys/unistd.h>
#include <sys/socket.h>
#include <sys/unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#endif
typedef int net_ioctl_request_t;
#ifdef WINDOWS_FAMILY
#define NET_EWOULDBLOCK WSAEWOULDBLOCK
#define NET_ETIMEDOUT WSAETIMEDOUT
#define NET_INFINITE INFINITE
#define NET_SOCKET_ERROR SOCKET_ERROR
#define NET_NO_ERROR NO_ERROR
#define NET_INVALID_SOCKET INVALID_SOCKET
typedef __int64 int64;
typedef unsigned __int64 uint64;
typedef SOCKET net_socket_fd;
#else
#define NET_EWOULDBLOCK EWOULDBLOCK
#define NET_ETIMEDOUT EWOULDBLOCK
//#define NET_ETIMEDOUT ETIMEDOUT
#define NET_INFINITE 0xffffffff
#define NET_SOCKET_ERROR (-1)
#define NET_NO_ERROR 0
#define NET_INVALID_SOCKET (-1)
#define SD_SEND SHUT_RD
#define SD_RECEIVE SHUT_WR
#define SD_BOTH SHUT_RDWR
typedef int net_socket_fd;
typedef int BOOL;
typedef signed long long int64;
typedef unsigned long long uint64;
#endif
#endif
Linux下设置接收超时,超时后,返回的是EWOULDBLOCK。