// This file is part of Timmi. // // Timmi is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. #ifndef TCPSOCKET_HH #define TCPSOCKET_HH #include class TCPSocket { public: TCPSocket(int fd, std::string addr = ""); ~TCPSocket(); // Get the socket file descriptor int getfd() const; // Get the socket remote address std::string getaddr() const; // Is the socket ready for IO bool good() const; // Wait for event for timeout milliseconds // Return true on event, false on timeout bool wait_for_event(int timeout = -1) const; // Get a line from socket, return true if got line bool getline(std::string &line); // Send a line void putline(std::string line); private: int fd_; // Connected socket file descriptor std::string addr_; // Remote address formatted as string std::string buf_; // Socket reception buffer, where partial lines are stored bool good_; // Is the socket ready for IO // Receive data to internal buffer void receive_(); }; #endif