streams: fix mu_stream_wait operation for buffered streams
* libmailutils/stream/stream.c (mu_stream_wait): Fix condition to determine if the buffer contains some data. Avoid passing empty flags to the wait method.
Showing
1 changed file
with
9 additions
and
2 deletions
... | @@ -1147,7 +1147,7 @@ mu_stream_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) | ... | @@ -1147,7 +1147,7 @@ mu_stream_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) |
1147 | /* FIXME: How about MU_STREAM_READY_WR? */ | 1147 | /* FIXME: How about MU_STREAM_READY_WR? */ |
1148 | if ((*pflags) & MU_STREAM_READY_RD | 1148 | if ((*pflags) & MU_STREAM_READY_RD |
1149 | && stream->buftype != mu_buffer_none | 1149 | && stream->buftype != mu_buffer_none |
1150 | && stream->level > 0) | 1150 | && stream->pos < stream->level) |
1151 | { | 1151 | { |
1152 | flg = MU_STREAM_READY_RD; | 1152 | flg = MU_STREAM_READY_RD; |
1153 | *pflags &= ~MU_STREAM_READY_RD; | 1153 | *pflags &= ~MU_STREAM_READY_RD; |
... | @@ -1155,7 +1155,14 @@ mu_stream_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) | ... | @@ -1155,7 +1155,14 @@ mu_stream_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) |
1155 | 1155 | ||
1156 | if (stream->wait) | 1156 | if (stream->wait) |
1157 | { | 1157 | { |
1158 | int rc = stream->wait (stream, pflags, tvp); | 1158 | int rc; |
1159 | |||
1160 | if (flg && *pflags == 0) | ||
1161 | /* Don't call wait method if our modifications (see above) resulted | ||
1162 | in empty *pflags. */ | ||
1163 | rc = 0; | ||
1164 | else | ||
1165 | rc = stream->wait (stream, pflags, tvp); | ||
1159 | if (rc == 0) | 1166 | if (rc == 0) |
1160 | *pflags |= flg; | 1167 | *pflags |= flg; |
1161 | return rc; | 1168 | return rc; | ... | ... |
-
Please register or sign in to post a comment