(util_wait_input): New function.
Showing
1 changed file
with
33 additions
and
0 deletions
... | @@ -1125,6 +1125,39 @@ util_set_output (stream_t str) | ... | @@ -1125,6 +1125,39 @@ util_set_output (stream_t str) |
1125 | ostream = str; | 1125 | ostream = str; |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | /* Wait TIMEOUT seconds for data on the input stream. | ||
1129 | Returns 0 if no data available | ||
1130 | 1 if some data is available | ||
1131 | -1 an error occurred */ | ||
1132 | int | ||
1133 | util_wait_input (int timeout) | ||
1134 | { | ||
1135 | int rc, fd; | ||
1136 | fd_set rdset; | ||
1137 | |||
1138 | if (stream_get_fd (istream, &fd)) | ||
1139 | { | ||
1140 | errno = ENOSYS; | ||
1141 | return -1; | ||
1142 | } | ||
1143 | |||
1144 | FD_ZERO (&rdset); | ||
1145 | FD_SET (fd, &rdset); | ||
1146 | |||
1147 | do | ||
1148 | { | ||
1149 | struct timeval tv; | ||
1150 | |||
1151 | tv.tv_sec = timeout; | ||
1152 | tv.tv_usec = 0; | ||
1153 | |||
1154 | rc = select (fd + 1, &rdset, NULL, NULL, &tv); | ||
1155 | } | ||
1156 | while (rc == -1 && errno == EINTR); | ||
1157 | |||
1158 | return rc; | ||
1159 | } | ||
1160 | |||
1128 | void | 1161 | void |
1129 | util_flush_output () | 1162 | util_flush_output () |
1130 | { | 1163 | { | ... | ... |
-
Please register or sign in to post a comment