int SocketClient::connectTimeOutForWin(SOCKET &connect_fd, const int &timeout, const sockaddr_in &server)
{
int error=-, len;
len = sizeof(int);
timeval tm;
fd_set set;
unsigned long ul = ; //设置为非阻塞模式 ioctlsocket(connect_fd,FIONBIO,&ul); bool ret = false;
if( connect(connect_fd, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -)
{
tm.tv_sec = timeout;
tm.tv_usec = ;
FD_ZERO(&set);
FD_SET(connect_fd, &set);
if( select(-, NULL, &set, NULL, &tm) > )
{ getsockopt(connect_fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len); if(error == ) ret = true;
else ret = false;
} else ret = false;
}
else ret = true;
ul = ; //设置为阻塞模式
ioctlsocket(connect_fd,FIONBIO,&ul); if(!ret){
closesocket(connect_fd);
// fprintf(stderr,"Connect server fail in WIN\n");
}
return ret;
}

windows网络编程之socket中的非阻塞connect()与getsockopt()

C connect实现Timeout效果(Windows)的更多相关文章

  1. C connect实现Timeout效果(Linux)

    C connect函数是阻塞的,现要实现非阻塞式的connect. int SocketClient::connectTimeOut(const int &connect_fd, const ...

  2. 记一次安装kolla遇到DockerException: Error while fetching server API version: Timeout value connect was Timeout的问题

    1)环境信息: docker版本:17.09,当docker的版本是12.06时,也会报这个错误 [root@localhost ~]# docker --version Docker version ...

  3. 解决InetAddress.isReachable(timeout)在windows xp始终返回false的bug

    笔者最近在做产品,其中一个环节用到ping测试主机是否在线. 开发环境:Windows 7 64bit+JDK1.8 x64 以下是检测主机是否在线,开发环境中测试通过 public static b ...

  4. adb connect 出现timeout的处理方式

    默认的timeout是5000ms毫秒,如果是断点调试的时候,经常会出现timeout, 所以修改这个值就不会出现timeout了, Eclipse下的设置位置: Window->Prefere ...

  5. Connect to a Windows PC from Ubuntu via Remote Desktop Connection

    http://www.7tutorials.com/connecting-windows-remote-desktop-ubuntu A useful feature of Windows is be ...

  6. Windows Phone 的控件倾斜效果

    原文:Windows Phone 的控件倾斜效果 Windows Phone 7的系统设置里,按钮都有一个点击倾斜的效果,但自己添加的控件就没有.但微软提供了这个效果的代码:TiltEffect MS ...

  7. 使用ubuntu远程连接windows, Connect to a Windows PC from Ubuntu via Remote Desktop Connection

    from: https://www.digitalcitizen.life/connecting-windows-remote-desktop-ubuntu NOTE: This tutorial w ...

  8. haproxy windows环境使用

    haproxy下载:http://pan.baidu.com/s/1miEvQUc 测试环境说明: ip地址 作用 开放端口 备注 nbproc 1 daemon defaults mode tcp ...

  9. kafka+windows+java+springboot中的配置

    1.百度kafka+zookeeper+windows配置 1.1  zookeeper配置 dataDir=/tmp/zookeeper # the port at which the client ...

随机推荐

  1. playframework 编译打包过程失败

    root@mytest:/data# play war p2p-master --exclude tmp:logs:test:eclipse -o /data/a/sp2p~ _ _ ~ _ __ | ...

  2. 老男孩python学习自修第十三天【md5加密】

    示例代码如下: hashlib_test.py #!/usr/bin/env python # _*_ coding:UTF-8 _*_ import hashlib def genPasswd(na ...

  3. js对json解析获取对应属性的值,JSON.stringify()和JSON.parse()

    JSON.stringify() 该方法,将一个JSON对象转化为字符串string JSON.parse() 该方法,将一个字符串转化为JSON对象object 对于JSON对象,获取其对应键值 可 ...

  4. fiddler 笔记-设置断点

    设置断点后,可以修改httprequest的任何信息包括:host,cookie或都表单中的数据 1 Fiddler--rules--Automatic Breakpoint --before Req ...

  5. jq的$.each()方法

    jq的$.each()方法: 语法:jQuery.each(object, [callback]) 回调函数拥有两个参数:第一个为对象的成员或数组的索引,第二个为对应变量或内容.如果需要退出 each ...

  6. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code

    Editor’s Note: The following is a guest post from Mustafa Mahmutović, a Microsoft Student Partner wh ...

  7. 【Tensorflow】Tensorflow入门教程

    基本使用 使用 TensorFlow, 你必须明白 TensorFlow: 使用图 (graph) 来表示计算任务. 在被称之为 会话 (Session) 的上下文 (context) 中执行图. 使 ...

  8. Hibernate中的Entity类之间的继承关系之一MappedSuperclass

    在hibernate中,Entity类可以继承Entity类或非Entity类.但是,关系数据库表之间不存在继承的关系.那么在Entity类之间的继承关系,在数据库表中如何表示呢? Hibernate ...

  9. P1164 小A点菜

    原题链接 https://www.luogu.org/problemnew/show/P1164 此题是一道简单的动规问题 才学两天不是很熟练,我苦思冥想看着题解终于想出来了. 主要的思路如下: 我们 ...

  10. 自定义chromium浏览器

    自定义chromium浏览器 来源  https://chaopeng.me/blog/2018/08/17/how-to-develop-full-homebrew-browser.html 最近有 ...