Ver código fonte

Fixed WaitFD
Author: jgg
Date: 1999-02-16 04:18:35 GMT
Fixed WaitFD

Arch Librarian 22 anos atrás
pai
commit
1084d58ae9
2 arquivos alterados com 12 adições e 8 exclusões
  1. 10 6
      apt-pkg/contrib/fileutl.cc
  2. 2 2
      apt-pkg/contrib/fileutl.h

+ 10 - 6
apt-pkg/contrib/fileutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.cc,v 1.20 1999/02/12 20:47:41 doogie Exp $
+// $Id: fileutl.cc,v 1.21 1999/02/16 04:18:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -165,7 +165,7 @@ void SetNonBlock(int Fd,bool Block)
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This waits for a FD to become readable using select. It is usefull for
 /* This waits for a FD to become readable using select. It is usefull for
    applications making use of non-blocking sockets. */
    applications making use of non-blocking sockets. */
-bool WaitFd(int Fd, bool write = false, long timeout = 0)
+bool WaitFd(int Fd,bool write,unsigned long timeout)
 {
 {
    fd_set Set;
    fd_set Set;
    struct timeval tv;
    struct timeval tv;
@@ -173,13 +173,17 @@ bool WaitFd(int Fd, bool write = false, long timeout = 0)
    FD_SET(Fd,&Set);
    FD_SET(Fd,&Set);
    tv.tv_sec = timeout / 1000000;
    tv.tv_sec = timeout / 1000000;
    tv.tv_usec = timeout % 1000000;
    tv.tv_usec = timeout % 1000000;
-   if(write) {
-      if (select(Fd+1,&Set,0,0,&tv) <= 0)
+   if (write == true) 
+   {
+      if (select(Fd+1,0,&Set,0,(timeout != 0?&tv:0)) <= 0)
          return false;
          return false;
-   } else {
-      if (select(Fd+1,0,&Set,0,&tv) <= 0)
+   } 
+   else 
+   {
+      if (select(Fd+1,&Set,0,0,(timeout != 0?&tv:0)) <= 0)
          return false;
          return false;
    }
    }
+   
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 2 - 2
apt-pkg/contrib/fileutl.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.h,v 1.13 1999/02/12 20:47:41 doogie Exp $
+// $Id: fileutl.h,v 1.14 1999/02/16 04:18:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -66,7 +66,7 @@ bool FileExists(string File);
 string SafeGetCWD();
 string SafeGetCWD();
 void SetCloseExec(int Fd,bool Close);
 void SetCloseExec(int Fd,bool Close);
 void SetNonBlock(int Fd,bool Block);
 void SetNonBlock(int Fd,bool Block);
-bool WaitFd(int Fd, bool write = false, long timeout = 0);
+bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
 
 
 // File string manipulators
 // File string manipulators
 string flNotDir(string File);
 string flNotDir(string File);