How to detect whether socket is still connected...
How to detect whether socket is still connected…
*/-->
div.org-src-container {
font-size: 85%;
font-family: monospace;
}
pre.src {
background-color:#2e3436;
color:#fefffe;
}
p {font-size: 15px}
li {font-size: 15px}
From wget source code…
bool
test_socket_open (int sock)
{
fd_set check_set;
struct timeval to;
int ret = 0; /* Check if we still have a valid (non-EOF) connection. From Andrew
* Maholski's code in the Unix Socket FAQ. */ FD_ZERO (&check_set);
FD_SET (sock, &check_set); /* Wait one microsecond */
to.tv_sec = 0;
to.tv_usec = 1; ret = select (sock + 1, &check_set, NULL, NULL, &to);
#ifdef WINDOWS
/* gnulib select() converts blocking sockets to nonblocking in windows.
wget uses blocking sockets so we must convert them back to blocking
*/
set_windows_fd_as_blocking_socket ( sock );
#endif if ( !ret )
/* We got a timeout, it means we're still connected. */
return true;
else
/* Read now would not wait, it means we have either pending data
or EOF/error. */
return false;
}
(转载请注明出处,
使用许可:署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议 。)
How to detect whether socket is still connected...的更多相关文章
- Choregraphe 2.8.6.23虚拟Nao机器人Socket is not connected
Traceback (most recent call last): File "c:/Users/fengmao/OneDrive - University of Wollongong/J ...
- 不应该使用Connected属性作为Socket是否连接上的依据
最近在做一个接口,用到了Socket异步通信. 调试了3天了,一直将Socket的Connected属性作为客户端和服务器端是否连接上的依据.今天发现我错了. 下面是从一个csdn博友写的,很好. h ...
- Python Socket 网络编程
Socket 是进程间通信的一种方式,它与其他进程间通信的一个主要不同是:它能实现不同主机间的进程间通信,我们网络上各种各样的服务大多都是基于 Socket 来完成通信的,例如我们每天浏览网页.QQ ...
- C++Socket编程总结 [转]
使用socket写代码主要是要看自己的需求是什么. 如果通信时,内容很重要就要使TCP方式. 如果用户数太多,可能就要使用UDP方式了. 在TCP模式下,最简单的方式就是这样的,使阻塞方式: 服务端: ...
- 项目笔记---Socket Error Code翻译
前言 在项目中为了方便调试及客户反馈,需要Socket错误数字的中文解释,MSDN上只有英文版,同时也想自己学习而且方便将来更新ErrorCode的实际发生的情景,顾有此博文. MSDN:https: ...
- java网络编程socket解析
转载:http://www.blogjava.net/landon/archive/2013/07/02/401137.html Java网络编程精解笔记2:Socket详解 Socket用法详解 在 ...
- C# socket 实现消息中心向消息平台 转发消息 (修改)
using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using ...
- C# socket 实现消息中心向消息平台 转发消息
公司用到,直接粘代码了 using System; using System.Collections.Generic; using System.Configuration; using System ...
- linux socket中的SO_REUSEADDR
Welcome to the wonderful world of portability... or rather the lack of it. Before we start analyzing ...
随机推荐
- 并发批量管理500台以上服务器脚本分享(shell版)
转载于运维笔记 Categories:Shell 也许很多人认为shell不能并发任务,其实可通过其它一些方式来实现.下面的脚本是我批量快速管理500+服务器脚本,阅读该脚本前建议先看<自动执行 ...
- Hadoop生态圈-hbase介绍-伪分布式安装
Hadoop生态圈-hbase介绍-伪分布式安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HBase简介 HBase是一个分布式的,持久的,强一致性的存储系统,具有近似最 ...
- 详解 Cookie 纪要(vue.cookie,jquery.cookie简化)
今天看到一篇cookie的文章,写的特别详细,感谢 晚晴幽草轩 的分享,原文链接http://www.jeffjade.com/2016/10/31/115-summary-of-cookie/ 原文 ...
- Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C
http://codeforces.com/contest/965/problem/C 题目大意:n个糖,k个人,每次最多只能拿M个糖,从第一个人开始拿,可以循环D次.问Arkady最多可以拿几块糖? ...
- android获取APP 包名和activity
1.连接设备并启动被测试app应用 2.打开cmd窗口 3.windows获取包名和activity adb shell dumpsys activity |find "mFocuse ...
- Android SDK更新失败对策
Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml Failed to fetch URL https:// ...
- 同一个IIS绑定多个Htts 站点问题
默认情况一个服务器的IIS只能绑定一个HTTPS也就是443端口 要实现多个站点对应HTTPS只能更改IIS配置 地址:C:Windowssystem32inetsrvconfigapplicatio ...
- 一个简单的ns2实验全过程
实验名称:比较tcp和udp的丢包行为 试验目的:1. 熟练用ns2做网络仿真试验的整个流程:2. 练习写tcl脚本,了解怎么应用http和rtp:3. 练习用awk处理trace数据,了解怎么计算丢 ...
- 【清华集训 2017】小Y的地铁 [模拟退火]
小Y的地铁 Time Limit: 50 Sec Memory Limit: 256 MB Description Input Output 对于每组输入数据,输出一行一个整数,表示除掉这 n 个换 ...
- springboot+mybatis使用PageHelper分页
项目结构和spring搭建mybatis请参考springboot整合mybatis.在这个基础上配置分页. 一:导入PageHelper依赖 <dependency> <group ...