1.1 --- a/libfsclient/lib/src/client.cc Thu Aug 05 01:28:41 2021 +0200
1.2 +++ b/libfsclient/lib/src/client.cc Thu Aug 05 01:29:59 2021 +0200
1.3 @@ -100,23 +100,43 @@
1.4
1.5
1.6
1.7 +/* Return whether an operation on file should block for more content or more
1.8 + space. */
1.9 +
1.10 +static int _operation_blocking(file_t *file, int reading)
1.11 +{
1.12 + return (file->can_block && (
1.13 + (reading && !file_data_available(file)) ||
1.14 + (!reading && !file_data_space(file))));
1.15 +}
1.16 +
1.17 +
1.18 +
1.19 /* Return whether an access could occur, blocking if necessary. */
1.20
1.21 -static int _access_blocking(file_t *file, offset_t position)
1.22 +static int _access_blocking(file_t *file, offset_t position, int reading)
1.23 {
1.24 long err;
1.25
1.26 - while ((err = _access(file, position)))
1.27 + /* Attempt to access the position, handling an error condition or a blocking
1.28 + condition. */
1.29 +
1.30 + while ((err = _access(file, position)) || _operation_blocking(file, reading))
1.31 {
1.32 /* Exit if blocking is not configured or suitable. */
1.33
1.34 - if ((err != -L4_EBUSY) || !file->can_block)
1.35 + if ((err && (err != -L4_EBUSY)) || !file->can_block)
1.36 return 0;
1.37
1.38 /* Handle an inability to access by blocking, exiting if waiting failed. */
1.39
1.40 if (client_wait_file(file))
1.41 return 0;
1.42 +
1.43 + /* Handle closure of the object. */
1.44 +
1.45 + if (file->notifications & NOTIFY_PEER_CLOSED)
1.46 + return 0;
1.47 }
1.48
1.49 return 1;
1.50 @@ -331,7 +351,7 @@
1.51 /* Flush any unwritten data, preparing to read from the file position at
1.52 the end of the data, and returning if no new data is available. */
1.53
1.54 - if (!_access_blocking(file, file_data_end_position(file)))
1.55 + if (!_access_blocking(file, file_data_end_position(file), 1))
1.56 break;
1.57
1.58 available = file_data_available(file);
1.59 @@ -560,7 +580,7 @@
1.60 /* Flush any unwritten data and continue writing from the current data
1.61 position. */
1.62
1.63 - if (!_access_blocking(file, file_data_current_position(file)))
1.64 + if (!_access_blocking(file, file_data_current_position(file), 0))
1.65 break;
1.66
1.67 space = file_data_space(file);