1 /* 2 Copyright (C) 2003-2008 MySQL AB 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, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 */ 25 26 #ifndef INPUT_STREAM_HPP 27 #define INPUT_STREAM_HPP 28 29 #include <ndb_global.h> 30 #include <NdbTCP.h> 31 #include <NdbMutex.h> 32 33 /** 34 * Input stream 35 */ 36 class InputStream { 37 public: InputStream()38 InputStream() { m_mutex= NULL; } ~InputStream()39 virtual ~InputStream() {} 40 virtual char* gets(char * buf, int bufLen) = 0; 41 /** 42 * Set the mutex to be UNLOCKED when blocking (e.g. select(2)) 43 */ set_mutex(NdbMutex * m)44 void set_mutex(NdbMutex *m) { m_mutex= m; } reset_timeout()45 virtual void reset_timeout() {} 46 protected: 47 NdbMutex *m_mutex; 48 }; 49 50 class FileInputStream : public InputStream { 51 FILE * f; 52 public: 53 FileInputStream(FILE * file = stdin); ~FileInputStream()54 virtual ~FileInputStream() {} 55 char* gets(char * buf, int bufLen); 56 }; 57 58 extern FileInputStream Stdin; 59 60 class SocketInputStream : public InputStream { 61 NDB_SOCKET_TYPE m_socket; 62 unsigned m_timeout_ms; 63 unsigned m_timeout_remain; 64 bool m_startover; 65 bool m_timedout; 66 public: 67 SocketInputStream(NDB_SOCKET_TYPE socket, unsigned read_timeout_ms = 60000); ~SocketInputStream()68 virtual ~SocketInputStream() {} 69 char* gets(char * buf, int bufLen); timedout()70 bool timedout() { return m_timedout; } reset_timeout()71 void reset_timeout() { m_timedout= false; m_timeout_remain= m_timeout_ms;} 72 73 }; 74 75 #endif 76