4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_Foundation_Common_Platform_Windows
8#elif qStroika_Foundation_Common_Platform_POSIX
13#include "Stroika/Foundation/Execution/OperationNotSupportedException.h"
15#include "Stroika/Foundation/Streams/InternallySynchronizedInputOutputStream.h"
20using namespace Stroika::Foundation::Streams;
21using namespace Stroika::Foundation::IO;
27 class Rep_ :
public InputOutputStream::IRep<byte> {
29 bool fOpenForRead_{
true};
30 bool fOpenForWrite_{
true};
36 virtual bool IsSeekable ()
const override
40 virtual void CloseWrite ()
override
43 fSD_.
Shutdown (Socket::ShutdownTarget::eWrites);
44 if (not fOpenForRead_) {
48 fOpenForWrite_ =
false;
50 Ensure (not IsOpenWrite ());
52 virtual bool IsOpenWrite ()
const override
54 return fOpenForWrite_;
56 virtual void CloseRead ()
override
59 fSD_.Shutdown (Socket::ShutdownTarget::eReads);
60 if (not fOpenForWrite_) {
64 fOpenForRead_ =
false;
66 Ensure (not IsOpenRead ());
68 virtual bool IsOpenRead ()
const override
74 Require (IsOpenRead ());
75 return fReadSeekOffset_;
77 virtual optional<size_t> AvailableToRead ()
override
79 Require (IsOpenRead ());
80 return fSD_.AvailableToRead ();
82 virtual optional<SeekOffsetType> RemainingLength ()
override
84 Require (IsOpenRead ());
89 Require (IsOpenRead ());
90 optional<span<byte>> result;
92 case NoDataAvailableHandling::eBlockIfNoDataAvailable:
93 result = fSD_.Read (intoBuffer);
95 case NoDataAvailableHandling::eDontBlock: {
96 auto o = fSD_.ReadNonBlocking (intoBuffer);
98 Execution::Throw (EWouldBlock::kThe);
106 fReadSeekOffset_ += result->size ();
112 Require (IsOpenWrite ());
118 Require (IsOpenWrite ());
121 virtual void Write (span<const byte> elts)
override
123 Require (IsOpenWrite ());
126 virtual void Flush ()
override
128 Require (IsOpenWrite ());
144 return Ptr{Memory::MakeSharedPtr<Rep_> (sd)};
149 switch (internallySynchronized) {
150 case Execution::eInternallySynchronized:
151 return InternallySynchronizedInputOutputStream::New<Rep_> ({}, sd);
152 case Execution::eNotKnownInternallySynchronized:
#define RequireNotReached()
NoDataAvailableHandling
If eDontBlock passed to most Stream APIs, then when the code would do a blocking read,...
int64_t SignedSeekOffsetType
nonvirtual void Shutdown(ShutdownTarget shutdownTarget=ShutdownTarget::eDEFAULT)
A Streams::Ptr<ELEMENT_TYPE> is a smart-pointer to a stream of elements of type T.