MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputStream.hpp
1 /*
2  Copyright (C) 2003-2008 MySQL AB, 2008 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef OUTPUT_STREAM_HPP
20 #define OUTPUT_STREAM_HPP
21 
22 #include <ndb_global.h>
23 #include <NdbTCP.h>
24 
28 class OutputStream {
29 public:
30  OutputStream() {}
31  virtual ~OutputStream() {}
32  virtual int print(const char * fmt, ...)
33  ATTRIBUTE_FORMAT(printf, 2, 3) = 0;
34  virtual int println(const char * fmt, ...)
35  ATTRIBUTE_FORMAT(printf, 2, 3) = 0;
36  virtual void flush() {};
37  virtual void reset_timeout() {};
38 };
39 
41  FILE * f;
42 public:
43  FileOutputStream(FILE * file = stdout);
44  virtual ~FileOutputStream() {}
45  FILE *getFile() { return f; }
46 
47  int print(const char * fmt, ...)
48  ATTRIBUTE_FORMAT(printf, 2, 3);
49  int println(const char * fmt, ...)
50  ATTRIBUTE_FORMAT(printf, 2, 3);
51  void flush() { fflush(f); }
52 };
53 
55 protected:
56  NDB_SOCKET_TYPE m_socket;
57  unsigned m_timeout_ms;
58  bool m_timedout;
59  unsigned m_timeout_remain;
60 public:
61  SocketOutputStream(NDB_SOCKET_TYPE socket, unsigned write_timeout_ms = 1000);
62  virtual ~SocketOutputStream() {}
63  bool timedout() { return m_timedout; }
64  void reset_timeout() { m_timedout= false; m_timeout_remain= m_timeout_ms;}
65 
66  int print(const char * fmt, ...)
67  ATTRIBUTE_FORMAT(printf, 2, 3);
68  int println(const char * fmt, ...)
69  ATTRIBUTE_FORMAT(printf, 2, 3);
70 };
71 
72 
74  class UtilBuffer& m_buffer;
75 public:
76  BufferedSockOutputStream(NDB_SOCKET_TYPE socket,
77  unsigned write_timeout_ms = 1000);
78  virtual ~BufferedSockOutputStream();
79 
80  int print(const char * fmt, ...)
81  ATTRIBUTE_FORMAT(printf, 2, 3);
82  int println(const char * fmt, ...)
83  ATTRIBUTE_FORMAT(printf, 2, 3);
84 
85  void flush();
86 };
87 
88 
90 public:
91  NullOutputStream() {}
92  virtual ~NullOutputStream() {}
93  int print(const char * /* unused */, ...) { return 1;}
94  int println(const char * /* unused */, ...) { return 1;}
95 };
96 
97 #endif