nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

timeoutwrite.c (421B)


      1 #include "timeoutwrite.h"
      2 
      3 #include "select.h"
      4 #include "error.h"
      5 #include "readwrite.h"
      6 
      7 ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len)
      8 {
      9   fd_set wfds;
     10   struct timeval tv;
     11 
     12   tv.tv_sec = t;
     13   tv.tv_usec = 0;
     14 
     15   FD_ZERO(&wfds);
     16   FD_SET(fd,&wfds);
     17 
     18   if (select(fd + 1,NULL,&wfds,NULL,&tv) == -1) return -1;
     19   if (FD_ISSET(fd,&wfds)) return write(fd,buf,len);
     20 
     21   errno = error_timeout;
     22   return -1;
     23 }