00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _OASYS_BUFFERED_IO_H_
00018 #define _OASYS_BUFFERED_IO_H_
00019
00020 #include "../debug/Logger.h"
00021 #include "../io/IOClient.h"
00022 #include "../util/StreamBuffer.h"
00023
00024 namespace oasys {
00025
00030 class BufferedInput : public Logger {
00031 public:
00032 BufferedInput(IOClient* client, const char* logbase = "/BufferedInput");
00033 ~BufferedInput();
00034
00046 int read_line(const char* nl, char** buf, int timeout = -1);
00047
00061 int read_bytes(size_t len, char** buf, int timeout = -1);
00062
00063
00072 int read_some_bytes(char** buf, int timeout = -1);
00073
00078 char get_char(int timeout = -1);
00079
00083 bool eof();
00084
00085 private:
00094 int internal_read(size_t len = 0, int timeout_ms = -1);
00095
00100 int find_nl(const char* nl);
00101
00102 IOClient* client_;
00103 StreamBuffer buf_;
00104
00105 bool seen_eof_;
00106
00107 static const size_t READ_AHEAD = 256;
00108 static const size_t MAX_LINE = 4096;
00109 };
00110
00111 class BufferedOutput : public Logger {
00112 public:
00113 BufferedOutput(IOClient* client, const char* logbase = "/BufferedOutput");
00114
00121 int write(const char* bp, size_t len = 0);
00122
00126 void clear_buf();
00127
00132 int format_buf(const char* format, ...) PRINTFLIKE(2, 3);
00133 int vformat_buf(const char* format, va_list args);
00134
00139 int flush();
00140
00146 void set_flush_limit(size_t limit);
00147
00151 int printf(const char* format, ...) PRINTFLIKE(2, 3);
00152
00153 private:
00154 IOClient* client_;
00155 StreamBuffer buf_;
00156
00157 size_t flush_limit_;
00158
00159 static const size_t DEFAULT_FLUSH_LIMIT = 256;
00160 };
00161
00162 }
00163
00164 #endif