My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
Client.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_CLIENT_H
2 #define GCP_UTIL_CLIENT_H
3 
11 #include "gcp/util/common/FdSet.h"
12 #include "gcp/util/common/NetDat.h"
13 #include "gcp/util/common/NetHandler.h"
14 #include "gcp/util/common/Runnable.h"
15 #include "gcp/util/common/TcpClient.h"
16 #include "gcp/util/common/TimeVal.h"
17 
18 namespace gcp {
19  namespace util {
20 
21  class Client : public Runnable {
22  public:
23 
27  Client(bool spawn, std::string host, unsigned connectPort,
28  unsigned readBufSize=0, unsigned sendBufSize=0);
29 
33  virtual ~Client();
34 
38  void run();
39 
40  void setReadBufSize(unsigned size);
41  void setSendBufSize(unsigned size);
42 
43  protected:
44 
45  // Method called when data have been completely read from the server
46 
47  virtual void readServerData(NetHandler& handler) {};
48 
49  // Send data to the server
50 
51  void sendServerData(NetDat& dat);
52 
53  TimeVal timeOut_;
54  struct timeval* timeOutPtr_;
55 
56  private:
57 
58  bool stop_;
59 
60  // The connection manager
61 
62  TcpClient tcp_;
63 
64  NetHandler handler_;
65 
66  FdSet fdSet_;
67 
68  void initMembers(std::string host, unsigned port,
69  unsigned readBufSize, unsigned sendBufSize);
70 
71  // A run method to be called from pthread_start()
72 
73  static RUN_FN(runFn);
74 
75  static NET_READ_HANDLER(readHandler);
76  static NET_SEND_HANDLER(sendHandler);
77  static NET_ERROR_HANDLER(errHandler);
78 
79  void connect();
80  void disconnect();
81 
82  }; // End class Client
83 
84  } // End namespace util
85 } // End namespace gcp
86 
87 
88 #endif // End #ifndef GCP_UTIL_CLIENT_H
Definition: NetHandler.h:16
Definition: FdSet.h:16
Definition: TcpClient.h:18
Definition: Runnable.h:23
Definition: TimeVal.h:55
Definition: Client.h:21
void sendServerData(NetDat &dat)
Definition: Client.cc:79
Definition: NetDat.h:23
void run()
Definition: Client.cc:123
virtual ~Client()
Definition: Client.cc:71
Client(bool spawn, std::string host, unsigned connectPort, unsigned readBufSize=0, unsigned sendBufSize=0)
Definition: Client.cc:14