📄 28.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://apue.dhs.org"><font face="黑体"><big><big>123</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center"> ● UNIX网络编程 (BM: clown) </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="index.htm">回到开始</a>][<a href="16.htm">上一层</a>][<a href="29.htm">下一篇</a>]
<hr><p align="left"><small>发信人: fion (fion), 信区: UNP <br>
标 题: unix socket faq (7) <br>
发信站: UNIX编程 (2001年07月07日09:48:28 星期六), 站内信件 <br>
<br>
6. Advanced Socket Programming <br>
<br>
6.1. How would I put my socket in non-blocking mode? <br>
From Andrew Gierth (andrew@erlenstar.demon.co.uk): <br>
Technically, fcntl(soc, F_SETFL, O_NONBLOCK) is incorrect since it <br>
clobbers all other file flags. Generally one gets away with it since <br>
the other flags (O_APPEND for example) don't really apply much to <br>
sockets. In a similarly rough vein, you would use fcntl(soc, F_SETFL, <br>
0) to go back to blocking mode. <br>
To do it right, use F_GETFL to get the current flags, set or clear the <br>
O_NONBLOCK flag, then use F_SETFL to set the flags. <br>
And yes, the flag can be changed either way at will. <br>
<br>
6.2. How can I put a timeout on connect()? <br>
Andrew Gierth (andrew@erlenstar.demon.co.uk) has outlined the <br>
following procedure for using select() with connect(), which will <br>
allow you to put a timeout on the connect() call: <br>
First, create the socket and put it into non-blocking mode, then call <br>
connect(). There are three possibilities: <br>
o connect succeeds: the connection has been successfully made (this <br>
usually only happens when connecting to the same machine) <br>
o connect fails: obvious <br>
o connect returns -1/EINPROGRESS. The connection attempt has begun, <br>
but not yet completed. <br>
If the connection succeeds: <br>
o the socket will select() as writable (and will also select as <br>
readable if data arrives) <br>
If the connection fails: <br>
o the socket will select as readable *and* writable, but either a <br>
read or write will return the error code from the connection <br>
attempt. Also, you can use getsockopt(SO_ERROR) to get the error <br>
status - but be careful; some systems return the error code in the <br>
result parameter of getsockopt(), but others (incorrectly) cause <br>
the getsockopt call itself to fail with the stored value as the <br>
error. <br>
Sample code that illustrates this can be found in the socket-faq <br>
examples, in the file connect.c. <br>
-- <br>
※ 来源:·UNIX编程 www.tiaozhan.com/unixbbs/·[FROM: 211.69.197.132] <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="16.htm">上一层</a>][<a href="29.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -