How to detect whether socket is still connected...
2014-07-19 22:07
330 查看
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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}
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
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 a module is managed code or not
- How to judge whether an array is empty?
- [转]How to tell whether your CPU is running in real mode or protected mode
- How To Check Whether Physical Standby is in Sync with the Primary or Not?
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC
- JavaScript: How to detect that the Internet Connection is foffline
- <boost -04>如何判断输入文件的类型在给定范围内?how to judge whether given file's extension is within list?
- How to determine whether a file is 32 bit or 64 bit
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- How to Check Whether API Server is up or Down
- How to detect when a list is scrolling (or not)
- how to know whether one string is english string
- Gets or sets whether drilling down to a page/chart/summary is enabled.
- How to detect if a thread owns a message queue in Windows
- Keyloggers: How they work and how to detect them
- How to detect which control caused postback
- Introduction to COM - What It Is and How to Use It.
- Kernel Korner - Why and How to Use Netlink Socket