为什么GetHostByName总是阻塞的
1个回答
展开全部
gethostbyname确实是阻塞的,但应该可以设置一个time_out免得DNS Server出问题时老是执行,关于设置Time_out,参阅一下code:
int timeout = TIMEOUT_VALUE;
int err;
SOCKET s;
s = socket( ... );
err = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
int timeout = TIMEOUT_VALUE;
int err;
SOCKET s;
s = socket( ... );
err = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询