Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


The use of select

Learning to select, the following code found no obstruction.
Select one return. Please experts advise. There is a parameter, in the end should be described at best, or the number of descriptors.
[code]#include "Stdio.h>;
#include "Sys/time.h>;
#include "Sys/types.h>;
#include "Unistd.h>;
#include "Fcntl.h>;
Int
Main (void) (
Fd_set rfds;
Struct timeval tv;
Int retval;
Int czw, ling;

Czw=open ( "/home/czw/czw" O_RDONLY|O_NONBLOCK);
LEAVES OF 13 SPECIES OF LAURACEAE Watch stdin (fd 0) to see when it has input. */
FD_ZERO (&rfds);
FD_SET (czw, &rfds);


LEAVES OF 13 SPECIES OF LAURACEAE Wail up to five seconds. */
Tv.tv_sec = 100;
Tv.tv_usec = 0
Retval = select (czw+1, &rfds, NULL, NULL, &tv);
LEAVES OF 13 SPECIES OF LAURACEAE Don 't rely on the value of tv now! */
Printf ( "retval = %d\n" retval);
If (retval)
Printf ( "Data is available now.\n");
LEAVES OF 13 SPECIES OF LAURACEAE FD_ISSET (0, &rfds) will be true. */
Else
Printf ( "No data within five seconds.\n");
}[/code]

The use of select

1. Czw not 0 (STDIN)
2. 1 fd which is the largest increase in value, you can use a greater scale, white waste of time



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com