RCFProto

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
Asio.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_ASIO_HPP
20 #define INCLUDE_RCF_ASIO_HPP
21
22 #include <RCF/Config.hpp>
23
24 // Turn off auto-linking for Boost Date Time lib. Asio headers include some boost/date_time/ headers.
25 #define BOOST_DATE_TIME_NO_LIB
26 #define BOOST_REGEX_NO_LIB
27
28 #include <RCF/AsioFwd.hpp>
29
30 // Some issues with asio headers.
31 //#if defined(__MACH__) && defined(__APPLE__)
32 //#include <limits.h>
33 //#ifndef IOV_MAX
34 //#define IOV_MAX 1024
35 //#endif
36 //#endif
37
38 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
39 # if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
40 # error WinSock.h has already been included. Define WIN32_LEAN_AND_MEAN in your build, to avoid implicit inclusion of WinSock.h.
41 # endif // defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
42 #endif
43
44 #ifdef _MSC_VER
45 #pragma warning(push)
46 #pragma warning(disable: 4913) // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used
47 #endif
48
49 #ifdef RCF_USE_BOOST_ASIO
50 #include <boost/asio.hpp>
51 #else
52 #include <RCF/external/asio/asio.hpp>
53 #endif
54
55 // Do we have local sockets?
56 #ifdef RCF_USE_BOOST_ASIO
57 #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
58 #define RCF_HAS_LOCAL_SOCKETS
59 #endif
60 #else
61 #ifdef ASIO_HAS_LOCAL_SOCKETS
62 #define RCF_HAS_LOCAL_SOCKETS
63 #endif
64 #endif
65
66 #include <RCF/AsioDeadlineTimer.hpp>
67
68 #ifdef _MSC_VER
69 #pragma warning(pop)
70 #endif
71
72 namespace RCF {
73
74
75 typedef ASIO_NS::ip::tcp::socket AsioSocket;
76 typedef boost::shared_ptr<AsioSocket> AsioSocketPtr;
77
78 typedef ASIO_NS::const_buffer AsioConstBuffer;
79
80 // This adapter around a std::vector prevents asio from making a deep copy
81 // of the buffer list, when sending multiple buffers. The deep copy would
82 // involve making memory allocations.
83 class AsioBuffers
84 {
85 public:
86
87 typedef std::vector<AsioConstBuffer> BufferVec;
88 typedef boost::shared_ptr<BufferVec> BufferVecPtr;
89
90 typedef AsioConstBuffer value_type;
91 typedef BufferVec::const_iterator const_iterator;
92
93 AsioBuffers()
94 {
95 mVecPtr.reset( new std::vector<AsioConstBuffer>() );
96 }
97
98 const_iterator begin() const
99 {
100 return mVecPtr->begin();
101 }
102
103 const_iterator end() const
104 {
105 return mVecPtr->end();
106 }
107
108 BufferVecPtr mVecPtr;
109 };
110
111 } // namespace RCF
112
113
114 #endif // ! INCLUDE_RCF_ASIO_HPP