一个进程会有一个SOCKET资源列表
有如下代码
[cpp]
void TestSock()
{
WSADATA wsaData; // winsock 结构体
WORD wVersionRequested;// winsock 的版本
// 配置 Windows Socket版本
wVersionRequested = MAKEWORD( 2, 2 ); // 初始化 Windows Socket
WSAStartup( wVersionRequested, &wsaData );
map<int,int> map2;
for (int i = 0; i< CNT; i++)
{
SOCKET sockServer = socket(AF_INET, SOCK_STREAM, 0);
PRINT_LOG("%d,", sockServer);
map2.insert(make_pair(sockServer,0));
}
PRINT_LOG("\r\n-------------\r\n");
map<int,int>::reverse_iterator it = map2.rbegin();
while (it != map2.rend())
{
closesocket(it->first);
PRINT_LOG("%d,", it->first);
++it;
}
PRINT_LOG("\r\n-------------\r\n");
for (int i = 0; i< CNT; i++)
{
SOCKET sockServer = socket(AF_INET, SOCK_STREAM, 0);
PRINT_LOG("%d,", sockServer);
map2.insert(make_pair(sockServer,0));
}
PRINT_LOG("\r\n-------------\r\n");
}
输出
216,220,224,228,232,236,240,244,248,252,
-------------252,248,244,240,236,232,228,224,220,216,-------------216,220,224,228,232,236,240,244,248,252,-------------