亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 0597-0599.html

?? linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
?? HTML
字號:


<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Network Programming</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311739 //-->

<!-- TITLE=RED HAT LINUX 2ND EDITION //-->

<!-- AUTHOR=DAVID PITTS ET AL //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS PUBLISHING //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=28 //-->

<!-- PAGES=0583-0604 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0593-0596.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0600-0602.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-597"><P>Page 597</P></A>













<P>Listing 28.9. nonblock.

</P>

<!-- CODE //-->

<PRE>1: #!/usr/bin/perl

2: use Socket;

3: use Fcntl;

4: require &quot;./network.pl&quot;;

5: $poke = &quot;yo!&quot;;

6: $NETFD = makeudpcli();

7: fcntl $NETFD, &amp;F_SETFL, O_NONBLOCK or die &quot;Fcntl failed : $!\n&quot;;

8: (rest of file remains the same)

</PRE>

<!-- END CODE //-->









<P>A new module, Fcntl, is added to the program in line 3, which provides an interface to

the fcntl(2) system call. It is used to alter file descriptor properties, such as blocking and how

it handles certain signals. In line 7, the last line of the modifications to

client2, you set the O_NONBLOCK flag for the UDP socket. The rest of the program is unchanged.

</P>









<P>When nonblocking I/O is used, the application designer has to be very careful when

handling errors returned from recv(), send(), and other I/O related functions. When no more data

is available for reading or no more data can be written, these functions return error codes. As

a result, the application has to be prepared to handle some errors as being routine

conditions. This is also true of the C/C++ interfaces.

</P>









<H3><A NAME="ch28_ 11">

I/O Multiplexing with UDP

</A></H3>









<P>Frequently, applications need to maintain more than one socket or file descriptor. For

example, many system services such as Telnet,

rlogin, and FTP are managed by one process on

Linux. In order to do this, the process, inetd, listens for requests for these services by opening a

socket for each one. Other applications, such as Applix, Netscape, and Xemacs, monitor file

descriptors for the keyboard, mouse, and perhaps the network.

</P>









<P>Let's set up an example that monitors the keyboard and a network connection. Listing

28.10 is contained in the file udptalk, which is included on the CD-ROM.

</P>









<P>Listing 28.10. updtalk.

</P>

<!-- CODE //-->

