MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SocketInputStream2.hpp
1 /* Copyright 2008 Sun Microsystems, Inc.
2  All rights reserved. Use is subject to license terms.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 
17 #ifndef SOCKETINPUTSTREAM2_HPP
18 #define SOCKETINPUTSTREAM2_HPP
19 
20 #include <NdbTCP.h>
21 #include <BaseString.hpp>
22 #include <UtilBuffer.hpp>
23 
25  NDB_SOCKET_TYPE m_socket;
26  unsigned m_read_timeout;
27  UtilBuffer m_buffer;
28  size_t m_buffer_read_pos;
29 
30  bool has_data_to_read();
31  ssize_t read_socket(char* buf, size_t len);
32  bool get_buffered_line(BaseString& str);
33  bool add_buffer(char* buf, ssize_t len);
34 
35 public:
36  SocketInputStream2(NDB_SOCKET_TYPE socket,
37  unsigned read_timeout = 60) :
38  m_socket(socket),
39  m_read_timeout(read_timeout),
40  m_buffer_read_pos(0)
41  {};
42 
43  /*
44  Read a line from socket into the string "str" until
45  either terminating newline, EOF or read timeout encountered.
46 
47  Returns:
48  true - a line ended with newline was read from socket
49  false - EOF or read timeout occured
50 
51  */
52  bool gets(BaseString& str);
53 
54 };
55 
56 #endif