Changeset 8 for trunk/src/slib.c
- Timestamp:
- Dec 31, 2005, 2:02:03 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/slib.c
r5 r8 566 566 void *sl_memset(void *s, int c, size_t n) 567 567 { 568 size_t i; 569 volatile char *p = s; 570 571 if (s == NULL || n <= 0) 572 return s; 573 574 for (i = 0; i < n; ++i) 575 p[i] = (char) c; 568 volatile char *p = (char *) s; 569 570 if (s != NULL) 571 { 572 while (n--) 573 *p++ = c; 574 } 576 575 return s; 577 576 } … … 1673 1672 fd = aud_open_noatime (FIL__, __LINE__, priv, filename, 1674 1673 O_RDONLY|O_NONBLOCK, 0, &o_noatime); 1674 /* 1675 1675 if (fd >= 0) { 1676 1676 sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0); 1677 1677 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags & ~O_NONBLOCK); 1678 1678 } 1679 */ 1679 1680 if (fd < 0) 1680 1681 SL_IRETURN(SL_EBADFILE, _("sl_open_file")); … … 2081 2082 } 2082 2083 2084 int sl_read_timeout_prep (SL_TICKET ticket) 2085 { 2086 int fd; 2087 int sflags; 2088 2089 SL_ENTER(_("sl_read_timeout_prep")); 2090 2091 if (SL_ISERROR(fd = get_the_fd(ticket))) 2092 { 2093 TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd)); 2094 SL_IRETURN(fd, _("sl_read_timeout_prep")); 2095 } 2096 2097 /* set to non-blocking mode 2098 */ 2099 sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0); 2100 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags | O_NONBLOCK); 2101 2102 SL_IRETURN(SL_ENONE, _("sl_read_timeout_prep")); 2103 } 2104 2083 2105 2084 2106 int sl_read_timeout (SL_TICKET ticket, void * buf_in, size_t count, … … 2087 2109 fd_set readfds; 2088 2110 struct timeval tv; 2089 int sflags;2111 /* int sflags; */ 2090 2112 int retval; 2091 2113 … … 2100 2122 extern volatile int sig_termfast; 2101 2123 2102 if (count < 1) 2103 { 2104 TPT(( 0, FIL__, __LINE__, _("msg=<range error>"))); 2105 return(SL_ERANGE); 2106 } 2107 if (buf_in == NULL) 2108 { 2109 TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>"))); 2110 return (SL_ENULL); 2111 } 2112 2113 if (SL_ISERROR(fd = get_the_fd(ticket))) 2114 { 2115 TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd)); 2116 return (fd); 2124 if (buf_in == NULL || SL_ISERROR(fd = get_the_fd(ticket))) 2125 { 2126 if (buf_in == NULL) 2127 { 2128 TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>"))); 2129 return (SL_ENULL); 2130 } 2131 if (SL_ISERROR(fd = get_the_fd(ticket))) 2132 { 2133 TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd)); 2134 return (fd); 2135 } 2117 2136 } 2118 2137 2119 2138 buf = (char *) buf_in; 2120 2121 /* set to non-blocking mode2122 */2123 sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);2124 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags | O_NONBLOCK);2125 2139 2126 2140 tstart = time(NULL); … … 2129 2143 while (count > 0) 2130 2144 { 2131 2132 if (sig_termfast == 1)2133 {2134 retry_fcntl(FIL__, __LINE__, fd, F_SETFL,2135 sflags & ~O_NONBLOCK);2136 return (SL_EREAD);2137 }2138 2139 2145 FD_ZERO(&readfds); 2140 2146 FD_SET(fd, &readfds); 2141 2142 if (tdiff >= timeout)2143 {2144 retry_fcntl(FIL__, __LINE__, fd, F_SETFL,2145 sflags & ~O_NONBLOCK);2146 return (SL_TIMEOUT);2147 }2148 2149 /*2150 tnow = time(NULL);2151 tdiff = tnow - tstart;2152 */2153 2147 2154 2148 tv.tv_sec = timeout - tdiff; … … 2160 2154 { 2161 2155 byteread = read (fd, buf, count); 2162 if (byteread != -1 && byteread != 0) 2156 2157 if (byteread > 0) 2163 2158 { 2164 2159 bytes += byteread; count -= byteread; … … 2182 2177 else 2183 2178 { 2184 retry_fcntl(FIL__, __LINE__, fd, F_SETFL,2185 sflags & ~O_NONBLOCK);2186 2179 return (SL_EREAD); 2187 2180 } … … 2197 2190 else if (retval == 0) 2198 2191 { 2199 retry_fcntl(FIL__, __LINE__, fd, F_SETFL,2200 sflags & ~O_NONBLOCK);2201 2192 return (SL_TIMEOUT); 2202 2193 } 2203 2194 else 2204 2195 { 2205 retry_fcntl(FIL__, __LINE__, fd, F_SETFL,2206 sflags & ~O_NONBLOCK);2207 2196 return (SL_EREAD); 2208 2197 } 2198 2199 if (sig_termfast == 1) 2200 { 2201 return (SL_EREAD); 2202 } 2203 2209 2204 tnow = time(NULL); 2210 2205 tdiff = tnow - tstart; 2211 } 2212 2213 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags & ~O_NONBLOCK); 2206 2207 if (tdiff > timeout) 2208 { 2209 return (SL_TIMEOUT); 2210 } 2211 } 2212 2214 2213 return ((int) bytes); 2215 2214 }
Note:
See TracChangeset
for help on using the changeset viewer.