<PRE> 1: #!/usr/bin/perl

 2:

 3: use Socket;

 4: require &quot;./network.pl&quot;;

 5:

 6:  $NETFD = makeudpserv($ARGV[2]);

 7:

 8:  $addr = gethostbyname($ARGV[0]);

 9:  $port = getservbyname($ARGV[1], `udp');

10:

11:  $servaddr = sockaddr_in($port, $addr);

12:

13:  $rin = &quot;&quot;;

14:  vec($rin, fileno(STDIN), 1) = 1;

</PRE>

<!-- END CODE //-->







<PRE>

                                                 continues

</PRE>



<A NAME="PAGENUM-598"><P>Page 598</P></A>













<P>Listing 28.10. continued

</P>

<!-- CODE //-->

<PRE>15:  vec($rin, fileno($NETFD), 1) = 1;

16:

17:  while (1) {

18:

19:     select $ready = $rin, undef, undef, undef;

20:

21:     if (vec($ready, fileno(STDIN), 1) == 1) {

22:       sysread STDIN, $mesg, 256;

23:        send $NETFD, $mesg, 0, $servaddr;

24:     }

25:     if (vec($ready, fileno($NETFD), 1) == 1) {

26:         recv $NETFD, $netmsg, 256, 0;

27:        print &quot;$netmsg&quot;;

28:        $netmsg = &quot;&quot;;

29:     }

30: }

31:   close $NETFD;

</PRE>

<!-- END CODE //-->









<P>In order to test this program it must be run in either two windows on the same system or

on two different systems. At one command-line session, execute the following command,

where iest is the host on which the second command will be run:

</P>



<!-- CODE SNIP //-->

<PRE>$ ./udptalk iest test test1

</PRE>

<!-- END CODE SNIP //-->









<P>On the second host, run the following command, where

iest is the host where the first command was run:

</P>



<!-- CODE SNIP //-->

<PRE>$ ./udptalk iest test1 test

</PRE>

<!-- END CODE SNIP //-->









<P>Each session will wait for keyboard input. Each line that is typed at one program is printed

by the other, after you press Enter.

</P>









<P>In order to perform the two-way communication required for this exercise, both instances

of udptalk have to bind a well-known port. To permit this on a single workstation, the

program accepts two port names as the second and third command-line arguments. For obvious

reasons, two programs cannot register interest in the same port.

</P>









<P>In line 6 of Listing 28.10, udptalk uses

makeudpserv() to create a UDP socket and bind it to

a well-known port. For the examples here, I used 8000 for one copy and 8001 for the other.

</P>









<P>In lines 8_11, you perform the usual procedure for building a network address. This will

be the address to which the keyboard input is written.

</P>









<P>Lines 13_15 build bit vectors in preparation for the

select() function. In Perl, a bit vector is a scalar variable that is handled as an array of bits; in

other words, instead of being evaluated as bytes that add up to characters or numbers, each individual bit is evaluated as a distinct value.

</P>









<P>In line 13, you create a variable ($rin) and tell the Perl interpreter to clear it. You then use

the vec() and fileno() functions to determine the file number for

STDIN (the keyboard) and set

</P>



<A NAME="PAGENUM-599"><P>Page 599</P></A>













<P>that bit in $rin. Then you do the same for the socket created by

makeudpcli(). Therefore, if STDIN uses file descriptor 1 (which is generally the case), the second bit in

$rin is set to 1. (Bit vectors, like other arrays, start numbering indexes at zero.) Fortunately, the

vec() function can be used to read bit vectors also, so you can treat these data structures as opaque (and sleep a

lot better at night for not knowing the details).

</P>









<P>select() is a key function for systems programmers. Unfortunately, it suffers from an

arcane interface that is intimidating in any language. System V UNIX has a replacement,

poll(), that is a little easier to use, but it is not available on Linux or within Perl. The following is the

function description for select():

</P>



<!-- CODE SNIP //-->

<PRE>select readfds, writefds, exceptfds, timeout;

</PRE>

<!-- END CODE SNIP //-->









<P>Like most of the UNIX system interface, this is virtually identical to

select() in C/C++.<BR>

select() is used for discovering which file descriptors are ready for reading, are ready for

writing, or have an exceptional condition. An exceptional condition usually corresponds with

the arrival of what is called out-of-band or urgent data. This sort of data is most frequently

associated with TCP connections. When a message is sent out-of-band, it is tagged as being

more important than any previously sent data and is placed at the top of the data queue. A client

or server can use this to notify the process on the other end of a connection that it is

exiting immediately.

</P>









<P>The first three arguments are bit vectors that correspond to the file descriptors that you

are interested in reading or writing to or that you are monitoring for exceptional conditions.

If you aren't interested in a set of file descriptors, you can pass

undef instead of a vector. In Listing 28.10, you aren't interested in writing or exceptions, so you pass

undef for the second and third arguments.

</P>









<P>When select returns, only the bits that correspond to files with activity are set; if any

descriptors aren't ready when select returns, their settings are lost in the vector. For that reason,

you have select() create a new vector and copy it into

$ready. This is done by passing an assignment to

select() as the first argument in line 19.

</P>









<P>The last parameter is the time-out interval in seconds.

select() waits for activity for this period. If the period expires with no activity occurring,

select() will return with everything in the vector cleared. Because

undef is supplied for timeout in line 19, select() will block until

a file is ready.

</P>









<P>Inside the while loop entered in line 17, you call

select(), passing it the bit vector built earlier and the new one to be created. When it returns, you check the vector using

vec() with pretty much the same syntax as you used to set the bits; however because you are using

== instead of =, vec() returns the value of the bit instead of setting it.

</P>









<P>If the bit for STDIN is set, you read from the keyboard and send it to the other instance of

udptalk. If the bit for the socket is set, you read from it and print it to the terminal. This sequence

illustrates a very important advantage of the sockets interface. The program is extracting data

to and from the network using the same functions as the keyboard and screen.

</P>



<P><CENTER>

<a href="0593-0596.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0600-0602.html">Next</A>

</CENTER></P>









</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一本一道久久a久久精品| av电影一区二区| www.欧美色图| 日韩一区二区在线看| 欧美高清在线精品一区| 日韩和欧美的一区| 99精品在线观看视频| 日韩精品一区二区三区中文不卡| 国产精品美女久久福利网站| 老司机精品视频一区二区三区| 99精品在线观看视频| 国产欧美一区在线| 日韩av一二三| 欧美日韩免费一区二区三区 | 国产成人无遮挡在线视频| 欧美日韩在线免费视频| 亚洲欧洲制服丝袜| 成人污污视频在线观看| 欧美精品一区二区三区在线播放| 午夜精品福利一区二区三区蜜桃| 99re热这里只有精品视频| 欧美激情一区在线观看| 国产精品一区二区在线观看不卡| 91精品欧美久久久久久动漫 | 精品av久久707| 日韩 欧美一区二区三区| 欧美曰成人黄网| 日韩理论电影院| av中文字幕不卡| 国产精品九色蝌蚪自拍| 成人丝袜18视频在线观看| 国产日产欧美一区二区视频| 国产精品亚洲一区二区三区在线| 精品黑人一区二区三区久久| 麻豆视频观看网址久久| 制服丝袜av成人在线看| 日本免费在线视频不卡一不卡二| 5566中文字幕一区二区电影| 香蕉乱码成人久久天堂爱免费| 欧美三级三级三级爽爽爽| 亚洲一区二区偷拍精品| 欧美剧情片在线观看| 日韩av不卡一区二区| 3d动漫精品啪啪一区二区竹菊| 亚洲成a人片综合在线| 欧美日韩一区二区三区在线看| 午夜精品久久久久久久| 欧美zozo另类异族| 丁香六月综合激情| 亚洲一区精品在线| 欧美一区二区三区免费视频| 国内精品伊人久久久久影院对白| 久久久久久夜精品精品免费| 成人国产精品视频| 亚洲国产一区在线观看| 欧美一区二区国产| 丁香另类激情小说| 亚洲国产精品精华液网站| 日韩一区二区影院| 成人黄色777网| 天堂一区二区在线| 国产视频在线观看一区二区三区| 一本到高清视频免费精品| 日韩影视精彩在线| 亚洲国产成人一区二区三区| 欧美专区日韩专区| 韩国一区二区视频| 亚洲影视在线播放| 久久久久国产精品麻豆| 日本乱码高清不卡字幕| 久久99热这里只有精品| 亚洲人成精品久久久久久| 日韩一级精品视频在线观看| jlzzjlzz亚洲日本少妇| 老司机精品视频线观看86| 亚洲人成亚洲人成在线观看图片| 欧美一区二区三区视频免费播放| 不卡电影一区二区三区| 蜜乳av一区二区| 亚洲欧美偷拍另类a∨色屁股| 日韩午夜精品电影| 色综合久久久网| 国产剧情av麻豆香蕉精品| 午夜精品福利一区二区蜜股av| 国产欧美精品区一区二区三区| 欧美精品日韩一区| 91免费国产在线| 国产精品中文欧美| 蜜桃精品视频在线观看| 亚洲一区在线电影| 国产精品久久久一本精品| 2024国产精品| 欧美成人女星排名| 欧美日韩亚洲国产综合| 日本久久电影网| 91在线丨porny丨国产| 国产精品一区二区在线观看不卡 | 国产精品国产三级国产aⅴ入口 | 欧美日韩成人高清| 99在线精品免费| 成人午夜视频福利| 国产福利一区二区三区在线视频| 日韩成人一级大片| 亚洲成人先锋电影| 尤物av一区二区| 一区二区三区中文在线观看| 国产精品成人免费精品自在线观看 | 精品88久久久久88久久久 | 在线观看网站黄不卡| av电影在线观看一区| 9色porny自拍视频一区二区| www.色精品| 色婷婷狠狠综合| 在线免费不卡电影| 欧美中文字幕不卡| 精品视频在线看| 欧美肥妇free| 日韩女优制服丝袜电影| 日韩免费高清视频| 精品久久久网站| 国产亚洲综合av| 亚洲国产精华液网站w| 国产精品色一区二区三区| 中文字幕一区二区三区av| 亚洲日本一区二区| 一区二区三区四区不卡视频| 亚洲一区二区av在线| 婷婷激情综合网| 激情综合网最新| 成人免费三级在线| 91啪亚洲精品| 在线不卡欧美精品一区二区三区| 91精品免费观看| 久久久久国产精品人| 综合激情成人伊人| 亚洲一区二区三区四区在线| 日韩高清不卡一区二区| 麻豆视频一区二区| 成人黄色软件下载| 欧美日韩电影在线| 久久影院视频免费| 亚洲欧美日韩国产综合在线| 午夜电影一区二区三区| 狂野欧美性猛交blacked| 成人午夜视频网站| 欧美久久久久久久久久| 国产亚洲短视频| 亚洲综合色噜噜狠狠| 久久成人免费网| 91在线高清观看| 欧美不卡一二三| 亚洲欧美激情在线| 老司机精品视频线观看86| 不卡的av在线播放| 日韩欧美在线网站| 亚洲欧美日韩综合aⅴ视频| 日本美女视频一区二区| 成人av综合一区| 欧美一区二区三区播放老司机| 国产女主播视频一区二区| 亚洲电影欧美电影有声小说| 懂色av一区二区三区蜜臀| 69成人精品免费视频| 中文字幕一区二区三| 精品综合久久久久久8888| 91国产视频在线观看| 国产三区在线成人av| 视频一区欧美精品| 色综合天天综合给合国产| 精品国产免费久久| 亚洲成a人在线观看| 91亚洲精品久久久蜜桃网站| 久久综合狠狠综合久久综合88| 亚洲午夜精品17c| av一区二区久久| 国产人成一区二区三区影院| 日韩黄色免费网站| 精品国产一区二区三区久久久蜜月 | 色综合一区二区三区| 日本一区二区三区在线不卡| 免费在线观看精品| 欧美日韩精品电影| 亚洲人成网站影音先锋播放| 成人激情动漫在线观看| 久久久久久久综合| 极品少妇xxxx精品少妇偷拍| 日韩午夜av一区| 日本不卡视频一二三区| 在线观看网站黄不卡| 亚洲欧美精品午睡沙发| a4yy欧美一区二区三区| 国产精品视频观看| 国产+成+人+亚洲欧洲自线| 337p日本欧洲亚洲大胆精品| 毛片基地黄久久久久久天堂| 日韩亚洲欧美在线| 久久国产夜色精品鲁鲁99| 日韩免费观看2025年上映的电影| 免费观看在线色综合| 日韩欧美自拍偷拍|