RCFProto
 All Classes Functions Typedefs
UnixLocalServerTransport.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_UNIXLOCALSERVERTRANSPORT_HPP
20 #define INCLUDE_RCF_UNIXLOCALSERVERTRANSPORT_HPP
21 
22 #if defined(BOOST_WINDOWS)
23 #error Unix domain sockets not supported on Windows.
24 #endif
25 
26 #ifndef RCF_HAS_LOCAL_SOCKETS
27 #error Unix domain sockets not supported by this version of Boost.Asio.
28 #endif
29 
30 #include <RCF/AsioServerTransport.hpp>
31 #include <RCF/Export.hpp>
32 
33 namespace RCF {
34 
35  using ASIO_NS::local::stream_protocol;
36  typedef stream_protocol::socket UnixLocalSocket;
37  typedef boost::shared_ptr<UnixLocalSocket> UnixLocalSocketPtr;
38 
39  class UnixLocalServerTransport;
40 
41  class RCF_EXPORT UnixLocalSessionState : public AsioSessionState
42  {
43  public:
44  UnixLocalSessionState(
45  UnixLocalServerTransport & transport,
46  AsioIoService & ioService);
47 
48  const RemoteAddress & implGetRemoteAddress();
49 
50  void implRead(char * buffer, std::size_t bufferLen);
51 
52  void implWrite(const std::vector<ByteBuffer> & buffers);
53 
54  void implWrite(
55  AsioSessionState &toBeNotified,
56  const char * buffer,
57  std::size_t bufferLen);
58 
59  void implAccept();
60 
61  bool implOnAccept();
62 
63  bool implIsConnected();
64 
65  void implClose();
66 
67  void implCloseAfterWrite();
68 
69  ClientTransportAutoPtr implCreateClientTransport();
70 
71  void implTransferNativeFrom(ClientTransport & clientTransport);
72 
73  int getNativeHandle();
74 
75  private:
76  UnixLocalSocketPtr mSocketPtr;
77  std::string mRemoteFileName;
78  NoRemoteAddress mRemoteAddress;
79  };
80 
81  class RCF_EXPORT UnixLocalServerTransport :
82  public AsioServerTransport
83  {
84  public:
85 
86  UnixLocalServerTransport(const std::string & fileName);
87 
88  TransportType getTransportType();
89 
90  ServerTransportPtr clone();
91 
92  AsioSessionStatePtr implCreateSessionState();
93 
94  void implOpen();
95 
96  ClientTransportAutoPtr implCreateClientTransport(
97  const Endpoint &endpoint);
98 
99  std::string getPipeName() const;
100 
101  void onServerStart(RcfServer & server);
102  void onServerStop(RcfServer & server);
103 
104  private:
105 
106  const std::string mFileName;
107  };
108 
109 } // namespace RCF
110 
111 #endif // ! INCLUDE_RCF_UNIXLOCALSERVERTRANSPORT_HPP