Remote Call Framework 3.0
TcpServerTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2018, 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: 3.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/IpAddress.hpp>
26 
27 namespace RCF {
28 
29  class TcpServerTransport;
30 
31  class RCF_EXPORT TcpNetworkSession : public AsioNetworkSession
32  {
33  public:
34 
35  TcpNetworkSession(
36  TcpServerTransport &transport,
37  AsioIoService & ioService);
38 
39  const RemoteAddress & implGetRemoteAddress();
40 
41  void implRead(char * buffer, std::size_t bufferLen);
42 
43  void implWrite(const std::vector<ByteBuffer> & buffers);
44 
45  void implWrite(
46  AsioNetworkSession &toBeNotified,
47  const char * buffer,
48  std::size_t bufferLen);
49 
50  void implAccept();
51 
52  bool implOnAccept();
53 
54  void implClose();
55 
56  void implCloseAfterWrite();
57 
58  bool implIsConnected();
59 
60  ClientTransportUniquePtr implCreateClientTransport();
61 
62  void implTransferNativeFrom(ClientTransport & clientTransport);
63 
64  int getNativeHandle();
65 
66  private:
67 
68  AsioSocketPtr mSocketPtr;
69  IpAddress mIpAddress;
70  int mWriteCounter;
71  };
72 
73  class RCF_EXPORT TcpServerTransport :
74  public AsioServerTransport,
75  public IpServerTransport
76  {
77  public:
78  TcpServerTransport(const IpAddress & ipAddress);
79  TcpServerTransport(const std::string & ip, int port);
80 
81  TransportType getTransportType();
82 
83  ServerTransportPtr clone();
84 
85  // IpServerTransport implementation
86  int getPort() const;
87 
88  private:
89 
90  AsioNetworkSessionPtr implCreateNetworkSession();
91  void implOpen();
92 
93  void onServerStart(RcfServer & server);
94 
95  ClientTransportUniquePtr implCreateClientTransport(
96  const Endpoint &endpoint);
97 
98  private:
99  IpAddress mIpAddress;
100 
101  int mAcceptorFd;
102  };
103 
104 } // namespace RCF
105 
106 #endif // ! INCLUDE_RCF_TCPSERVERTRANSPORT_HPP
std::unique_ptr< ClientTransport > ClientTransportUniquePtr
Unique pointer wrapper for RCF::ClientTransport.
Definition: RcfFwd.hpp:43
Definition: AmiIoHandler.hpp:24
TransportType
Describes the transport types used by a RCF connection.
Definition: Enums.hpp:34
std::shared_ptr< ServerTransport > ServerTransportPtr
Unique pointer wrapper for RCF::ServerTransport.
Definition: RcfFwd.hpp:46