Author: doogie
Date: 1999-02-12 20:47:41 GMT
modified WaitFd in fileutl to support passing a timeout
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// -*- 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
/* ######################################################################
File Utilities
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <sys/types.h>
#include <errno.h>
/*}}}*/
#include <errno.h>
/*}}}*/
// ---------------------------------------------------------------------
/* This waits for a FD to become readable using select. It is usefull for
applications making use of non-blocking sockets. */
// ---------------------------------------------------------------------
/* 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 write = false, long timeout = 0)
FD_ZERO(&Set);
FD_SET(Fd,&Set);
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;
+ }
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.h,v 1.12 1999/01/18 06:20:08 jgg Exp $
+// $Id: fileutl.h,v 1.13 1999/02/12 20:47:41 doogie Exp $
/* ######################################################################
File Utilities
/* ######################################################################
File Utilities
string SafeGetCWD();
void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
string SafeGetCWD();
void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
+bool WaitFd(int Fd, bool write = false, long timeout = 0);
// File string manipulators
string flNotDir(string File);
// File string manipulators
string flNotDir(string File);