/* ---- This file is part of SECONDO. Copyright (C) 2004, University in Hagen, Department of Computer Science, Database Systems for New Applications. SECONDO 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 2 of the License, or (at your option) any later version. SECONDO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SECONDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---- //paragraph [1] Title: [{\Large \bf \begin{center}] [\end{center}}] //characters [1] Type: [] [] //characters [2] Type: [] [] //[ae] [\"{a}] //[oe] [\"{o}] //[ue] [\"{u}] //[ss] [{\ss}] //[Ae] [\"{A}] //[Oe] [\"{O}] //[Ue] [\"{U}] //[x] [$\times $] //[->] [$\rightarrow $] //[toc] [\tableofcontents] [1] Implementation of a generic Tcp Client [toc] 1 Tcpclient class implementation see TcpClient.cpp for details. */ #ifndef __TCPCLIENT_H__ #define __TCPCLIENT_H__ #include #include #include #include #include //close #include //close #include #include #include #include //FD_SET, FD_ISSET, FD_ZERO macros // #include "Protocols.h" // wird hier nicht gebraucht #include #include #include #include #include namespace continuousqueries { // make sure to change this in TcpServer.h as well! #define MAXPACKETSIZE 4096 class TcpClient { public: struct Message { int socket=-1; uint64_t timestamp=0; std::string body=""; }; TcpClient(std::string targetAddress, int targetPort); ~TcpClient(); void Initialize(); void Receive(); int GetServerPort(); std::string GetServerAddress(); int GetMasterSocket(); TcpClient::Message CreateMsg(int sockd, std::string body); TcpClient::Message CreateConnectMsg(int sockd); TcpClient::Message CreateDisconnectMsg(int sockd); void PushMsgToQueue(TcpClient::Message msg); bool IsRunning(); void Shutdown(); int Send(std::string msg); void SendAsync(std::string msg); void AsyncHandler(); std::queue messages; std::mutex mqMutex; std::condition_variable mqCondition; private: std::string _targetAddress; int _targetPort; bool _running; int _master_socket; std::queue _outgoingMsgsQueue; std::mutex _outgoingMsgsMutex; std::condition_variable _outgoingMsgsCondition; }; } #endif