diff options
author | Arch Librarian <arch@canonical.com> | 2004-09-20 16:52:49 +0000 |
---|---|---|
committer | Arch Librarian <arch@canonical.com> | 2004-09-20 16:52:49 +0000 |
commit | cc2313b74cd33dd79e82c44cd9d3dbbefeb8092d (patch) | |
tree | 3a0c70817ced82646c0db884132d9f869a768ee2 /apt-pkg/contrib/fileutl.cc | |
parent | cdb970c74216a19194380ad657f44332c4aae5a3 (diff) |
modified WaitFd in fileutl to support passing a timeout
Author: doogie
Date: 1999-02-12 20:47:41 GMT
modified WaitFd in fileutl to support passing a timeout
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index f34d839e3..5b7c76496 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: fileutl.cc,v 1.19 1999/02/08 07:30:50 jgg Exp $ +// $Id: fileutl.cc,v 1.20 1999/02/12 20:47:41 doogie Exp $ /* ###################################################################### File Utilities @@ -24,6 +24,7 @@ #include <sys/stat.h> #include <sys/fcntl.h> #include <sys/types.h> +#include <sys/time.h> #include <errno.h> /*}}}*/ @@ -164,15 +165,21 @@ void SetNonBlock(int Fd,bool Block) // --------------------------------------------------------------------- /* This waits for a FD to become readable using select. It is usefull for applications making use of non-blocking sockets. */ -bool WaitFd(int Fd) +bool WaitFd(int Fd, bool write = false, long timeout = 0) { fd_set Set; + struct timeval tv; FD_ZERO(&Set); FD_SET(Fd,&Set); - - if (select(Fd+1,&Set,0,0,0) <= 0) - return false; - + tv.tv_sec = timeout / 1000000; + tv.tv_usec = timeout % 1000000; + if(write) { + if (select(Fd+1,&Set,0,0,&tv) <= 0) + return false; + } else { + if (select(Fd+1,0,&Set,0,&tv) <= 0) + return false; + } return true; } /*}}}*/ |