hotspot/src/share/vm/utilities/ostream.hpp
author never
Tue, 24 Jun 2008 16:00:14 -0700
changeset 768 d0bebc7eefc2
parent 347 df859fcca515
child 781 e1baa9c8f16f
child 1383 3a216aa862b7
permissions -rw-r--r--
6718676: putback for 6604014 is incomplete Reviewed-by: kvn, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Output streams for printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// Printing guidelines:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Where possible, please use tty->print() and tty->print_cr().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// For product mode VM warnings use warning() which internally uses tty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// In places where tty is not initialized yet or too much overhead,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// we may use jio_printf:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//     jio_fprintf(defaultStream::output_stream(), "Message");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// This allows for redirection via -XX:+DisplayVMOutputToStdout and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// -XX:+DisplayVMOutputToStderr
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class outputStream : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
   int _indentation; // current indentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
   int _width;       // width of the page
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
   int _position;    // position on the current line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
   int _newlines;    // number of '\n' output so far
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
   julong _precount; // number of chars output, less _position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
   TimeStamp _stamp; // for time stamps
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
   void update_position(const char* s, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
   static const char* do_vsnprintf(char* buffer, size_t buflen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
                                   const char* format, va_list ap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                                   bool add_cr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                                   size_t& result_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
   // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
   outputStream(int width = 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
   outputStream(int width, bool has_time_stamps);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
   // indentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
   void indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
   void inc() { _indentation++; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
   void dec() { _indentation--; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
   int  indentation() const    { return _indentation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
   void set_indentation(int i) { _indentation = i;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
   void fill_to(int col);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
    62
   void move_to(int col, int slop = 6, int min_space = 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
   // sizing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
   int width()    const { return _width;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
   int position() const { return _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
   int newlines() const { return _newlines; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
   julong count() const { return _precount + _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
   void set_count(julong count) { _precount = count - _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
   void set_position(int pos)   { _position = pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
   // printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
   void print(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
   void print_cr(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
   void vprint(const char *format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
   void vprint_cr(const char* format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
   void print_raw(const char* str)            { write(str, strlen(str)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
   void print_raw(const char* str, int len)   { write(str,         len); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
   void print_raw_cr(const char* str)         { write(str, strlen(str)); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
   void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
   void put(char ch);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
    82
   void sp(int count = 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
   void cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
   void bol() { if (_position > 0)  cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
   // Time stamp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
   TimeStamp& time_stamp() { return _stamp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
   void stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
   // Date stamp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
   void date_stamp(bool guard, const char* prefix, const char* suffix);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
   // A simplified call that includes a suffix of ": "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
   void date_stamp(bool guard) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
     date_stamp(guard, "", ": ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
   // portable printing of 64 bit integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
   void print_jlong(jlong value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
   void print_julong(julong value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
   // flushing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
   virtual void flush() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
   virtual void write(const char* str, size_t len) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
   virtual ~outputStream() {}  // close properly on deletion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
   void dec_cr() { dec(); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
   void inc_cr() { inc(); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
// standard output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                                // ANSI C++ name collision
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
extern outputStream* tty;           // tty output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
extern outputStream* gclog_or_tty;  // stream for gc log if -Xloggc:<f>, or tty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// advisory locking for the shared tty stream:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
class ttyLocker: StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  intx _holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  static intx  hold_tty();                // returns a "holder" token
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  static void  release_tty(intx holder);  // must witness same token
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  static void  break_tty_lock_for_safepoint(intx holder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  ttyLocker()  { _holder = hold_tty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  ~ttyLocker() { release_tty(_holder); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// for writing to strings; buffer will expand automatically
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
class stringStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  char*  buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  size_t buffer_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  size_t buffer_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  bool   buffer_fixed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  stringStream(size_t initial_bufsize = 256);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  stringStream(char* fixed_buffer, size_t fixed_buffer_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  ~stringStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  size_t      size() { return buffer_pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  const char* base() { return buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  void  reset() { buffer_pos = 0; _precount = 0; _position = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  char* as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
class fileStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  FILE* _file;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  bool  _need_close;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  fileStream(const char* file_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  fileStream(FILE* file) { _file = file; _need_close = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  ~fileStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  bool is_open() const { return _file != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// unlike fileStream, fdStream does unbuffered I/O by calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// open() and write() directly. It is async-safe, but output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// from multiple thread may be mixed together. Used by fatal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
// error handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
class fdStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  int  _fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  bool _need_close;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  fdStream(const char* file_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  fdStream(int fd = -1) { _fd = fd; _need_close = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  ~fdStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  bool is_open() const { return _fd != -1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  void set_fd(int fd) { _fd = fd; _need_close = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  int fd() const { return _fd; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  void flush() {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
void ostream_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
void ostream_init_log();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
void ostream_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
void ostream_abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
// staticBufferStream uses a user-supplied buffer for all formatting.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
// Used for safe formatting during fatal error handling.  Not MT safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
// Do not share the stream between multiple threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
class staticBufferStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  char* _buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  size_t _buflen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  outputStream* _outer_stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  staticBufferStream(char* buffer, size_t buflen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
                     outputStream *outer_stream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  ~staticBufferStream() {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  void print(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  void print_cr(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  void vprint(const char *format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  void vprint_cr(const char* format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// In the non-fixed buffer case an underlying buffer will be created and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
// managed in C heap. Not MT-safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
class bufferedStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  char*  buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  size_t buffer_pos;
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   209
  size_t buffer_max;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  size_t buffer_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  bool   buffer_fixed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
 public:
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   213
  bufferedStream(size_t initial_bufsize = 256, size_t bufmax = 1024*1024*10);
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   214
  bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax = 1024*1024*10);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  ~bufferedStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  size_t      size() { return buffer_pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  const char* base() { return buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  void  reset() { buffer_pos = 0; _precount = 0; _position = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  char* as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
#define O_BUFLEN 2000   // max size of output of individual print() methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
class networkStream : public bufferedStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    int _socket;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    ~networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    bool connect(const char *host, short port);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    bool is_open() const { return _socket != -1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    int read(char *buf, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    void close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    virtual void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
#endif