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 UnixLocalNetworkSession : public AsioNetworkSession
42  {
43  public:
44  UnixLocalNetworkSession(
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 implAccept();
55 
56  bool implOnAccept();
57 
58  bool implIsConnected();
59 
60  void implClose();
61 
62  void implCloseAfterWrite();
63 
64  ClientTransportAutoPtr implCreateClientTransport();
65 
66  void implTransferNativeFrom(ClientTransport & clientTransport);
67 
68  int getNativeHandle();
69 
70  private:
71  UnixLocalSocketPtr mSocketPtr;
72  std::string mRemoteFileName;
73  NoRemoteAddress mRemoteAddress;
74  };
75 
76  class RCF_EXPORT UnixLocalServerTransport :
77  public AsioServerTransport
78  {
79  public:
80 
81  UnixLocalServerTransport(const std::string & fileName);
82 
83  TransportType getTransportType();
84 
85  ServerTransportPtr clone();
86 
87  AsioNetworkSessionPtr implCreateNetworkSession();
88 
89  void implOpen();
90 
91  ClientTransportAutoPtr implCreateClientTransport(
92  const Endpoint &endpoint);
93 
94  std::string getPipeName() const;
95 
96  void onServerStart(RcfServer & server);
97  void onServerStop(RcfServer & server);
98 
99  private:
100 
101  const std::string mFileName;
102  };
103 
104 } // namespace RCF
105 
106 #endif // ! INCLUDE_RCF_UNIXLOCALSERVERTRANSPORT_HPP