# HG changeset patch # User Paul Boddie # Date 1715345392 -7200 # Node ID bbb065eae48318fbae56af1ca5754ac73499918f # Parent 569d90054efef1a06c889ed019a5acdcbb0ab33e Added a synchronisation operation for streams when shared between programs. Currently, it only really makes sense for output streams. diff -r 569d90054efe -r bbb065eae483 libfsclient/include/fsclient/client.h --- a/libfsclient/include/fsclient/client.h Fri May 10 14:46:04 2024 +0200 +++ b/libfsclient/include/fsclient/client.h Fri May 10 14:49:52 2024 +0200 @@ -36,6 +36,7 @@ /* Stream access operations. */ file_t *client_get_stream(const char *name, flags_t flags); +long client_sync_stream(file_t *file); /* Opening and closing operations. */ diff -r 569d90054efe -r bbb065eae483 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Fri May 10 14:46:04 2024 +0200 +++ b/libfsclient/lib/src/client.cc Fri May 10 14:49:52 2024 +0200 @@ -140,12 +140,7 @@ else if (position == file->end_pos) { - err = client_next_region(file); - if (err) - return err; - - file->data_current = 0; - return L4_EOK; + return client_next_region(file); } /* Within the current pipe region, synchronise with the pipe object. */ @@ -283,10 +278,10 @@ stream->flags = flags; stream->ref = ref; - /* Test for pipe-based access, switching to memory mapped access if not - supported. */ + /* Synchronise the state of the stream, testing for pipe-based access and + switching to memory mapped access if not supported. */ - long err = client_current_region(stream); + long err = client_sync_stream(stream); if (err == -L4_EBADPROTO) stream->object_flags |= OBJECT_SUPPORTS_MMAP; @@ -310,6 +305,19 @@ return stream; } +/* Initialise the stream data position to the end of any existing data. */ + +long client_sync_stream(file_t *file) +{ + long err = client_current_region(file); + + if (err) + return err; + + file->data_current = file->data_end; + return err; +} + /* Open a filesystem object. */ @@ -608,7 +616,13 @@ if (!client_opened(file)) return -L4_EINVAL; - return pipe_next(file); + long err = pipe_next(file); + + if (err) + return err; + + file->data_current = 0; + return L4_EOK; }