#include <stddef.h>
Include dependency graph for readn.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
int | readn (int fd, void *vptr, int n, double timeout) |
|
Definition at line 50 of file readn.c. 00051 { 00052 int nleft, nread; 00053 char *ptr; 00054 double int_part; 00055 struct timeval timeout_tv; 00056 fd_set read_fd_set; 00057 timeout_tv.tv_sec = (long) _timeout; 00058 timeout_tv.tv_usec = (long) (_timeout * 1000000.0); 00059 if (timeout_tv.tv_usec >= 1000000) 00060 { 00061 timeout_tv.tv_usec = timeout_tv.tv_usec % 1000000; 00062 } 00063 FD_ZERO (&read_fd_set); 00064 RCS_FD_SET (fd, &read_fd_set); 00065 00066 00067 ptr = (char *) vptr; 00068 nleft = n; 00069 while (nleft > 0) 00070 { 00071 if (_timeout > 0.0) 00072 { 00073 switch (dl_select 00074 (fd + 1, &read_fd_set, (fd_set *) NULL, (fd_set *) NULL, 00075 &timeout_tv)) 00076 { 00077 case -1: 00078 rcs_print_error ("Error in select: %d -> %s\n", errno, 00079 strerror (errno)); 00080 return -1; 00081 00082 case 0: 00083 rcs_print_error ("Read timed out.\n"); 00084 return -1; 00085 00086 default: 00087 break; 00088 } 00089 } 00090 if ((nread = read (fd, ptr, nleft)) == -1) 00091 { 00092 rcs_print_error ("Read error: %d = %s\n", errno, strerror (errno)); 00093 return (-1); /* error, return < 0 */ 00094 } 00095 else if (nread == 0) 00096 { 00097 rcs_print_error ("readn: Premature EOF recieved.\n"); 00098 return (-1); 00099 } 00100 00101 nleft -= nread; 00102 ptr += nread; 00103 } 00104 return (n - nleft); /* return >= 0 */ 00105 } |