RCFProto
 All Classes Functions Typedefs
TcpServerTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_TCPSERVERTRANSPORT_HPP
20 #define INCLUDE_RCF_TCPSERVERTRANSPORT_HPP
21 
22 #include <RCF/AsioServerTransport.hpp>
23 
24 #include <RCF/Asio.hpp>
25 
26 namespace RCF {
27 
28  class TcpServerTransport;
29 
30  class RCF_EXPORT TcpNetworkSession : public AsioNetworkSession
31  {
32  public:
33 
34  TcpNetworkSession(
35  TcpServerTransport &transport,
36  AsioIoService & ioService);
37 
38  const RemoteAddress & implGetRemoteAddress();
39 
40  void implRead(char * buffer, std::size_t bufferLen);
41 
42  void implWrite(const std::vector<ByteBuffer> & buffers);
43 
44  void implWrite(
45  AsioNetworkSession &toBeNotified,
46  const char * buffer,
47  std::size_t bufferLen);
48 
49  void implAccept();
50 
51  bool implOnAccept();
52 
53  void implClose();
54 
55  void implCloseAfterWrite();
56 
57  bool implIsConnected();
58 
59  ClientTransportAutoPtr implCreateClientTransport();
60 
61  void implTransferNativeFrom(ClientTransport & clientTransport);
62 
63  int getNativeHandle();
64 
65  private:
66 
67  AsioSocketPtr mSocketPtr;
68  IpAddress mIpAddress;
69  int mWriteCounter;
70  };
71 
72  class RCF_EXPORT TcpServerTransport :
73  public AsioServerTransport,
74  public IpServerTransport
75  {
76  public:
77  TcpServerTransport(const IpAddress & ipAddress);
78  TcpServerTransport(const std::string & ip, int port);
79 
80  TransportType getTransportType();
81 
82  ServerTransportPtr clone();
83 
84  // IpServerTransport implementation
85  int getPort() const;
86 
87  private:
88 
89  AsioNetworkSessionPtr implCreateNetworkSession();
90  void implOpen();
91 
92  void onServerStart(RcfServer & server);
93 
94  ClientTransportAutoPtr implCreateClientTransport(
95  const Endpoint &endpoint);
96 
97  private:
98  IpAddress mIpAddress;
99 
100  int mAcceptorFd;
101  };
102 
103 } // namespace RCF
104 
105 #endif // ! INCLUDE_RCF_TCPSERVERTRANSPORT_HPP