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"
14#include "Stroika/Foundation/Streams/InternallySynchronizedInputOutputStream.h"
19using namespace Stroika::Foundation::Streams;
20using namespace Stroika::Foundation::IO;
26 class Rep_ :
public InputOutputStream::IRep<byte> {
28 bool fOpenForRead_{
true};
29 bool fOpenForWrite_{
true};
35 virtual bool IsSeekable ()
const override
39 virtual void CloseWrite ()
override
42 fSD_.
Shutdown (Socket::ShutdownTarget::eWrites);
43 if (not fOpenForRead_) {
47 fOpenForWrite_ =
false;
49 Ensure (not IsOpenWrite ());
51 virtual bool IsOpenWrite ()
const override
53 return fOpenForWrite_;
55 virtual void CloseRead ()
override
58 fSD_.Shutdown (Socket::ShutdownTarget::eReads);
59 if (not fOpenForWrite_) {
63 fOpenForRead_ =
false;
65 Ensure (not IsOpenRead ());
67 virtual bool IsOpenRead ()
const override
73 Require (IsOpenRead ());
74 return fReadSeekOffset_;
76 virtual optional<size_t> AvailableToRead ()
override
78 Require (IsOpenRead ());
79 return fSD_.AvailableToRead ();
81 virtual optional<SeekOffsetType> RemainingLength ()
override
83 Require (IsOpenRead ());
88 Require (IsOpenRead ());
89 optional<span<byte>> result;
91 case NoDataAvailableHandling::eBlockIfNoDataAvailable:
92 result = fSD_.Read (intoBuffer);
94 case NoDataAvailableHandling::eDontBlock: {
95 auto o = fSD_.ReadNonBlocking (intoBuffer);
97 Execution::Throw (EWouldBlock::kThe);
105 fReadSeekOffset_ += result->size ();
111 Require (IsOpenWrite ());
117 Require (IsOpenWrite ());
120 virtual void Write (span<const byte> elts)
override
122 Require (IsOpenWrite ());
125 virtual void Flush ()
override
127 Require (IsOpenWrite ());
143 return Ptr{make_shared<Rep_> (sd)};
148 switch (internallySynchronized) {
149 case Execution::eInternallySynchronized:
150 return InternallySynchronizedInputOutputStream::New<Rep_> ({}, sd);
151 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.