Qore Programming Language 1.19.2
Loading...
Searching...
No Matches
StreamPipe.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 StreamPipe.h
4
5 Qore Programming Language
6
7 Copyright (C) 2016 - 2023 Qore Technologies, s.r.o.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Note that the Qore library is released under a choice of three open-source
28 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29 information.
30*/
31
32#ifndef _QORE_STREAMPIPE_H
33#define _QORE_STREAMPIPE_H
34
35#include <stdint.h>
36#include "qore/InputStream.h"
37#include "qore/OutputStream.h"
38
45public:
46 DLLLOCAL StreamPipe(bool syncClose, int64 timeout, int64 bufferSize, ExceptionSink *xsink);
47 DLLLOCAL void reportError(const QoreHashNode* ex);
48 DLLLOCAL void rethrow(ExceptionSink *xsink);
49
50private:
51 QoreThreadLock mutex;
52 QoreCondition readCondVar;
53 QoreCondition writeCondVar;
54 std::vector<unsigned char> buffer;
55 bool broken;
56 bool outputClosed;
57 bool closeFinished;
58 int64 size;
59 int64 count;
60 int64 readPtr;
61 int64 timeout;
63
64 friend class PipeInputStream;
65 friend class PipeOutputStream;
66};
67
72public:
73 DLLLOCAL PipeInputStream(StreamPipe *pipe) : pipe(pipe) {
74 }
75
76 DLLLOCAL int64 read(void *ptr, int64 limit, ExceptionSink *xsink) override;
77 DLLLOCAL int64 peek(ExceptionSink *xsink) override;
78 DLLLOCAL void finishClose();
79 DLLLOCAL void reportError(const QoreHashNode* ex) { pipe->reportError(ex); }
80 DLLLOCAL virtual const char *getName() override {
81 return "PipeInputStream";
82 }
83
84protected:
86
87private:
89};
90
95public:
96 DLLLOCAL PipeOutputStream(StreamPipe *pipe) : pipe(pipe) {
97 }
98
99 DLLLOCAL void close(ExceptionSink* xsink) override;
100 DLLLOCAL void write(const void *ptr, int64 count, ExceptionSink *xsink) override;
101 DLLLOCAL void reportError(const QoreHashNode* ex) { pipe->reportError(ex); }
102 DLLLOCAL bool isClosed() override {
103 return false;
104 }
105 DLLLOCAL virtual const char *getName() override {
106 return "PipeInputStream";
107 }
108
109protected:
111
112private:
114};
115
116#endif // _QORE_STREAMPIPE_H
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
Interface for private data of input streams.
Definition: InputStream.h:44
Interface for private data of output streams.
Definition: OutputStream.h:44
Private data for the Qore::PipeInputStream class.
Definition: StreamPipe.h:71
virtual DLLLOCAL const char * getName() override
Returns the name of the class.
Definition: StreamPipe.h:80
DLLLOCAL int64 read(void *ptr, int64 limit, ExceptionSink *xsink) override
Reads up to `limit` bytes from the input stream.
DLLLOCAL int64 peek(ExceptionSink *xsink) override
Peeks the next byte from the input stream.
Private data for the Qore::PipeOutputStream class.
Definition: StreamPipe.h:94
DLLLOCAL bool isClosed() override
Returns true is the stream has been closed.
Definition: StreamPipe.h:102
DLLLOCAL void write(const void *ptr, int64 count, ExceptionSink *xsink) override
Writes bytes to the output stream.
virtual DLLLOCAL const char * getName() override
Returns the name of the class.
Definition: StreamPipe.h:105
DLLLOCAL void close(ExceptionSink *xsink) override
Flushes any buffered (unwritten) bytes, closes the output stream and releases resources.
a thread condition class implementing a wrapper for pthread_cond_t
Definition: QoreCondition.h:45
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:52
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:127
Private data for the Qore::StreamPipe class.
Definition: StreamPipe.h:44
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260