Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #if defined(OLD_STDCPP) || defined(NEW_STDCPP)
00025 #ifndef _UCOMMON_STREAM_H_
00026 #define _UCOMMON_STREAM_H_
00027
00028 #ifndef _UCOMMON_THREAD_H_
00029 #include <ucommon/thread.h>
00030 #endif
00031
00032 #ifndef _UCOMMON_SOCKET_H_
00033 #include <ucommon/socket.h>
00034 #endif
00035
00036 #ifndef _UCOMMON_FSYS_H_
00037 #include <ucommon/fsys.h>
00038 #endif
00039
00040 #include <iostream>
00041
00042 NAMESPACE_UCOMMON
00043
00052 class __EXPORT tcpstream : protected std::streambuf, public std::iostream
00053 {
00054 private:
00055 __LOCAL void allocate(unsigned size);
00056 __LOCAL void reset(void);
00057
00058 protected:
00059 socket_t so;
00060 timeout_t timeout;
00061 size_t bufsize;
00062 char *gbuf, *pbuf;
00063
00067 void release(void);
00068
00075 int underflow();
00076
00085 int uflow();
00086
00094 int overflow(int ch);
00095
00096 public:
00101 tcpstream(const tcpstream& copy);
00102
00109 tcpstream(ListenSocket& listener, unsigned segsize = 536, timeout_t timeout = 0);
00110
00116 tcpstream(int family = PF_INET, timeout_t timeout = 0);
00117
00126 tcpstream(Socket::address& address, unsigned segsize = 536, timeout_t timeout = 0);
00127
00131 virtual ~tcpstream();
00132
00137 inline operator bool() const
00138 {return so != INVALID_SOCKET && bufsize > 0;};
00139
00144 inline bool operator!() const
00145 {return so == INVALID_SOCKET || bufsize == 0;};
00146
00152 void open(Socket::address& address, unsigned segment = 536);
00153
00158 void close(void);
00159
00164 int sync(void);
00165 };
00166
00175 class __EXPORT pipestream : protected std::streambuf, public std::iostream
00176 {
00177 public:
00178 typedef enum {
00179 RDONLY,
00180 WRONLY,
00181 RDWR
00182 } access_t;
00183
00184 private:
00185 __LOCAL void allocate(size_t size, access_t mode);
00186
00187 protected:
00188 fsys_t rd, wr;
00189 pid_t pid;
00190 size_t bufsize;
00191 char *gbuf, *pbuf;
00192
00196 void release(void);
00197
00204 int underflow();
00205
00214 int uflow();
00215
00223 int overflow(int ch);
00224
00225 public:
00229 pipestream();
00230
00238 pipestream(const char *command, access_t access, const char **env = NULL, size_t size = 512);
00239
00243 virtual ~pipestream();
00244
00249 inline operator bool() const
00250 {return (bufsize > 0);};
00251
00256 inline bool operator!() const
00257 {return bufsize == 0;};
00258
00266 void open(const char *command, access_t access, const char **env = NULL, size_t buffering = 512);
00267
00272 void close(void);
00273
00277 void terminate(void);
00278
00283 int sync(void);
00284 };
00285
00294 class __EXPORT filestream : protected std::streambuf, public std::iostream
00295 {
00296 public:
00297 typedef enum {
00298 RDONLY,
00299 WRONLY,
00300 RDWR
00301 } access_t;
00302
00303 private:
00304 __LOCAL void allocate(size_t size, fsys::access_t mode);
00305
00306 protected:
00307 fsys_t fd;
00308 fsys::access_t ac;
00309 size_t bufsize;
00310 char *gbuf, *pbuf;
00311
00318 int underflow();
00319
00328 int uflow();
00329
00337 int overflow(int ch);
00338
00339 public:
00343 filestream();
00344
00348 filestream(const filestream& copy);
00349
00353 filestream(const char *path, fsys::access_t access, unsigned mode, size_t bufsize);
00354
00358 filestream(const char *path, fsys::access_t access, size_t bufsize);
00359
00363 virtual ~filestream();
00364
00369 inline operator bool() const
00370 {return (bufsize > 0);};
00371
00376 inline bool operator!() const
00377 {return bufsize == 0;};
00378
00382 void open(const char *filename, fsys::access_t access, size_t buffering = 512);
00383
00387 void create(const char *filename, fsys::access_t access, unsigned mode, size_t buffering = 512);
00388
00392 void close(void);
00393
00397 void seek(fsys::offset_t offset);
00398
00403 int sync(void);
00404
00409 inline int error(void) const
00410 {return fd.getError();};
00411 };
00412
00413 END_NAMESPACE
00414
00415 #endif
00416 #endif