25#ifndef UCOMMON_SYSRUNTIME
26#ifndef _UCOMMON_STREAM_H_
27#define _UCOMMON_STREAM_H_
29#ifndef _UCOMMON_CONFIG_H
33#ifndef _UCOMMON_PROTOCOLS_H_
37#ifndef _UCOMMON_THREAD_H_
41#ifndef _UCOMMON_SOCKET_H_
45#ifndef _UCOMMON_FSYS_H_
49#ifndef _UCOMMON_SHELL_H_
64class __EXPORT
StreamBuffer :
protected std::streambuf,
public std::iostream
87 void allocate(
size_t size);
96 inline
bool is_open(
void)
const
99 inline operator bool()
const
100 {
return bufsize > 0;}
102 inline bool operator!()
const
103 {
return bufsize == 0;}
117 __LOCAL
void allocate(
unsigned size);
118 __LOCAL
void reset(
void);
124 virtual ssize_t _read(
char *buffer,
size_t size);
126 virtual ssize_t _write(
const char *buffer,
size_t size);
128 virtual bool _wait(
void);
151 inline socket_t getsocket(
void)
const {
196 inline operator bool()
const {
197 return so != INVALID_SOCKET && bufsize > 0;
205 return so == INVALID_SOCKET || bufsize == 0;
221 void open(
const char *host,
const char *service,
unsigned segment = 536);
247 __LOCAL
void allocate(
size_t size, access_t mode);
291 pipestream(
const char *command, access_t access,
char **args,
char **env = NULL,
size_t size = 512);
302 inline operator bool()
const {
303 return (bufsize > 0);
322 void open(
const char *path, access_t access,
char **args,
char **env = NULL,
size_t buffering = 512);
335 inline void cancel(
void) {
410 inline operator bool()
const {
411 return (bufsize > 0);
448 inline int err(
void)
const
456class __EXPORT
imemstream :
protected std::streambuf,
public std::istream
462 const uint8_t *pos, *bp;
468 int underflow() __OVERRIDE;
470 int uflow() __OVERRIDE;
472 inline size_t remains()
const {
476 inline const uint8_t *mem()
const {
480 inline const char *chr()
const {
481 return (
const char *)bp;
484 inline size_t len()
const {
485 return (
size_t)(pos - bp) + count;
492class __EXPORT
omemstream :
protected std::streambuf,
public std::ostream
502 explicit omemstream(uint8_t *data,
size_t size);
505 int overflow(
int ch) __OVERRIDE;
507 inline size_t remains()
const {
511 inline uint8_t *mem()
const {
515 inline char *chr()
const {
519 inline size_t len()
const {
520 return (
size_t)(pos - bp);
524bool __EXPORT getline(std::istream& in,
char *buffer,
size_t size);
526bool __EXPORT putline(std::ostream& out,
const char *buffer);
538 static std::ostream& print(std::ostream& out,
const PrintProtocol& format);
540 static std::istream& input(std::istream& inp,
InputProtocol& format);
542 static std::ostream& print(std::ostream& out,
const string_t& str);
544 static std::istream& input(std::istream& inp,
string_t& str);
546 static std::ostream& print(std::ostream& out,
const stringlist_t& list);
548 static std::istream& input(std::istream& in,
stringlist_t& list);
550 static std::string& append(std::string& target,
String& source);
553inline std::ostream& operator<< (std::ostream& out,
const PrintProtocol& format) {
554 return _stream_operators::print(out, format);
557inline std::istream& operator>> (std::istream& inp, InputProtocol& format) {
558 return _stream_operators::input(inp, format);
561inline std::ostream& operator<< (std::ostream& out,
const string_t& str) {
562 return _stream_operators::print(out, str);
565inline std::istream& operator>> (std::istream& inp,
string_t& str) {
566 return _stream_operators::input(inp, str);
569inline std::ostream& operator<< (std::ostream& out,
const stringlist_t& list) {
570 return _stream_operators::print(out, list);
573inline std::istream& operator>> (std::istream& in,
stringlist_t& list) {
574 return _stream_operators::input(in, list);
577inline std::string& operator+(std::string& target, String& source) {
578 return _stream_operators::append(target, source);
581inline std::string& operator+=(std::string& target, String& source) {
582 return _stream_operators::append(target, source);
585inline std::ostream& operator<<(std::ostream& os, Socket::address&
addr) {
587 char buf[INET6_ADDRSTRLEN];
589 char buf[INET_ADDRSTRLEN];
591 addr.print(buf,
sizeof(buf),
false,
true);
599 extern __EXPORT iostream& null;
Thread-aware file system manipulation class.
Various miscellaneous platform specific headers and defines.
Abstract interfaces and support.
Generic shell parsing and application services.
Common namespace for all ucommon objects.
String string_t
A convenience type for string.
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.
StringPager stringlist_t
A convenience type for paged string lists.
A container for generic and o/s portable threadsafe file system functions.
int err(void) const
Get last error.
access_t
Enumerated file access modes.
long offset_t
File offset type.
String pager for storing lists of NULL terminated strings.
Used for forming stream output.
Used for processing input.
int pid_t
Standard type of process id for shell class.
A generic socket address class.
A generic tcp server class.
Common stream buffer for std C++ i/o classes.
int uflow()
This streambuf method is used for doing unbuffered reads through the establish tcp socket connection ...
Streamable tcp connection between client and server.
tcpstream(int family=2, timeout_t timeout=0)
Create an unconnected tcp stream object that is idle until opened.
int underflow(void)
This streambuf method is used to load the input buffer through the established tcp socket connection.
int overflow(int ch)
This streambuf method is used to write the output buffer through the established tcp connection.
void open(Socket::address &address, unsigned segment=536)
Open a stream connection to a tcp service.
virtual ~tcpstream()
Destroy a tcp stream.
void close(void)
Close an active stream connection.
void open(const char *host, const char *service, unsigned segment=536)
Open a stream connectoion to a host and service.
tcpstream(const tcpstream ©)
Copy constructor...
void release(void)
Release the tcp stream and destroy the underlying socket.
tcpstream(const TCPServer *server, unsigned segsize=536, timeout_t timeout=0)
Create a stream from an existing tcp listener.
bool operator!() const
See if stream is disconnected.
tcpstream(Socket::address &address, unsigned segsize=536, timeout_t timeout=0)
A convenience constructor that creates a connected tcp stream directly from an address.
Streamable pipe socket connection.
void release(void)
Release the stream, detach/do not wait for the process.
int underflow(void)
This streambuf method is used to load the input buffer through the established pipe connection.
int overflow(int ch)
This streambuf method is used to write the output buffer through the established pipe connection.
virtual ~pipestream()
Destroy a pipe stream.
bool operator!() const
See if stream is disconnected.
pipestream(const char *command, access_t access, char **args, char **env=NULL, size_t size=512)
Create child process and start pipe.
pipestream()
Create an unopened pipe stream.
void terminate(void)
Force terminate child and close.
void open(const char *path, access_t access, char **args, char **env=NULL, size_t buffering=512)
Open a stream connection to a pipe service.
int close(void)
Close an active stream connection.
Streamable file class based on low level fsys io.
filestream(const filestream ©)
Create duplicate stream.
void open(const char *filename, fsys::access_t access, size_t buffering=512)
Open a stream connection to a tcp service.
int overflow(int ch)
This streambuf method is used to write the output buffer through the established pipe connection.
virtual ~filestream()
Destroy a file stream.
void seek(fsys::offset_t offset)
Seek position.
bool operator!() const
See if stream is disconnected.
filestream(const char *path, fsys::access_t access, size_t bufsize=512)
Open file stream.
void close(void)
Close an active stream connection.
filestream()
Create an unopened pipe stream.
void open(const char *filename, unsigned mode, fsys::access_t access, size_t buffering=512)
Create a stream connection to a tcp service.
int err(void) const
Get error flag from last i/o operation.
int underflow(void)
This streambuf method is used to load the input buffer through the established pipe connection.
filestream(const char *path, unsigned mode, fsys::access_t access, size_t bufsize=512)
Create and open a file stream.
Stream class to read from a memory buffer.
Stream class to write to memory buffer.
At least with gcc, linking of stream operators was broken.
A copy-on-write string class that operates by reference count.
Common socket class and address manipulation.
Thread classes and sychronization objects.