select标准输入句柄出错

luhaoting110 2015-07-18 11:12:14

为什么select标准输入句柄出错啊 ,日了够了
...全文
78 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
LubinLew 2015-07-18
  • 打赏
  • 举报
回复

#include <windows.h>
#include <iostream>
#include “winsock2.h”
#pragma comment(lib, "ws2_32.lib")


int main(void)
{
	char buf[10] = "";
	fd_set rdfds;
	struct timeval tv;
	int ret = 0;

	WSADATA wsa;
	WSAStartup(MAKEWORD(2, 2), &wsa);

	FD_ZERO(&rdfds);
	FD_SET(0, &rdfds);
	tv.tv_sec = 3;
	tv.tv_usec = 500;

	//A successful WSAStartup call must occur before using this function.
	ret = select(1, &rdfds, NULL, NULL, &tv);
	if (SOCKET_ERROR == ret)
	{// error occurred
		std::cout << "Error Code = "<< WSAGetLastError() << std::endl;
	}
	else if (0 == ret)
	{// the time limit expired

	}
	else //success
	{//ret = the total number of socket handles that are ready and contained in the fd_set structures
	}

	return 0;
}
运行结果: Error Code = 10038 //An operation was attempted on something that is not a socket. 说明windows下的select函数只能操作socket的文件描述符

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