00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _OASYS_BUFFERED_IO_H_
00039 #define _OASYS_BUFFERED_IO_H_
00040
00041 #include "../debug/Logger.h"
00042 #include "../io/IOClient.h"
00043 #include "../util/StreamBuffer.h"
00044
00045 namespace oasys {
00046
00051 class BufferedInput : public Logger {
00052 public:
00053 BufferedInput(IOClient* client, const char* logbase = "/BufferedInput");
00054 ~BufferedInput();
00055
00067 int read_line(const char* nl, char** buf, int timeout = -1);
00068
00082 int read_bytes(size_t len, char** buf, int timeout = -1);
00083
00084
00093 int read_some_bytes(char** buf, int timeout = -1);
00094
00099 char get_char(int timeout = -1);
00100
00104 bool eof();
00105
00106 private:
00115 int internal_read(size_t len = 0, int timeout_ms = -1);
00116
00121 int find_nl(const char* nl);
00122
00123 IOClient* client_;
00124 StreamBuffer buf_;
00125
00126 bool seen_eof_;
00127
00128 static const size_t READ_AHEAD = 256;
00129 static const size_t MAX_LINE = 4096;
00130 };
00131
00132 class BufferedOutput : public Logger {
00133 public:
00134 BufferedOutput(IOClient* client, const char* logbase = "/BufferedOutput");
00135
00142 int write(const char* bp, size_t len = 0);
00143
00147 void clear_buf();
00148
00153 int format_buf(const char* format, ...) PRINTFLIKE(2, 3);
00154 int vformat_buf(const char* format, va_list args);
00155
00160 int flush();
00161
00167 void set_flush_limit(size_t limit);
00168
00172 int printf(const char* format, ...) PRINTFLIKE(2, 3);
00173
00174 private:
00175 IOClient* client_;
00176 StreamBuffer buf_;
00177
00178 size_t flush_limit_;
00179
00180 static const size_t DEFAULT_FLUSH_LIMIT = 256;
00181 };
00182
00183 }
00184
00185 #endif