C connect实现Timeout效果(Windows)
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)的更多相关文章
- C connect实现Timeout效果(Linux)
C connect函数是阻塞的,现要实现非阻塞式的connect. int SocketClient::connectTimeOut(const int &connect_fd, const ...
- 记一次安装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 ...
- 解决InetAddress.isReachable(timeout)在windows xp始终返回false的bug
笔者最近在做产品,其中一个环节用到ping测试主机是否在线. 开发环境:Windows 7 64bit+JDK1.8 x64 以下是检测主机是否在线,开发环境中测试通过 public static b ...
- adb connect 出现timeout的处理方式
默认的timeout是5000ms毫秒,如果是断点调试的时候,经常会出现timeout, 所以修改这个值就不会出现timeout了, Eclipse下的设置位置: Window->Prefere ...
- 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 ...
- Windows Phone 的控件倾斜效果
原文:Windows Phone 的控件倾斜效果 Windows Phone 7的系统设置里,按钮都有一个点击倾斜的效果,但自己添加的控件就没有.但微软提供了这个效果的代码:TiltEffect MS ...
- 使用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 ...
- haproxy windows环境使用
haproxy下载:http://pan.baidu.com/s/1miEvQUc 测试环境说明: ip地址 作用 开放端口 备注 nbproc 1 daemon defaults mode tcp ...
- kafka+windows+java+springboot中的配置
1.百度kafka+zookeeper+windows配置 1.1 zookeeper配置 dataDir=/tmp/zookeeper # the port at which the client ...
随机推荐
- maven配置,jdk1.8
<!-- 局部jdk配置,pom.xml中 --> <build> <plugins> <plugin> <groupId>org.apac ...
- java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.jav
在整合spring和mybatis在执行数据库操作的时候报出了: java.lang.AbstractMethodError: org.mybatis.spring.transaction.Sprin ...
- ACM之路——上车了
校赛坚持到底,拿到了银牌:第一批进入ACM队集训,期末考试之前仍然代码不断,甚至感觉对不起大学第一次的期末考试,五天复习高数,两天复习英语,看到英语成绩是胸口突然好痛,好难受……就为了成为ACM正式队 ...
- sklearn训练感知器用iris数据集
简化版代码 from sklearn import datasets import numpy as np #获取data和类标 iris = datasets.load_iris() X = iri ...
- pysphere VMware控制模块的一些函数的说明
对于虚拟机的操作获得虚拟机对象 当你正常连接了服务器后,你就可以使用以下两种方式来得到虚拟机对象. get_vm_by_path get_vm_by_name 虚拟机路径可以从虚拟机右键信息中的”Ed ...
- Python中pandas模块解析
Pandas基于两种数据类型: series 与 dataframe . 1.Series 一个series是一个一维的数据类型,其中每一个元素都有一个标签.类似于Numpy中元素带标签的数组.其中, ...
- Marriage Match II HDU - 3081(二分权值建边)
题意: 有编号为1~n的女生和1~n的男生配对 首先输入m组,a,b表示编号为a的女生没有和编号为b的男生吵过架 然后输入f组,c,d表示编号为c的女生和编号为d的女生是朋友 进行配对的要求满足其一即 ...
- 白兔的刁难 IDFT
题目描述 给你\(n,k\),求 \[ \forall 0\leq t< k,s_t=\sum_{i=-t}^{n-t}[k|i]\binom{n}{i+t} \] 对\(998244353\) ...
- 【XSY2721】求和 杜教筛
题目描述 设\(n=\prod a_i^{p_i}\),那么定义\(f_d(n)=\prod{(-1)^{p_i}[p_i\leq d]}\).特别的,\(f_1(n)=\mu(n)\). 给你\(n ...
- MS-DOS 6.22 +Vim+masm 汇编环境
安装vim 个人习惯用 vim 编辑,因此稍微折腾了一下.不用这么麻烦直接用 edit 编辑也是可以的. 原来安装的 MS-DOS 7.10 虚拟机安装好vim后无法运行,所以改用了 MS-DOS 6 ...