mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-02-11 00:00:08 +08:00
Compare commits
134 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcbc7b034b | ||
|
|
5deb73311f | ||
|
|
1efcef1637 | ||
|
|
b3196ad6aa | ||
|
|
e6d64ab981 | ||
|
|
eef09bdb28 | ||
|
|
f077c32fa6 | ||
|
|
947ac7a34b | ||
|
|
46543218e6 | ||
|
|
14fed5527d | ||
|
|
16069c0127 | ||
|
|
8a4755d51f | ||
|
|
afdb988ae9 | ||
|
|
f2ef611283 | ||
|
|
7294157182 | ||
|
|
d75dc24a8c | ||
|
|
63f8838172 | ||
|
|
e793320734 | ||
|
|
aff379ba21 | ||
|
|
02d1895396 | ||
|
|
05217a5d55 | ||
|
|
3372aca957 | ||
|
|
618b086aa6 | ||
|
|
b4b0ef1aca | ||
|
|
0d2c4e99b5 | ||
|
|
45213a2d8e | ||
|
|
fb9560b7a0 | ||
|
|
51b3e19450 | ||
|
|
cc2663779f | ||
|
|
5129f6ecb2 | ||
|
|
4d794cc279 | ||
|
|
adcb23702e | ||
|
|
6b782a9309 | ||
|
|
1e77a600a4 | ||
|
|
e66d4b04a2 | ||
|
|
02b1077795 | ||
|
|
82d2694a57 | ||
|
|
43e011aa12 | ||
|
|
8a79798c2c | ||
|
|
ea77618c28 | ||
|
|
dd08e51a19 | ||
|
|
e3266c3792 | ||
|
|
23fcbf55a9 | ||
|
|
d7ca445f35 | ||
|
|
7d53a7f396 | ||
|
|
990326e52f | ||
|
|
2bd0879a3b | ||
|
|
9dd887db5c | ||
|
|
32f1555929 | ||
|
|
86cc97e55f | ||
|
|
133b3756e6 | ||
|
|
c0cd028912 | ||
|
|
175080ea69 | ||
|
|
1dd2f46452 | ||
|
|
c274ea6ecc | ||
|
|
1a3a83f332 | ||
|
|
9b6210faab | ||
|
|
1639547f74 | ||
|
|
4c1704d1a2 | ||
|
|
d387eb4f5f | ||
|
|
f4f98ddf88 | ||
|
|
b04a285210 | ||
|
|
2d1fdfb019 | ||
|
|
ad77627ca9 | ||
|
|
d8a55bc358 | ||
|
|
76e5488aa1 | ||
|
|
c3ed67b67d | ||
|
|
f9d506ffca | ||
|
|
ef93e5adc9 | ||
|
|
3db23628cb | ||
|
|
7331ae5fad | ||
|
|
aa396dad2d | ||
|
|
29bd59f78f | ||
|
|
f44694ce5f | ||
|
|
238abab032 | ||
|
|
688ce11081 | ||
|
|
3980fb9be5 | ||
|
|
8e87aecebf | ||
|
|
828011bbd3 | ||
|
|
a6e3758c68 | ||
|
|
fb23b2a92e | ||
|
|
7faa96b809 | ||
|
|
8d167952b1 | ||
|
|
d1f794ae57 | ||
|
|
96cf2d1804 | ||
|
|
79eca6ca5f | ||
|
|
37dc5e024e | ||
|
|
1f03a43003 | ||
|
|
0b94df103a | ||
|
|
d950779014 | ||
|
|
7d2bd2a1cf | ||
|
|
a76165a23e | ||
|
|
9ec9e579e9 | ||
|
|
5edb23a7ab | ||
|
|
1c8f34560f | ||
|
|
61c9e8f6dc | ||
|
|
206ce5eeb9 | ||
|
|
e77c8a7994 | ||
|
|
838184dcae | ||
|
|
36de2fc09c | ||
|
|
90fbbbea65 | ||
|
|
45723d7ee1 | ||
|
|
f3caddf509 | ||
|
|
f0844e998f | ||
|
|
208d87f258 | ||
|
|
b38a8050e0 | ||
|
|
7b2320fbe3 | ||
|
|
9eac433665 | ||
|
|
b00951ceae | ||
|
|
bd98a18fb3 | ||
|
|
4e2bb966c2 | ||
|
|
6766fb52f9 | ||
|
|
74f56bf680 | ||
|
|
aa67ea253f | ||
|
|
9686d3295a | ||
|
|
a58d48b88b | ||
|
|
e9b9b66317 | ||
|
|
9243263fcd | ||
|
|
9b51c260a1 | ||
|
|
4889f3b8cd | ||
|
|
399ce8435d | ||
|
|
ed98f2568b | ||
|
|
e7084c56c6 | ||
|
|
72bf0c306d | ||
|
|
16c2801168 | ||
|
|
fa25b668e0 | ||
|
|
b578e282f5 | ||
|
|
c514bf7312 | ||
|
|
ece80f63a9 | ||
|
|
9c09e6f507 | ||
|
|
f5fda0fa73 | ||
|
|
008678734f | ||
|
|
1e010202f7 | ||
|
|
4d36dbddd1 |
35
.gitignore
vendored
35
.gitignore
vendored
@@ -48,3 +48,38 @@ playground.xcworkspace
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build
|
||||
|
||||
# Swift PM
|
||||
|
||||
.build/
|
||||
.swiftpm
|
||||
|
||||
## macOS generated
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
6
CHANGELOG.md
Normal file
6
CHANGELOG.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Changelog
|
||||
|
||||
## 0.5.0
|
||||
- **Added**: Swift Package Manager support;
|
||||
- **Updated**: openvpn3 library – 3.5.4 version;
|
||||
- **Fixed**: Network issue when adapter used in macOS projects.
|
||||
@@ -1,6 +0,0 @@
|
||||
#include "Framework.xcconfig"
|
||||
|
||||
ONLY_ACTIVE_ARCH = YES
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DEBUG
|
||||
BITCODE_GENERATION_MODE = marker
|
||||
@@ -1,16 +0,0 @@
|
||||
PRODUCT_NAME = OpenVPNAdapter
|
||||
PRODUCT_BUNDLE_IDENTIFIER = me.ss-abramchuk.openvpn-adapter
|
||||
INFOPLIST_FILE = Configuration/Info-Framework.plist
|
||||
MODULEMAP_FILE = Configuration/OpenVPNAdapter.modulemap
|
||||
DYLIB_CURRENT_VERSION = $(CURRENT_PROJECT_VERSION)
|
||||
APPLICATION_EXTENSION_API_ONLY = YES
|
||||
CLANG_CXX_LANGUAGE_STANDARD = gnu++14
|
||||
CLANG_CXX_LIBRARY = libc++
|
||||
VENDORS_DIR = $(PROJECT_DIR)/Sources/OpenVPNAdapter/Libraries/Vendors
|
||||
HEADER_SEARCH_PATHS = "$(VENDORS_DIR)/asio/asio/include" "$(VENDORS_DIR)/lz4/include" "$(VENDORS_DIR)/mbedtls/include" "$(VENDORS_DIR)/openvpn"
|
||||
LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*] = "$(VENDORS_DIR)/lz4/lib/sim" "$(VENDORS_DIR)/mbedtls/lib/sim"
|
||||
LIBRARY_SEARCH_PATHS[sdk=iphoneos*] = "$(VENDORS_DIR)/lz4/lib/ios" "$(VENDORS_DIR)/mbedtls/lib/ios"
|
||||
LIBRARY_SEARCH_PATHS[sdk=macosx*] = "$(VENDORS_DIR)/lz4/lib/macos" "$(VENDORS_DIR)/mbedtls/lib/macos"
|
||||
OTHER_LDFLAGS = -lmbedtls -lmbedx509 -lmbedcrypto -llz4
|
||||
OTHER_CPLUSPLUSFLAGS = $(OTHER_CFLAGS) -DUSE_ASIO -DUSE_ASIO_THREADLOCAL -DASIO_STANDALONE -DASIO_NO_DEPRECATED -DHAVE_LZ4 -DUSE_MBEDTLS -DOPENVPN_FORCE_TUN_NULL -DUSE_TUN_BUILDER
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = NO
|
||||
1
Configuration/LZ4.xcconfig
Normal file
1
Configuration/LZ4.xcconfig
Normal file
@@ -0,0 +1 @@
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) XXH_NAMESPACE=LZ4_
|
||||
3
Configuration/OpenVPNAdapter.xcconfig
Normal file
3
Configuration/OpenVPNAdapter.xcconfig
Normal file
@@ -0,0 +1,3 @@
|
||||
MODULEMAP_FILE = Sources/OpenVPNAdapter/module.modulemap
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) USE_ASIO
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = NO
|
||||
2
Configuration/OpenVPNClient.xcconfig
Normal file
2
Configuration/OpenVPNClient.xcconfig
Normal file
@@ -0,0 +1,2 @@
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) USE_ASIO USE_ASIO_THREADLOCAL ASIO_STANDALONE ASIO_NO_DEPRECATED ASIO_HAS_STD_STRING_VIEW USE_MBEDTLS HAVE_LZ4 OPENVPN_FORCE_TUN_NULL USE_TUN_BUILDER
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = NO
|
||||
@@ -1,24 +1,31 @@
|
||||
SUPPORTED_PLATFORMS = iphoneos iphonesimulator macosx
|
||||
TARGETED_DEVICE_FAMILY = 1,2
|
||||
|
||||
HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/Sources/OpenVPNAdapter/include $(SRCROOT)/Sources/OpenVPNClient/include $(SRCROOT)/Sources/LZ4/include $(SRCROOT)/Sources/mbedTLS/include $(SRCROOT)/Sources/ASIO/asio/include $(SRCROOT)/Sources/OpenVPN3
|
||||
|
||||
CLANG_CXX_LANGUAGE_STANDARD = gnu++14
|
||||
CLANG_CXX_LIBRARY = libc++
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// iOS-specific settings
|
||||
//
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0
|
||||
|
||||
SDKROOT[arch=arm64] = iphoneos
|
||||
SDKROOT[arch=armv7] = iphoneos
|
||||
SDKROOT[arch=armv7s] = iphoneos
|
||||
|
||||
VALID_ARCHS[sdk=iphoneos*] = arm64 armv7 armv7s
|
||||
VALID_ARCHS[sdk=iphonesimulator*] = i386 x86_64
|
||||
|
||||
LD_RUNPATH_SEARCH_PATHS[sdk=iphoneos*] = @executable_path/Frameworks @loader_path/Frameworks
|
||||
LD_RUNPATH_SEARCH_PATHS[sdk=iphonesimulator*] = @executable_path/Frameworks @loader_path/Frameworks
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// macOS-specific settings
|
||||
//
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
|
||||
VALID_ARCHS[sdk=macosx*] = i386 x86_64
|
||||
SDKROOT[arch=i386] = macosx
|
||||
SDKROOT[arch=x86_64] = macosx
|
||||
|
||||
LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = @executable_path/../Frameworks @loader_path/../Frameworks
|
||||
VALID_ARCHS[sdk=macosx*] = i386 x86_64
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "Framework.xcconfig"
|
||||
|
||||
ONLY_ACTIVE_ARCH = NO
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Owholemodule
|
||||
BITCODE_GENERATION_MODE = bitcode
|
||||
@@ -1,5 +0,0 @@
|
||||
PRODUCT_NAME = OpenVPNAdapterTests
|
||||
PRODUCT_BUNDLE_IDENTIFIER = me.ss-abramchuk.openvpn-adapter.tests
|
||||
INFOPLIST_FILE = Configuration/Info-Tests.plist
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
ONLY_ACTIVE_ARCH = YES
|
||||
1
Configuration/mbedTLS.xcconfig
Normal file
1
Configuration/mbedTLS.xcconfig
Normal file
@@ -0,0 +1 @@
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) MBEDTLS_MD4_C MBEDTLS_RELAXED_X509_DATE _FILE_OFFSET_BITS=64
|
||||
4
NOTICE
4
NOTICE
@@ -4,7 +4,6 @@ Third party libraries used by the OpenVPNAdapter project:
|
||||
|
||||
--------------------------------------------------------------------
|
||||
Dependency: https://github.com/OpenVPN/openvpn3
|
||||
Revision: 3e002c83ce2e9f9f40ddcee750d3cfa664238abe
|
||||
License type: GNU Affero General Public License - Version 3.0
|
||||
--------------------------------------------------------------------
|
||||
OpenVPN Library
|
||||
@@ -675,7 +674,6 @@ For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
|
||||
--------------------------------------------------------------------
|
||||
Dependency: https://github.com/ARMmbed/mbedtls
|
||||
Revision: 72ea31b026e1fc61b01662474aa5125817b968bc
|
||||
License type: Apache License - Version 2.0
|
||||
--------------------------------------------------------------------
|
||||
mbedTLS Library
|
||||
@@ -886,7 +884,6 @@ limitations under the License.
|
||||
|
||||
--------------------------------------------------------------------
|
||||
Dependency: https://github.com/chriskohlhoff/asio
|
||||
Revision: 72ea31b026e1fc61b01662474aa5125817b968bc
|
||||
License type: Boost Software License - Version 1.0
|
||||
--------------------------------------------------------------------
|
||||
ASIO Library
|
||||
@@ -920,7 +917,6 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
--------------------------------------------------------------------
|
||||
Dependency: https://github.com/lz4/lz4
|
||||
Revision: c10863b98e1503af90616ae99725ecd120265dfb
|
||||
License type: BSD 2-Clause License
|
||||
--------------------------------------------------------------------
|
||||
LZ4 Library
|
||||
|
||||
@@ -3,7 +3,7 @@ Pod::Spec.new do |s|
|
||||
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
||||
|
||||
s.name = "OpenVPNAdapter"
|
||||
s.version = "0.1.0"
|
||||
s.version = "0.5.1"
|
||||
s.summary = "Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS."
|
||||
s.description = <<-DESC
|
||||
OpenVPNAdapter is an Objective-C framework that allows to easily configure and establish VPN connection using OpenVPN protocol.
|
||||
@@ -35,116 +35,70 @@ Pod::Spec.new do |s|
|
||||
s.source = { :git => "https://github.com/ss-abramchuk/OpenVPNAdapter.git", :tag => "#{s.version}" }
|
||||
|
||||
|
||||
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
||||
|
||||
framework_path = "Sources/OpenVPNAdapter"
|
||||
vendors_path = "#{framework_path}/Libraries/Vendors"
|
||||
|
||||
s.source_files = "#{framework_path}/*.{h,m,mm}"
|
||||
|
||||
s.public_header_files = "#{framework_path}/*.h"
|
||||
s.private_header_files = [
|
||||
"#{framework_path}/*+Internal.h",
|
||||
"#{framework_path}/OpenVPNReachabilityTracker.h",
|
||||
"#{framework_path}/OpenVPNClient.h",
|
||||
"#{framework_path}/OpenVPNNetworkSettingsBuilder.h",
|
||||
"#{framework_path}/OpenVPNPacket.h",
|
||||
"#{framework_path}/OpenVPNPacketFlowBridge.h",
|
||||
"#{framework_path}/NSError+OpenVPNError.h",
|
||||
"#{framework_path}/NSArray+OpenVPNAdditions.h"
|
||||
]
|
||||
|
||||
s.module_map = "Configuration/OpenVPNAdapter.modulemap"
|
||||
|
||||
|
||||
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
||||
|
||||
s.ios.frameworks = "Foundation", "NetworkExtension", "SystemConfiguration", "UIKit"
|
||||
s.osx.frameworks = "Foundation", "NetworkExtension", "SystemConfiguration"
|
||||
|
||||
s.libraries = "lz4", "mbedcrypto", "mbedtls", "mbedx509"
|
||||
|
||||
|
||||
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
||||
|
||||
s.requires_arc = true
|
||||
s.prefix_header_file = false
|
||||
|
||||
adapter_path = "Sources/OpenVPNAdapter"
|
||||
asio_path = "Sources/ASIO"
|
||||
lz4_path = "Sources/LZ4"
|
||||
mbedtls_path = "Sources/mbedTLS"
|
||||
openvpn_path = "Sources/OpenVPN3"
|
||||
client_path = "Sources/OpenVPNClient"
|
||||
|
||||
s.xcconfig = {
|
||||
"APPLICATION_EXTENSION_API_ONLY" => "YES",
|
||||
"CLANG_CXX_LANGUAGE_STANDARD" => "gnu++14",
|
||||
"CLANG_CXX_LIBRARY" => "libc++",
|
||||
"GCC_WARN_64_TO_32_BIT_CONVERSION" => "NO",
|
||||
"CLANG_WARN_DOCUMENTATION_COMMENTS" => "NO"
|
||||
"CLANG_WARN_DOCUMENTATION_COMMENTS" => "NO",
|
||||
"HEADER_SEARCH_PATHS" => "\"${PODS_TARGET_SRCROOT}/#{asio_path}/asio/include/**\" \"${PODS_TARGET_SRCROOT}/#{mbedtls_path}/include/**\" \"${PODS_TARGET_SRCROOT}/#{openvpn_path}/**\""
|
||||
}
|
||||
|
||||
|
||||
# ――― Subspecs ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
||||
|
||||
s.subspec "lz4" do |lz4|
|
||||
lz4_path = "#{vendors_path}/lz4"
|
||||
s.subspec "OpenVPNAdapter" do |adapter|
|
||||
adapter.source_files = "#{adapter_path}/library/*.{h,m,mm}", "#{adapter_path}/include/*.h"
|
||||
adapter.public_header_files = "#{adapter_path}/include/*.h"
|
||||
|
||||
lz4.preserve_paths = "#{lz4_path}/include/*.h"
|
||||
|
||||
lz4.ios.vendored_libraries = [
|
||||
"#{lz4_path}/lib/ios/liblz4.a"
|
||||
]
|
||||
|
||||
lz4.osx.vendored_libraries = [
|
||||
"#{lz4_path}/lib/macos/liblz4.a"
|
||||
]
|
||||
|
||||
lz4.xcconfig = {
|
||||
"HEADER_SEARCH_PATHS" => "${PODS_TARGET_SRCROOT}/#{lz4_path}/include/**"
|
||||
}
|
||||
adapter.compiler_flags = "-DUSE_ASIO"
|
||||
end
|
||||
|
||||
s.subspec "mbedtls" do |mbedtls|
|
||||
mbedtls_path = "#{vendors_path}/mbedtls"
|
||||
|
||||
mbedtls.preserve_paths = "#{mbedtls_path}/include/**/*.h"
|
||||
|
||||
mbedtls.ios.vendored_libraries = [
|
||||
"#{mbedtls_path}/lib/ios/libmbedcrypto.a",
|
||||
"#{mbedtls_path}/lib/ios/libmbedtls.a",
|
||||
"#{mbedtls_path}/lib/ios/libmbedx509.a"
|
||||
]
|
||||
|
||||
mbedtls.osx.vendored_libraries = [
|
||||
"#{mbedtls_path}/lib/macos/libmbedcrypto.a",
|
||||
"#{mbedtls_path}/lib/macos/libmbedtls.a",
|
||||
"#{mbedtls_path}/lib/macos/libmbedx509.a"
|
||||
]
|
||||
|
||||
mbedtls.xcconfig = {
|
||||
"HEADER_SEARCH_PATHS" => "${PODS_TARGET_SRCROOT}/#{mbedtls_path}/include/**"
|
||||
}
|
||||
end
|
||||
|
||||
s.subspec "asio" do |asio|
|
||||
asio_path = "#{vendors_path}/asio"
|
||||
|
||||
s.subspec "ASIO" do |asio|
|
||||
asio.preserve_paths = "#{asio_path}/asio/include/**/*.{hpp,ipp}"
|
||||
|
||||
asio.xcconfig = {
|
||||
"HEADER_SEARCH_PATHS" => "${PODS_TARGET_SRCROOT}/#{asio_path}/asio/include/**"
|
||||
}
|
||||
end
|
||||
|
||||
s.subspec "openvpn" do |openvpn|
|
||||
openvpn_path = "#{vendors_path}/openvpn"
|
||||
s.subspec "LZ4" do |lz4|
|
||||
lz4.source_files = "#{lz4_path}/lib/*.{h,c}",
|
||||
lz4.private_header_files = "#{lz4_path}/lib/*.{h,c}"
|
||||
|
||||
openvpn.source_files = "#{openvpn_path}/client/*.{hpp,cpp}"
|
||||
openvpn.private_header_files = "#{openvpn_path}/client/*.hpp"
|
||||
lz4.compiler_flags = "-DXXH_NAMESPACE=LZ4_"
|
||||
end
|
||||
|
||||
openvpn.preserve_paths = "#{openvpn_path}/openvpn/**/*.hpp"
|
||||
s.subspec "mbedTLS" do |mbedtls|
|
||||
mbedtls.source_files = "#{mbedtls_path}/library/*.{c}"
|
||||
mbedtls.preserve_paths = "#{mbedtls_path}/include/**/*.{h}"
|
||||
|
||||
openvpn.compiler_flags = "-x objective-c++"
|
||||
mbedtls.compiler_flags = "-DMBEDTLS_MD4_C", "-DMBEDTLS_RELAXED_X509_DATE", "-D_FILE_OFFSET_BITS=64"
|
||||
end
|
||||
|
||||
openvpn.xcconfig = {
|
||||
"HEADER_SEARCH_PATHS" => "${PODS_TARGET_SRCROOT}/#{openvpn_path}/**",
|
||||
"OTHER_CPLUSPLUSFLAGS" => "$(OTHER_CFLAGS) -DUSE_ASIO -DUSE_ASIO_THREADLOCAL -DASIO_STANDALONE -DASIO_NO_DEPRECATED -DHAVE_LZ4 -DUSE_MBEDTLS -DOPENVPN_FORCE_TUN_NULL -DUSE_TUN_BUILDER"
|
||||
}
|
||||
s.subspec "OpenVPN3" do |openvpn|
|
||||
openvpn.preserve_paths = "#{openvpn_path}/openvpn/**/*.hpp", "#{openvpn_path}/client/*.{hpp,cpp}"
|
||||
end
|
||||
|
||||
s.subspec "OpenVPNClient" do |client|
|
||||
client.source_files = "#{client_path}/library/*.{mm}", "#{client_path}/include/*.{hpp}"
|
||||
client.private_header_files = "#{client_path}/include/*.{hpp}"
|
||||
|
||||
client.compiler_flags = "-x objective-c++", "-DUSE_ASIO", "-DUSE_ASIO_THREADLOCAL", "-DASIO_STANDALONE", "-DASIO_NO_DEPRECATED", "-DASIO_HAS_STD_STRING_VIEW", "-DHAVE_LZ4", "-DUSE_MBEDTLS", "-DOPENVPN_FORCE_TUN_NULL", "-DUSE_TUN_BUILDER"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1.0</string>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
26
OpenVPNAdapter.xcodeproj/OpenVPNAdapter_Info.plist
Normal file
26
OpenVPNAdapter.xcodeproj/OpenVPNAdapter_Info.plist
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
26
OpenVPNAdapter.xcodeproj/OpenVPNClient_Info.plist
Normal file
26
OpenVPNAdapter.xcodeproj/OpenVPNClient_Info.plist
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
26
OpenVPNAdapter.xcodeproj/mbedTLS_Info.plist
Normal file
26
OpenVPNAdapter.xcodeproj/mbedTLS_Info.plist
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,6 @@
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:/Users/ss.abramchuk/Sources.localized/open-source.localized/openvpn-adapter/OpenVPNAdapter.xcodeproj">
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
</Workspace>
|
||||
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict/>
|
||||
</plist>
|
||||
<dict>
|
||||
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,100 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0930"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9D2ABD81EA20F99007EDF9D"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter macOS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
codeCoverageEnabled = "YES"
|
||||
shouldUseLaunchSchemeArgsEnv = "NO">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9D2ABF21EA212A3007EDF9D"
|
||||
BuildableName = "OpenVPNAdapterTests.xctest"
|
||||
BlueprintName = "OpenVPNAdapter macOS Tests"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9D2ABD81EA20F99007EDF9D"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter macOS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9D2ABD81EA20F99007EDF9D"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter macOS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9D2ABD81EA20F99007EDF9D"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter macOS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0930"
|
||||
LastUpgradeVersion = "9999"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,9 +14,51 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9BB475B1E71663A00F3F98C"
|
||||
BlueprintIdentifier = "OpenVPNAdapter::mbedTLS"
|
||||
BuildableName = "mbedTLS.framework"
|
||||
BlueprintName = "mbedTLS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "OpenVPNAdapter::LZ4"
|
||||
BuildableName = "LZ4.framework"
|
||||
BlueprintName = "LZ4"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "OpenVPNAdapter::OpenVPNClient"
|
||||
BuildableName = "OpenVPNClient.framework"
|
||||
BlueprintName = "OpenVPNClient"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "OpenVPNAdapter::OpenVPNAdapter"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter iOS"
|
||||
BlueprintName = "OpenVPNAdapter"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
@@ -26,31 +68,24 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
codeCoverageEnabled = "YES"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9BB478D1E71821A00F3F98C"
|
||||
BlueprintIdentifier = "C97E5FCC24123F2E005C2EBC"
|
||||
BuildableName = "OpenVPNAdapterTests.xctest"
|
||||
BlueprintName = "OpenVPNAdapter iOS Tests"
|
||||
BlueprintName = "OpenVPNAdapterTests"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
<SkippedTests>
|
||||
<Test
|
||||
Identifier = "OpenVPNReachabilityTests">
|
||||
</Test>
|
||||
</SkippedTests>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9BB475B1E71663A00F3F98C"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter iOS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
@@ -62,17 +97,6 @@
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9BB475B1E71663A00F3F98C"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter iOS"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
@@ -83,9 +107,9 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9BB475B1E71663A00F3F98C"
|
||||
BuildableName = "OpenVPNAdapter.framework"
|
||||
BlueprintName = "OpenVPNAdapter iOS"
|
||||
BlueprintIdentifier = "OpenVPNAdapter::OpenVPNClient"
|
||||
BuildableName = "OpenVPNClient.framework"
|
||||
BlueprintName = "OpenVPNClient"
|
||||
ReferencedContainer = "container:OpenVPNAdapter.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
67
Package.swift
Normal file
67
Package.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
// swift-tools-version:5.1
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "OpenVPNAdapter",
|
||||
platforms: [
|
||||
.iOS("9.0"),
|
||||
.macOS("10.11"),
|
||||
],
|
||||
products: [
|
||||
.library(name: "OpenVPNAdapter", type: .static, targets: ["OpenVPNAdapter"]),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "OpenVPNAdapter",
|
||||
dependencies: [
|
||||
.target(name: "mbedTLS"),
|
||||
.target(name: "OpenVPNClient")
|
||||
],
|
||||
sources: ["library"],
|
||||
cxxSettings: [
|
||||
.headerSearchPath("../ASIO/asio/include"),
|
||||
.headerSearchPath("../OpenVPN3"),
|
||||
.define("USE_ASIO")
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "LZ4",
|
||||
sources: ["lib"],
|
||||
cSettings: [
|
||||
.define("XXH_NAMESPACE", to: "LZ4_")
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "mbedTLS",
|
||||
sources: ["library"],
|
||||
cSettings: [
|
||||
.define("MBEDTLS_MD4_C"),
|
||||
.define("MBEDTLS_RELAXED_X509_DATE"),
|
||||
.define("_FILE_OFFSET_BITS", to: "64"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "OpenVPNClient",
|
||||
dependencies: [
|
||||
.target(name: "LZ4"),
|
||||
.target(name: "mbedTLS")
|
||||
],
|
||||
sources: ["library"],
|
||||
cxxSettings: [
|
||||
.headerSearchPath("../ASIO/asio/include"),
|
||||
.headerSearchPath("../OpenVPN3"),
|
||||
.define("USE_ASIO"),
|
||||
.define("USE_ASIO_THREADLOCAL"),
|
||||
.define("ASIO_STANDALONE"),
|
||||
.define("ASIO_NO_DEPRECATED"),
|
||||
.define("ASIO_HAS_STD_STRING_VIEW"),
|
||||
.define("USE_MBEDTLS"),
|
||||
.define("HAVE_LZ4"),
|
||||
.define("OPENVPN_FORCE_TUN_NULL"),
|
||||
.define("USE_TUN_BUILDER")
|
||||
]
|
||||
)
|
||||
],
|
||||
cxxLanguageStandard: .gnucxx14
|
||||
)
|
||||
36
README.md
36
README.md
@@ -3,8 +3,10 @@
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Overview
|
||||
@@ -16,7 +18,7 @@ The framework is designed to use in conjunction with [`NetworkExtension`](https:
|
||||
|
||||
### Requirements
|
||||
- iOS 9.0+ or macOS 10.11+
|
||||
- Xcode 9.0+
|
||||
- Xcode 11.0+
|
||||
|
||||
### Carthage
|
||||
To install OpenVPNAdapter with Carthage, add the following line to your `Cartfile`.
|
||||
@@ -32,16 +34,16 @@ To install OpenVPNAdapter with Cocoapods, add the following lines to your `Podfi
|
||||
|
||||
```ruby
|
||||
target 'Your Target Name' do
|
||||
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
|
||||
use_frameworks!
|
||||
|
||||
# Pods for iOSOpenVPNTunnel
|
||||
pod 'OpenVPNAdapter', '~> 0.1'
|
||||
pod 'OpenVPNAdapter', :git => 'https://github.com/ss-abramchuk/OpenVPNAdapter.git', :tag => '0.5.1'
|
||||
end
|
||||
```
|
||||
|
||||
And run `$ pod install`.
|
||||
|
||||
### Swift Package Manager
|
||||
Add `OpenVPNAdapter` package to your project using File > Swift Packages > Add Package Dependency menu. Xcode 11 will automatically retrieve all necessary dependencies. In addition to that you need to add `SystemConfiguration` framework to the Frameworks and Libraries. If you work on iOS project add `UIKit` as well.
|
||||
|
||||
## Usage
|
||||
At first, you need to add a Packet Tunnel Provider extension to the project and configure provision profiles for both the container app and the extension. There are official documentation and many tutorials describing how to do it so we won't dwell on this in detail.
|
||||
|
||||
@@ -56,7 +58,7 @@ Then we need to create or load a VPN profile. [`NETunnelProviderManager`](https:
|
||||
```swift
|
||||
NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
|
||||
guard error == nil else {
|
||||
// Handle an occured error
|
||||
// Handle an occurred error
|
||||
return
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ The next step is to provide VPN settings to the instance of [`NETunnelProviderMa
|
||||
```swift
|
||||
self.providerManager?.loadFromPreferences(completionHandler: { (error) in
|
||||
guard error == nil else {
|
||||
// Handle an occured error
|
||||
// Handle an occurred error
|
||||
return
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ self.providerManager?.loadFromPreferences(completionHandler: { (error) in
|
||||
// Save configuration in the Network Extension preferences
|
||||
self.providerManager?.saveToPreferences(completionHandler: { (error) in
|
||||
if let error = error {
|
||||
// Handle an occured error
|
||||
// Handle an occurred error
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -121,14 +123,14 @@ Start VPN by calling the following code.
|
||||
```swift
|
||||
self.providerManager?.loadFromPreferences(completionHandler: { (error) in
|
||||
guard error == nil else {
|
||||
// Handle an occured error
|
||||
// Handle an occurred error
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
try self.providerManager?.connection.startVPNTunnel()
|
||||
} catch {
|
||||
// Handle an occured error
|
||||
// Handle an occurred error
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -180,6 +182,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
// Additional parameters as key:value pairs may be provided here
|
||||
]
|
||||
|
||||
// Add this line if you want to keep TUN interface active during pauses or reconnections
|
||||
configuration.tunPersist = true
|
||||
|
||||
// Apply OpenVPN configuration
|
||||
let properties: OpenVPNProperties
|
||||
do {
|
||||
@@ -250,7 +255,12 @@ extension PacketTunnelProvider: OpenVPNAdapterDelegate {
|
||||
// `OpenVPNAdapterPacketFlow` method signatures are similar to `NEPacketTunnelFlow` so
|
||||
// you can just extend that class to adopt `OpenVPNAdapterPacketFlow` protocol and
|
||||
// send `self.packetFlow` to `completionHandler` callback.
|
||||
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
|
||||
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
|
||||
// In order to direct all DNS queries first to the VPN DNS servers before the primary DNS servers
|
||||
// send empty string to NEDNSSettings.matchDomains
|
||||
networkSettings?.dnsSettings?.matchDomains = [""]
|
||||
|
||||
// Specify the network settings for the current tunneling session.
|
||||
setTunnelNetworkSettings(settings) { (error) in
|
||||
completionHandler(error == nil ? self.packetFlow : nil)
|
||||
}
|
||||
@@ -323,7 +333,7 @@ extension NEPacketTunnelFlow: OpenVPNAdapterPacketFlow {}
|
||||
Any contributions and suggestions are welcome! But before creating a PR or an issue please read the [Contribution Guide](CONTRIBUTING.md).
|
||||
|
||||
## Acknowledgments
|
||||
Special thanks goes to @JonathanDowning for great help in development of this project and bug fixing.
|
||||
Special thanks goes to [@JonathanDowning](https://github.com/JonathanDowning) for great help in development of this project and bug fixing.
|
||||
|
||||
## License
|
||||
OpenVPNAdapter is available under the AGPLv3 license. See the [LICENSE](LICENSE) file for more info. Also this project has a few dependencies:
|
||||
|
||||
19
Scripts/apply_patches.sh
Executable file
19
Scripts/apply_patches.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
. functions.sh
|
||||
|
||||
ASIO_SRC_DIR="../Sources/ASIO"
|
||||
ASIO_PATCH_DIR="../Sources/OpenVPN3/deps/asio/patches"
|
||||
|
||||
MBEDTLS_SRC_DIR="../Sources/mbedTLS"
|
||||
MBEDTLS_PATCH_DIR="../Sources/OpenVPN3/deps/mbedtls/patches"
|
||||
|
||||
if [ "$1" = "--reverse" ]; then
|
||||
reverse_patches ${ASIO_SRC_DIR} ${ASIO_PATCH_DIR}
|
||||
reverse_patches ${MBEDTLS_SRC_DIR} ${MBEDTLS_PATCH_DIR}
|
||||
else
|
||||
apply_patches ${ASIO_SRC_DIR} ${ASIO_PATCH_DIR}
|
||||
apply_patches ${MBEDTLS_SRC_DIR} ${MBEDTLS_PATCH_DIR}
|
||||
fi
|
||||
@@ -1,64 +0,0 @@
|
||||
# Your OpenVPN username
|
||||
if ENV["OPENVPN_USERNAME"].nil?
|
||||
ENV["OPENVPN_USERNAME"] = "Username"
|
||||
end
|
||||
|
||||
# Your OpenVPN password
|
||||
if ENV["OPENVPN_PASSWORD"].nil?
|
||||
ENV["OPENVPN_PASSWORD"] = "Password"
|
||||
end
|
||||
|
||||
# Your OpenVPN configuration
|
||||
if ENV["OPENVPN_CONFIGURATION"].nil?
|
||||
ENV["OPENVPN_CONFIGURATION"] = <<~END
|
||||
client
|
||||
dev tun
|
||||
proto udp
|
||||
|
||||
remote X.X.X.X 1194
|
||||
|
||||
remote-random
|
||||
resolv-retry infinite
|
||||
nobind
|
||||
cipher AES-256-CBC
|
||||
auth SHA512
|
||||
comp-lzo no
|
||||
verb 3
|
||||
|
||||
tun-mtu 1500
|
||||
tun-mtu-extra 32
|
||||
mssfix 1450
|
||||
persist-key
|
||||
persist-tun
|
||||
|
||||
reneg-sec 0
|
||||
|
||||
remote-cert-tls server
|
||||
auth-user-pass
|
||||
pull
|
||||
fast-io
|
||||
|
||||
<ca>
|
||||
-----BEGIN CERTIFICATE-----
|
||||
...
|
||||
-----END CERTIFICATE-----
|
||||
</ca>
|
||||
|
||||
key-direction 1
|
||||
|
||||
<tls-auth>
|
||||
# 2048 bit OpenVPN static key
|
||||
-----BEGIN OpenVPN Static key V1-----
|
||||
...
|
||||
-----END OpenVPN Static key V1-----
|
||||
</tls-auth>
|
||||
END
|
||||
end
|
||||
|
||||
if ENV["OPENVPN_REMOTE_HOST"].nil?
|
||||
ENV["OPENVPN_REMOTE_HOST"] = "Remote Host Address"
|
||||
end
|
||||
|
||||
if ENV["OPENVPN_REMOTE_PORT"].nil?
|
||||
ENV["OPENVPN_REMOTE_PORT"] = "Remote Host Port"
|
||||
end
|
||||
@@ -1,35 +0,0 @@
|
||||
environment_file = File.join(ENV["SRCROOT"], "Scripts", "environment.rb")
|
||||
if File.exist?(environment_file)
|
||||
require "#{environment_file}"
|
||||
end
|
||||
|
||||
require "erb"
|
||||
|
||||
if ENV["OPENVPN_USERNAME"].nil? || ENV["OPENVPN_PASSWORD"].nil? || ENV["OPENVPN_CONFIGURATION"].nil?
|
||||
puts "warning: VPN profile data is missing, you need to fill VPNProfile.swift manually."
|
||||
exit(true)
|
||||
end
|
||||
|
||||
template_file = File.join(ENV["SRCROOT"], "Scripts", "vpn_profile_template.erb")
|
||||
unless File.exist?(template_file)
|
||||
puts "error: Template file does not exist."
|
||||
exit(false)
|
||||
end
|
||||
|
||||
output_file = File.join(ENV["SRCROOT"], "Tests", "VPNProfile.swift")
|
||||
unless File.exist?(output_file)
|
||||
puts "error: Output file does not exist."
|
||||
exit(false)
|
||||
end
|
||||
|
||||
OPENVPN_USERNAME = ENV["OPENVPN_USERNAME"]
|
||||
OPENVPN_PASSWORD = ENV["OPENVPN_PASSWORD"]
|
||||
OPENVPN_CONFIGURATION = ENV["OPENVPN_CONFIGURATION"]
|
||||
OPENVPN_REMOTE_HOST = ENV["OPENVPN_REMOTE_HOST"]
|
||||
OPENVPN_REMOTE_PORT = ENV["OPENVPN_REMOTE_PORT"]
|
||||
|
||||
template_content = File.read(template_file)
|
||||
erb_template = ERB.new(template_content, nil, ">")
|
||||
|
||||
result = erb_template.result
|
||||
File.write(output_file, result)
|
||||
37
Scripts/functions.sh
Normal file
37
Scripts/functions.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
function apply_patches()
|
||||
{
|
||||
DEP_SRC_DIR=$1
|
||||
DEP_PATCH_DIR=$2
|
||||
|
||||
CURRENT_DIR=$(pwd)
|
||||
|
||||
pushd ${CURRENT_DIR}
|
||||
|
||||
cd /tmp
|
||||
|
||||
for file in ${CURRENT_DIR}/${DEP_PATCH_DIR}/*.patch; do
|
||||
echo Applying patch: $file
|
||||
git apply --directory ${CURRENT_DIR}/${DEP_SRC_DIR} --unsafe-path $file
|
||||
done
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
function reverse_patches()
|
||||
{
|
||||
DEP_SRC_DIR=$1
|
||||
DEP_PATCH_DIR=$2
|
||||
|
||||
CURRENT_DIR=$(pwd)
|
||||
|
||||
pushd ${CURRENT_DIR}
|
||||
|
||||
cd /tmp
|
||||
|
||||
for file in ${CURRENT_DIR}/${DEP_PATCH_DIR}/*.patch; do
|
||||
echo Reverse patch: $file
|
||||
git apply --reverse --directory ${CURRENT_DIR}/${DEP_SRC_DIR} --unsafe-path $file
|
||||
done
|
||||
|
||||
popd
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// VPNProfile.swift
|
||||
// OpenVPNAdapter
|
||||
//
|
||||
// Created by Sergey Abramchuk on 27/09/2018.
|
||||
//
|
||||
// Do not commit changes of this file to the repo!
|
||||
|
||||
import Foundation
|
||||
|
||||
struct VPNProfile {
|
||||
|
||||
static let username: String = "<%= OPENVPN_USERNAME %>"
|
||||
static let password: String = "<%= OPENVPN_PASSWORD %>"
|
||||
|
||||
static let configuration: String = """
|
||||
<% OPENVPN_CONFIGURATION.each_line do |line| %>
|
||||
<%= line %>
|
||||
<% end %>
|
||||
"""
|
||||
|
||||
static let remoteHost: String = "<%= OPENVPN_REMOTE_HOST %>"
|
||||
static let remotePort: Int = <%= OPENVPN_REMOTE_PORT %>
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -1,4 +1,4 @@
|
||||
asio version 1.12.0
|
||||
Released Sunday, 04 March 2018.
|
||||
asio version 1.14.0
|
||||
Released Sunday, 14 April 2019.
|
||||
|
||||
See doc/index.html for API documentation and a tutorial.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -281,7 +281,7 @@ sub copy_source_file
|
||||
$line =~ s/asio::/boost::asio::/g if !$is_xsl;
|
||||
print_line($output, $line, $from, $lineno);
|
||||
}
|
||||
elsif ($line =~ /} \/\/ namespace std/)
|
||||
elsif ($line =~ /^} \/\/ namespace std/)
|
||||
{
|
||||
print_line($output, "} // namespace system", $from, $lineno);
|
||||
print_line($output, "} // namespace boost", $from, $lineno);
|
||||
@@ -365,6 +365,8 @@ sub copy_include_files
|
||||
"include/asio",
|
||||
"include/asio/detail",
|
||||
"include/asio/detail/impl",
|
||||
"include/asio/experimental",
|
||||
"include/asio/experimental/impl",
|
||||
"include/asio/generic",
|
||||
"include/asio/generic/detail",
|
||||
"include/asio/generic/detail/impl",
|
||||
@@ -528,8 +530,15 @@ sub copy_examples
|
||||
"src/examples/cpp11/local",
|
||||
"src/examples/cpp11/multicast",
|
||||
"src/examples/cpp11/nonblocking",
|
||||
"src/examples/cpp11/operations",
|
||||
"src/examples/cpp11/socks4",
|
||||
"src/examples/cpp11/spawn",
|
||||
"src/examples/cpp14/executors");
|
||||
"src/examples/cpp11/ssl",
|
||||
"src/examples/cpp11/timeouts",
|
||||
"src/examples/cpp11/timers",
|
||||
"src/examples/cpp14/executors",
|
||||
"src/examples/cpp14/operations",
|
||||
"src/examples/cpp17/coroutines_ts");
|
||||
|
||||
our $boost_dir;
|
||||
foreach my $dir (@dirs)
|
||||
@@ -1,4 +1,4 @@
|
||||
AC_INIT(asio, [1.12.0])
|
||||
AC_INIT(asio, [1.14.0])
|
||||
AC_CONFIG_SRCDIR(include/asio.hpp)
|
||||
AM_MAINTAINER_MODE
|
||||
AM_INIT_AUTOMAKE([tar-ustar])
|
||||
@@ -17,20 +17,12 @@ AC_ARG_WITH(boost,
|
||||
if test "${withval}" = no; then
|
||||
STANDALONE="yes"
|
||||
else
|
||||
CPPFLAGS="$CPPFLAGS -I${withval} -DBOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING"
|
||||
CPPFLAGS="$CPPFLAGS -I${withval} -DASIO_ENABLE_BOOST -DBOOST_CHRONO_HEADER_ONLY -DBOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING"
|
||||
LIBS="$LIBS -L${withval}/stage/lib"
|
||||
fi
|
||||
],
|
||||
[
|
||||
BOOSTDIR=`ls -1d ../boost_*_*_*/ 2>/dev/null | sort -t "_" -k 2nr -k 3nr -k 4nr | head -n 1 | sed -e 's/\/$//'`
|
||||
if test "${BOOSTDIR}" != ""; then
|
||||
BOOSTDIR="`pwd`/${BOOSTDIR}"
|
||||
if test -d "${BOOSTDIR}"; then
|
||||
echo "using automatically detected boost from ${BOOSTDIR}"
|
||||
CPPFLAGS="$CPPFLAGS -I${BOOSTDIR} -DBOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING"
|
||||
LIBS="$LIBS -L${BOOSTDIR}/stage/lib"
|
||||
fi
|
||||
fi
|
||||
STANDALONE="yes"
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(separate-compilation,
|
||||
@@ -50,6 +42,7 @@ if test "$STANDALONE" != yes; then
|
||||
[
|
||||
echo "Can't find boost headers. Please check the location of the boost"
|
||||
echo "distribution and rerun configure using the --with-boost=DIR option."
|
||||
echo "Alternatively, run with --without-boost to enable standalone build."
|
||||
exit 1
|
||||
],[])
|
||||
fi
|
||||
@@ -101,7 +94,7 @@ case $host in
|
||||
WINDOWS=yes
|
||||
;;
|
||||
*-pc-cygwin*)
|
||||
CXXFLAGS="$CXXFLAGS -D__USE_W32_SOCKETS -D_WIN32_WINNT=0x0501"
|
||||
CXXFLAGS="$CXXFLAGS -D__USE_W32_SOCKETS -D_WIN32_WINNT=0x0601"
|
||||
LIBS="$LIBS -lws2_32 -lmswsock"
|
||||
WINDOWS=yes
|
||||
;;
|
||||
@@ -117,13 +110,14 @@ case $host in
|
||||
CXXFLAGS="$CXXFLAGS -pthread"
|
||||
LDFLAGS="$LDFLAGS -pthread"
|
||||
;;
|
||||
*-*-haiku*)
|
||||
CXXFLAGS="$CXXFLAGS -lnetwork"
|
||||
LDFLAGS="$LDFLAGS -lnetwork"
|
||||
|
||||
esac
|
||||
|
||||
if test "$GXX" = yes; then
|
||||
CXXFLAGS="$CXXFLAGS -ftemplate-depth-256"
|
||||
if test "$STANDALONE" = yes; then
|
||||
CPPFLAGS="-std=c++0x $CPPFLAGS"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$STANDALONE" = yes; then
|
||||
@@ -134,6 +128,37 @@ if test "$SEPARATE_COMPILATION" = yes; then
|
||||
CPPFLAGS="$CPPFLAGS -DASIO_SEPARATE_COMPILATION"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([whether C++11 is enabled])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#if __cplusplus < 201103L]]
|
||||
[[#error C++11 not available]]
|
||||
[[#endif]])],
|
||||
[AC_MSG_RESULT([yes])
|
||||
HAVE_CXX11=yes;],
|
||||
[AC_MSG_RESULT([no])
|
||||
HAVE_CXX11=no;])
|
||||
|
||||
AC_MSG_CHECKING([whether C++14 is enabled])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#if __cplusplus < 201402L]]
|
||||
[[#error C++14 not available]]
|
||||
[[#endif]])],
|
||||
[AC_MSG_RESULT([yes])
|
||||
HAVE_CXX14=yes;],
|
||||
[AC_MSG_RESULT([no])
|
||||
HAVE_CXX14=no;])
|
||||
|
||||
if test "$GXX" = yes; then
|
||||
if test "$STANDALONE" = yes; then
|
||||
if test "$HAVE_CXX11" = no; then
|
||||
HAVE_CXX11=yes
|
||||
CPPFLAGS="-std=c++0x $CPPFLAGS"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(STANDALONE,test x$STANDALONE = xyes)
|
||||
|
||||
AM_CONDITIONAL(SEPARATE_COMPILATION,test x$SEPARATE_COMPILATION = xyes)
|
||||
@@ -142,6 +167,10 @@ AM_CONDITIONAL(HAVE_BOOST_COROUTINE,test x$HAVE_BOOST_COROUTINE = xyes)
|
||||
|
||||
AM_CONDITIONAL(WINDOWS_TARGET,test x$WINDOWS != xno)
|
||||
|
||||
AM_CONDITIONAL(HAVE_CXX11,test x$HAVE_CXX11 = xyes)
|
||||
|
||||
AM_CONDITIONAL(HAVE_CXX14,test x$HAVE_CXX14 = xyes)
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
include/Makefile
|
||||
@@ -149,4 +178,5 @@ AC_OUTPUT([
|
||||
src/tests/Makefile
|
||||
src/examples/cpp03/Makefile
|
||||
src/examples/cpp11/Makefile
|
||||
src/examples/cpp14/Makefile])
|
||||
src/examples/cpp14/Makefile
|
||||
src/examples/cpp17/Makefile])
|
||||
@@ -3,6 +3,7 @@ nobase_include_HEADERS = \
|
||||
asio/associated_allocator.hpp \
|
||||
asio/associated_executor.hpp \
|
||||
asio/async_result.hpp \
|
||||
asio/awaitable.hpp \
|
||||
asio/basic_datagram_socket.hpp \
|
||||
asio/basic_deadline_timer.hpp \
|
||||
asio/basic_io_object.hpp \
|
||||
@@ -27,13 +28,14 @@ nobase_include_HEADERS = \
|
||||
asio/buffered_write_stream.hpp \
|
||||
asio/buffer.hpp \
|
||||
asio/buffers_iterator.hpp \
|
||||
asio/co_spawn.hpp \
|
||||
asio/completion_condition.hpp \
|
||||
asio/compose.hpp \
|
||||
asio/connect.hpp \
|
||||
asio/coroutine.hpp \
|
||||
asio/datagram_socket_service.hpp \
|
||||
asio/deadline_timer.hpp \
|
||||
asio/deadline_timer_service.hpp \
|
||||
asio/defer.hpp \
|
||||
asio/detached.hpp \
|
||||
asio/detail/array_fwd.hpp \
|
||||
asio/detail/array.hpp \
|
||||
asio/detail/assert.hpp \
|
||||
@@ -64,10 +66,12 @@ nobase_include_HEADERS = \
|
||||
asio/detail/epoll_reactor.hpp \
|
||||
asio/detail/eventfd_select_interrupter.hpp \
|
||||
asio/detail/event.hpp \
|
||||
asio/detail/executor_function.hpp \
|
||||
asio/detail/executor_op.hpp \
|
||||
asio/detail/fd_set_adapter.hpp \
|
||||
asio/detail/fenced_block.hpp \
|
||||
asio/detail/functional.hpp \
|
||||
asio/detail/future.hpp \
|
||||
asio/detail/gcc_arm_fenced_block.hpp \
|
||||
asio/detail/gcc_hppa_fenced_block.hpp \
|
||||
asio/detail/gcc_sync_fenced_block.hpp \
|
||||
@@ -131,6 +135,8 @@ nobase_include_HEADERS = \
|
||||
asio/detail/impl/win_thread.ipp \
|
||||
asio/detail/impl/win_tss_ptr.ipp \
|
||||
asio/detail/io_control.hpp \
|
||||
asio/detail/io_object_executor.hpp \
|
||||
asio/detail/io_object_impl.hpp \
|
||||
asio/detail/is_buffer_sequence.hpp \
|
||||
asio/detail/is_executor.hpp \
|
||||
asio/detail/keyword_tss_ptr.hpp \
|
||||
@@ -140,6 +146,7 @@ nobase_include_HEADERS = \
|
||||
asio/detail/macos_fenced_block.hpp \
|
||||
asio/detail/memory.hpp \
|
||||
asio/detail/mutex.hpp \
|
||||
asio/detail/non_const_lvalue.hpp \
|
||||
asio/detail/noncopyable.hpp \
|
||||
asio/detail/null_event.hpp \
|
||||
asio/detail/null_fenced_block.hpp \
|
||||
@@ -284,8 +291,8 @@ nobase_include_HEADERS = \
|
||||
asio/error_code.hpp \
|
||||
asio/error.hpp \
|
||||
asio/execution_context.hpp \
|
||||
asio/executor_work_guard.hpp \
|
||||
asio/executor.hpp \
|
||||
asio/executor_work_guard.hpp \
|
||||
asio/generic/basic_endpoint.hpp \
|
||||
asio/generic/datagram_protocol.hpp \
|
||||
asio/generic/detail/endpoint.hpp \
|
||||
@@ -296,13 +303,16 @@ nobase_include_HEADERS = \
|
||||
asio/handler_alloc_hook.hpp \
|
||||
asio/handler_continuation_hook.hpp \
|
||||
asio/handler_invoke_hook.hpp \
|
||||
asio/handler_type.hpp \
|
||||
asio/high_resolution_timer.hpp \
|
||||
asio.hpp \
|
||||
asio/impl/awaitable.hpp \
|
||||
asio/impl/buffered_read_stream.hpp \
|
||||
asio/impl/buffered_write_stream.hpp \
|
||||
asio/impl/co_spawn.hpp \
|
||||
asio/impl/compose.hpp \
|
||||
asio/impl/connect.hpp \
|
||||
asio/impl/defer.hpp \
|
||||
asio/impl/detached.hpp \
|
||||
asio/impl/dispatch.hpp \
|
||||
asio/impl/error_code.ipp \
|
||||
asio/impl/error.ipp \
|
||||
@@ -317,6 +327,7 @@ nobase_include_HEADERS = \
|
||||
asio/impl/read_at.hpp \
|
||||
asio/impl/read.hpp \
|
||||
asio/impl/read_until.hpp \
|
||||
asio/impl/redirect_error.hpp \
|
||||
asio/impl/serial_port_base.hpp \
|
||||
asio/impl/serial_port_base.ipp \
|
||||
asio/impl/spawn.hpp \
|
||||
@@ -327,13 +338,14 @@ nobase_include_HEADERS = \
|
||||
asio/impl/system_executor.hpp \
|
||||
asio/impl/thread_pool.hpp \
|
||||
asio/impl/thread_pool.ipp \
|
||||
asio/impl/use_awaitable.hpp \
|
||||
asio/impl/use_future.hpp \
|
||||
asio/impl/write_at.hpp \
|
||||
asio/impl/write.hpp \
|
||||
asio/io_context_strand.hpp \
|
||||
asio/io_context.hpp \
|
||||
asio/io_service_strand.hpp \
|
||||
asio/io_context_strand.hpp \
|
||||
asio/io_service.hpp \
|
||||
asio/io_service_strand.hpp \
|
||||
asio/ip/address.hpp \
|
||||
asio/ip/address_v4.hpp \
|
||||
asio/ip/address_v4_iterator.hpp \
|
||||
@@ -370,7 +382,6 @@ nobase_include_HEADERS = \
|
||||
asio/ip/network_v6.hpp \
|
||||
asio/ip/resolver_base.hpp \
|
||||
asio/ip/resolver_query_base.hpp \
|
||||
asio/ip/resolver_service.hpp \
|
||||
asio/ip/tcp.hpp \
|
||||
asio/ip/udp.hpp \
|
||||
asio/ip/unicast.hpp \
|
||||
@@ -388,22 +399,17 @@ nobase_include_HEADERS = \
|
||||
asio/placeholders.hpp \
|
||||
asio/posix/basic_descriptor.hpp \
|
||||
asio/posix/basic_stream_descriptor.hpp \
|
||||
asio/posix/descriptor.hpp \
|
||||
asio/posix/descriptor_base.hpp \
|
||||
asio/posix/descriptor.hpp \
|
||||
asio/posix/stream_descriptor.hpp \
|
||||
asio/posix/stream_descriptor_service.hpp \
|
||||
asio/post.hpp \
|
||||
asio/raw_socket_service.hpp \
|
||||
asio/read_at.hpp \
|
||||
asio/read.hpp \
|
||||
asio/read_until.hpp \
|
||||
asio/seq_packet_socket_service.hpp \
|
||||
asio/redirect_error.hpp \
|
||||
asio/serial_port_base.hpp \
|
||||
asio/serial_port.hpp \
|
||||
asio/serial_port_service.hpp \
|
||||
asio/signal_set.hpp \
|
||||
asio/signal_set_service.hpp \
|
||||
asio/socket_acceptor_service.hpp \
|
||||
asio/socket_base.hpp \
|
||||
asio/spawn.hpp \
|
||||
asio/ssl/context_base.hpp \
|
||||
@@ -437,11 +443,11 @@ nobase_include_HEADERS = \
|
||||
asio/steady_timer.hpp \
|
||||
asio/strand.hpp \
|
||||
asio/streambuf.hpp \
|
||||
asio/stream_socket_service.hpp \
|
||||
asio/system_context.hpp \
|
||||
asio/system_error.hpp \
|
||||
asio/system_executor.hpp \
|
||||
asio/system_timer.hpp \
|
||||
asio/this_coro.hpp \
|
||||
asio/thread.hpp \
|
||||
asio/thread_pool.hpp \
|
||||
asio/time_traits.hpp \
|
||||
@@ -454,23 +460,20 @@ nobase_include_HEADERS = \
|
||||
asio/ts/socket.hpp \
|
||||
asio/ts/timer.hpp \
|
||||
asio/unyield.hpp \
|
||||
asio/use_awaitable.hpp \
|
||||
asio/use_future.hpp \
|
||||
asio/uses_executor.hpp \
|
||||
asio/version.hpp \
|
||||
asio/waitable_timer_service.hpp \
|
||||
asio/wait_traits.hpp \
|
||||
asio/windows/basic_handle.hpp \
|
||||
asio/windows/basic_object_handle.hpp \
|
||||
asio/windows/basic_overlapped_handle.hpp \
|
||||
asio/windows/basic_random_access_handle.hpp \
|
||||
asio/windows/basic_stream_handle.hpp \
|
||||
asio/windows/object_handle.hpp \
|
||||
asio/windows/object_handle_service.hpp \
|
||||
asio/windows/overlapped_handle.hpp \
|
||||
asio/windows/overlapped_ptr.hpp \
|
||||
asio/windows/random_access_handle.hpp \
|
||||
asio/windows/random_access_handle_service.hpp \
|
||||
asio/windows/stream_handle.hpp \
|
||||
asio/windows/stream_handle_service.hpp \
|
||||
asio/write_at.hpp \
|
||||
asio/write.hpp \
|
||||
asio/yield.hpp
|
||||
@@ -2,7 +2,7 @@
|
||||
// asio.hpp
|
||||
// ~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/awaitable.hpp"
|
||||
#include "asio/basic_datagram_socket.hpp"
|
||||
#include "asio/basic_deadline_timer.hpp"
|
||||
#include "asio/basic_io_object.hpp"
|
||||
@@ -25,6 +26,7 @@
|
||||
#include "asio/basic_seq_packet_socket.hpp"
|
||||
#include "asio/basic_serial_port.hpp"
|
||||
#include "asio/basic_signal_set.hpp"
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/basic_socket_acceptor.hpp"
|
||||
#include "asio/basic_socket_iostream.hpp"
|
||||
#include "asio/basic_socket_streambuf.hpp"
|
||||
@@ -40,13 +42,14 @@
|
||||
#include "asio/buffered_write_stream_fwd.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/buffers_iterator.hpp"
|
||||
#include "asio/co_spawn.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/compose.hpp"
|
||||
#include "asio/connect.hpp"
|
||||
#include "asio/coroutine.hpp"
|
||||
#include "asio/datagram_socket_service.hpp"
|
||||
#include "asio/deadline_timer_service.hpp"
|
||||
#include "asio/deadline_timer.hpp"
|
||||
#include "asio/defer.hpp"
|
||||
#include "asio/detached.hpp"
|
||||
#include "asio/dispatch.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/error_code.hpp"
|
||||
@@ -61,7 +64,6 @@
|
||||
#include "asio/handler_alloc_hook.hpp"
|
||||
#include "asio/handler_continuation_hook.hpp"
|
||||
#include "asio/handler_invoke_hook.hpp"
|
||||
#include "asio/handler_type.hpp"
|
||||
#include "asio/high_resolution_timer.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/io_context_strand.hpp"
|
||||
@@ -74,6 +76,8 @@
|
||||
#include "asio/ip/address_v6.hpp"
|
||||
#include "asio/ip/address_v6_iterator.hpp"
|
||||
#include "asio/ip/address_v6_range.hpp"
|
||||
#include "asio/ip/network_v4.hpp"
|
||||
#include "asio/ip/network_v6.hpp"
|
||||
#include "asio/ip/bad_address_cast.hpp"
|
||||
#include "asio/ip/basic_endpoint.hpp"
|
||||
#include "asio/ip/basic_resolver.hpp"
|
||||
@@ -85,7 +89,6 @@
|
||||
#include "asio/ip/multicast.hpp"
|
||||
#include "asio/ip/resolver_base.hpp"
|
||||
#include "asio/ip/resolver_query_base.hpp"
|
||||
#include "asio/ip/resolver_service.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "asio/ip/unicast.hpp"
|
||||
@@ -104,48 +107,40 @@
|
||||
#include "asio/posix/descriptor.hpp"
|
||||
#include "asio/posix/descriptor_base.hpp"
|
||||
#include "asio/posix/stream_descriptor.hpp"
|
||||
#include "asio/posix/stream_descriptor_service.hpp"
|
||||
#include "asio/post.hpp"
|
||||
#include "asio/raw_socket_service.hpp"
|
||||
#include "asio/read.hpp"
|
||||
#include "asio/read_at.hpp"
|
||||
#include "asio/read_until.hpp"
|
||||
#include "asio/seq_packet_socket_service.hpp"
|
||||
#include "asio/redirect_error.hpp"
|
||||
#include "asio/serial_port.hpp"
|
||||
#include "asio/serial_port_base.hpp"
|
||||
#include "asio/serial_port_service.hpp"
|
||||
#include "asio/signal_set.hpp"
|
||||
#include "asio/signal_set_service.hpp"
|
||||
#include "asio/socket_acceptor_service.hpp"
|
||||
#include "asio/socket_base.hpp"
|
||||
#include "asio/steady_timer.hpp"
|
||||
#include "asio/strand.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
#include "asio/streambuf.hpp"
|
||||
#include "asio/system_context.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
#include "asio/system_executor.hpp"
|
||||
#include "asio/system_timer.hpp"
|
||||
#include "asio/this_coro.hpp"
|
||||
#include "asio/thread.hpp"
|
||||
#include "asio/thread_pool.hpp"
|
||||
#include "asio/time_traits.hpp"
|
||||
#include "asio/use_awaitable.hpp"
|
||||
#include "asio/use_future.hpp"
|
||||
#include "asio/uses_executor.hpp"
|
||||
#include "asio/version.hpp"
|
||||
#include "asio/wait_traits.hpp"
|
||||
#include "asio/waitable_timer_service.hpp"
|
||||
#include "asio/windows/basic_handle.hpp"
|
||||
#include "asio/windows/basic_object_handle.hpp"
|
||||
#include "asio/windows/basic_overlapped_handle.hpp"
|
||||
#include "asio/windows/basic_random_access_handle.hpp"
|
||||
#include "asio/windows/basic_stream_handle.hpp"
|
||||
#include "asio/windows/object_handle.hpp"
|
||||
#include "asio/windows/object_handle_service.hpp"
|
||||
#include "asio/windows/overlapped_handle.hpp"
|
||||
#include "asio/windows/overlapped_ptr.hpp"
|
||||
#include "asio/windows/random_access_handle.hpp"
|
||||
#include "asio/windows/random_access_handle_service.hpp"
|
||||
#include "asio/windows/stream_handle.hpp"
|
||||
#include "asio/windows/stream_handle_service.hpp"
|
||||
#include "asio/write.hpp"
|
||||
#include "asio/write_at.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// associated_allocator.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// associated_executor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
356
Sources/ASIO/asio/include/asio/async_result.hpp
Normal file
356
Sources/ASIO/asio/include/asio/async_result.hpp
Normal file
@@ -0,0 +1,356 @@
|
||||
//
|
||||
// async_result.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_ASYNC_RESULT_HPP
|
||||
#define ASIO_ASYNC_RESULT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/detail/variadic_templates.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// An interface for customising the behaviour of an initiating function.
|
||||
/**
|
||||
* The async_result traits class is used for determining:
|
||||
*
|
||||
* @li the concrete completion handler type to be called at the end of the
|
||||
* asynchronous operation;
|
||||
*
|
||||
* @li the initiating function return type; and
|
||||
*
|
||||
* @li how the return value of the initiating function is obtained.
|
||||
*
|
||||
* The trait allows the handler and return types to be determined at the point
|
||||
* where the specific completion handler signature is known.
|
||||
*
|
||||
* This template may be specialised for user-defined completion token types.
|
||||
* The primary template assumes that the CompletionToken is the completion
|
||||
* handler.
|
||||
*/
|
||||
template <typename CompletionToken, typename Signature>
|
||||
class async_result
|
||||
{
|
||||
public:
|
||||
/// The concrete completion handler type for the specific signature.
|
||||
typedef CompletionToken completion_handler_type;
|
||||
|
||||
/// The return type of the initiating function.
|
||||
typedef void return_type;
|
||||
|
||||
/// Construct an async result from a given handler.
|
||||
/**
|
||||
* When using a specalised async_result, the constructor has an opportunity
|
||||
* to initialise some state associated with the completion handler, which is
|
||||
* then returned from the initiating function.
|
||||
*/
|
||||
explicit async_result(completion_handler_type& h)
|
||||
{
|
||||
(void)h;
|
||||
}
|
||||
|
||||
/// Obtain the value to be returned from the initiating function.
|
||||
return_type get()
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Initiate the asynchronous operation that will produce the result, and
|
||||
/// obtain the value to be returned from the initiating function.
|
||||
template <typename Initiation, typename RawCompletionToken, typename... Args>
|
||||
static return_type initiate(
|
||||
ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_MOVE_ARG(RawCompletionToken) token,
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)(
|
||||
ASIO_MOVE_CAST(RawCompletionToken)(token),
|
||||
ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Initiation, typename RawCompletionToken>
|
||||
static return_type initiate(
|
||||
ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_MOVE_ARG(RawCompletionToken) token)
|
||||
{
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)(
|
||||
ASIO_MOVE_CAST(RawCompletionToken)(token));
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_INITIATE_DEF(n) \
|
||||
template <typename Initiation, typename RawCompletionToken, \
|
||||
ASIO_VARIADIC_TPARAMS(n)> \
|
||||
static return_type initiate( \
|
||||
ASIO_MOVE_ARG(Initiation) initiation, \
|
||||
ASIO_MOVE_ARG(RawCompletionToken) token, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)( \
|
||||
ASIO_MOVE_CAST(RawCompletionToken)(token), \
|
||||
ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INITIATE_DEF)
|
||||
#undef ASIO_PRIVATE_INITIATE_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
private:
|
||||
async_result(const async_result&) ASIO_DELETED;
|
||||
async_result& operator=(const async_result&) ASIO_DELETED;
|
||||
};
|
||||
|
||||
/// Helper template to deduce the handler type from a CompletionToken, capture
|
||||
/// a local copy of the handler, and then create an async_result for the
|
||||
/// handler.
|
||||
template <typename CompletionToken, typename Signature>
|
||||
struct async_completion
|
||||
{
|
||||
/// The real handler type to be used for the asynchronous operation.
|
||||
typedef typename asio::async_result<
|
||||
typename decay<CompletionToken>::type,
|
||||
Signature>::completion_handler_type completion_handler_type;
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Constructor.
|
||||
/**
|
||||
* The constructor creates the concrete completion handler and makes the link
|
||||
* between the handler and the asynchronous result.
|
||||
*/
|
||||
explicit async_completion(CompletionToken& token)
|
||||
: completion_handler(static_cast<typename conditional<
|
||||
is_same<CompletionToken, completion_handler_type>::value,
|
||||
completion_handler_type&, CompletionToken&&>::type>(token)),
|
||||
result(completion_handler)
|
||||
{
|
||||
}
|
||||
#else // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
explicit async_completion(typename decay<CompletionToken>::type& token)
|
||||
: completion_handler(token),
|
||||
result(completion_handler)
|
||||
{
|
||||
}
|
||||
|
||||
explicit async_completion(const typename decay<CompletionToken>::type& token)
|
||||
: completion_handler(token),
|
||||
result(completion_handler)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// A copy of, or reference to, a real handler object.
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
typename conditional<
|
||||
is_same<CompletionToken, completion_handler_type>::value,
|
||||
completion_handler_type&, completion_handler_type>::type completion_handler;
|
||||
#else // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
completion_handler_type completion_handler;
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// The result of the asynchronous operation's initiating function.
|
||||
async_result<typename decay<CompletionToken>::type, Signature> result;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename CompletionToken, typename Signature>
|
||||
struct async_result_helper
|
||||
: async_result<typename decay<CompletionToken>::type, Signature>
|
||||
{
|
||||
};
|
||||
|
||||
struct async_result_memfns_base
|
||||
{
|
||||
void initiate();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct async_result_memfns_derived
|
||||
: T, async_result_memfns_base
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, T>
|
||||
struct async_result_memfns_check
|
||||
{
|
||||
};
|
||||
|
||||
template <typename>
|
||||
char (&async_result_initiate_memfn_helper(...))[2];
|
||||
|
||||
template <typename T>
|
||||
char async_result_initiate_memfn_helper(
|
||||
async_result_memfns_check<
|
||||
void (async_result_memfns_base::*)(),
|
||||
&async_result_memfns_derived<T>::initiate>*);
|
||||
|
||||
template <typename CompletionToken, typename Signature>
|
||||
struct async_result_has_initiate_memfn
|
||||
: integral_constant<bool, sizeof(async_result_initiate_memfn_helper<
|
||||
async_result<typename decay<CompletionToken>::type, Signature>
|
||||
>(0)) != 1>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
# define ASIO_INITFN_RESULT_TYPE(ct, sig) \
|
||||
void_or_deduced
|
||||
#elif defined(_MSC_VER) && (_MSC_VER < 1500)
|
||||
# define ASIO_INITFN_RESULT_TYPE(ct, sig) \
|
||||
typename ::asio::detail::async_result_helper< \
|
||||
ct, sig>::return_type
|
||||
#define ASIO_HANDLER_TYPE(ct, sig) \
|
||||
typename ::asio::detail::async_result_helper< \
|
||||
ct, sig>::completion_handler_type
|
||||
#else
|
||||
# define ASIO_INITFN_RESULT_TYPE(ct, sig) \
|
||||
typename ::asio::async_result< \
|
||||
typename ::asio::decay<ct>::type, sig>::return_type
|
||||
#define ASIO_HANDLER_TYPE(ct, sig) \
|
||||
typename ::asio::async_result< \
|
||||
typename ::asio::decay<ct>::type, sig>::completion_handler_type
|
||||
#endif
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename CompletionToken, typename Signature,
|
||||
typename Initiation, typename... Args>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken),
|
||||
ASIO_MOVE_ARG(Args)... args);
|
||||
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename CompletionToken, typename Signature,
|
||||
typename Initiation, typename... Args>
|
||||
inline typename enable_if<
|
||||
detail::async_result_has_initiate_memfn<CompletionToken, Signature>::value,
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
return async_result<typename decay<CompletionToken>::type,
|
||||
Signature>::initiate(ASIO_MOVE_CAST(Initiation)(initiation),
|
||||
ASIO_MOVE_CAST(CompletionToken)(token),
|
||||
ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
template <typename CompletionToken, typename Signature,
|
||||
typename Initiation, typename... Args>
|
||||
inline typename enable_if<
|
||||
!detail::async_result_has_initiate_memfn<CompletionToken, Signature>::value,
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
async_completion<CompletionToken, Signature> completion(token);
|
||||
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)(
|
||||
ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(CompletionToken,
|
||||
Signature))(completion.completion_handler),
|
||||
ASIO_MOVE_CAST(Args)(args)...);
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename CompletionToken, typename Signature, typename Initiation>
|
||||
inline typename enable_if<
|
||||
detail::async_result_has_initiate_memfn<CompletionToken, Signature>::value,
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return async_result<typename decay<CompletionToken>::type,
|
||||
Signature>::initiate(ASIO_MOVE_CAST(Initiation)(initiation),
|
||||
ASIO_MOVE_CAST(CompletionToken)(token));
|
||||
}
|
||||
|
||||
template <typename CompletionToken, typename Signature, typename Initiation>
|
||||
inline typename enable_if<
|
||||
!detail::async_result_has_initiate_memfn<CompletionToken, Signature>::value,
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
async_completion<CompletionToken, Signature> completion(token);
|
||||
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)(
|
||||
ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(CompletionToken,
|
||||
Signature))(completion.completion_handler));
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_INITIATE_DEF(n) \
|
||||
template <typename CompletionToken, typename Signature, \
|
||||
typename Initiation, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
inline typename enable_if< \
|
||||
detail::async_result_has_initiate_memfn< \
|
||||
CompletionToken, Signature>::value, \
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type \
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation, \
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
return async_result<typename decay<CompletionToken>::type, \
|
||||
Signature>::initiate(ASIO_MOVE_CAST(Initiation)(initiation), \
|
||||
ASIO_MOVE_CAST(CompletionToken)(token), \
|
||||
ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
\
|
||||
template <typename CompletionToken, typename Signature, \
|
||||
typename Initiation, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
inline typename enable_if< \
|
||||
!detail::async_result_has_initiate_memfn< \
|
||||
CompletionToken, Signature>::value, \
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type \
|
||||
async_initiate(ASIO_MOVE_ARG(Initiation) initiation, \
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
async_completion<CompletionToken, Signature> completion(token); \
|
||||
\
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)( \
|
||||
ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(CompletionToken, \
|
||||
Signature))(completion.completion_handler), \
|
||||
ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
\
|
||||
return completion.result.get(); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INITIATE_DEF)
|
||||
#undef ASIO_PRIVATE_INITIATE_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_ASYNC_RESULT_HPP
|
||||
123
Sources/ASIO/asio/include/asio/awaitable.hpp
Normal file
123
Sources/ASIO/asio/include/asio/awaitable.hpp
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// awaitable.hpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_AWAITABLE_HPP
|
||||
#define ASIO_AWAITABLE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <experimental/coroutine>
|
||||
#include "asio/executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
using std::experimental::coroutine_handle;
|
||||
using std::experimental::suspend_always;
|
||||
|
||||
template <typename> class awaitable_thread;
|
||||
template <typename, typename> class awaitable_frame;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// The return type of a coroutine or asynchronous operation.
|
||||
template <typename T, typename Executor = executor>
|
||||
class awaitable
|
||||
{
|
||||
public:
|
||||
/// The type of the awaited value.
|
||||
typedef T value_type;
|
||||
|
||||
/// The executor type that will be used for the coroutine.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Default constructor.
|
||||
constexpr awaitable() noexcept
|
||||
: frame_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/// Move constructor.
|
||||
awaitable(awaitable&& other) noexcept
|
||||
: frame_(std::exchange(other.frame_, nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
~awaitable()
|
||||
{
|
||||
if (frame_)
|
||||
frame_->destroy();
|
||||
}
|
||||
|
||||
/// Checks if the awaitable refers to a future result.
|
||||
bool valid() const noexcept
|
||||
{
|
||||
return !!frame_;
|
||||
}
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
// Support for co_await keyword.
|
||||
bool await_ready() const noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Support for co_await keyword.
|
||||
template <class U>
|
||||
void await_suspend(
|
||||
detail::coroutine_handle<detail::awaitable_frame<U, Executor>> h)
|
||||
{
|
||||
frame_->push_frame(&h.promise());
|
||||
}
|
||||
|
||||
// Support for co_await keyword.
|
||||
T await_resume()
|
||||
{
|
||||
return frame_->get();
|
||||
}
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
private:
|
||||
template <typename> friend class detail::awaitable_thread;
|
||||
template <typename, typename> friend class detail::awaitable_frame;
|
||||
|
||||
// Not copy constructible or copy assignable.
|
||||
awaitable(const awaitable&) = delete;
|
||||
awaitable& operator=(const awaitable&) = delete;
|
||||
|
||||
// Construct the awaitable from a coroutine's frame object.
|
||||
explicit awaitable(detail::awaitable_frame<T, Executor>* a)
|
||||
: frame_(a)
|
||||
{
|
||||
}
|
||||
|
||||
detail::awaitable_frame<T, Executor>* frame_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/awaitable.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_AWAITABLE_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_datagram_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -19,18 +19,24 @@
|
||||
#include <cstddef>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/datagram_socket_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if !defined(ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL)
|
||||
#define ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Protocol, typename Executor = executor>
|
||||
class basic_datagram_socket;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL)
|
||||
|
||||
/// Provides datagram-oriented socket functionality.
|
||||
/**
|
||||
* The basic_datagram_socket class template provides asynchronous and blocking
|
||||
@@ -40,18 +46,28 @@ namespace asio {
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol
|
||||
ASIO_SVC_TPARAM_DEF1(= datagram_socket_service<Protocol>)>
|
||||
template <typename Protocol, typename Executor>
|
||||
class basic_datagram_socket
|
||||
: public basic_socket<Protocol ASIO_SVC_TARG>
|
||||
: public basic_socket<Protocol, Executor>
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the socket type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The socket type when rebound to the specified executor.
|
||||
typedef basic_datagram_socket<Protocol, Executor1> other;
|
||||
};
|
||||
|
||||
/// The native representation of a socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_handle_type;
|
||||
#else
|
||||
typedef typename basic_socket<
|
||||
Protocol ASIO_SVC_TARG>::native_handle_type native_handle_type;
|
||||
typedef typename basic_socket<Protocol,
|
||||
Executor>::native_handle_type native_handle_type;
|
||||
#endif
|
||||
|
||||
/// The protocol type.
|
||||
@@ -65,12 +81,29 @@ public:
|
||||
* This constructor creates a datagram socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param io_context The io_context object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_datagram_socket(asio::io_context& io_context)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context)
|
||||
explicit basic_datagram_socket(const executor_type& ex)
|
||||
: basic_socket<Protocol, Executor>(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a datagram socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_datagram_socket(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,17 +111,37 @@ public:
|
||||
/**
|
||||
* This constructor creates and opens a datagram socket.
|
||||
*
|
||||
* @param io_context The io_context object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(asio::io_context& io_context,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, protocol)
|
||||
basic_datagram_socket(const executor_type& ex, const protocol_type& protocol)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_datagram_socket.
|
||||
/**
|
||||
* This constructor creates and opens a datagram socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_datagram_socket(ExecutionContext& context,
|
||||
const protocol_type& protocol,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,18 +152,42 @@ public:
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_context The io_context object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the datagram
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(asio::io_context& io_context,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, endpoint)
|
||||
basic_datagram_socket(const executor_type& ex, const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, Executor>(ex, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a datagram socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the datagram
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_datagram_socket(ExecutionContext& context,
|
||||
const endpoint_type& endpoint,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -119,9 +196,8 @@ public:
|
||||
* This constructor creates a datagram socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param io_context The io_context object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
@@ -129,10 +205,34 @@ public:
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(asio::io_context& io_context,
|
||||
basic_datagram_socket(const executor_type& ex,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(
|
||||
io_context, protocol, native_socket)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a datagram socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_datagram_socket(ExecutionContext& context,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -145,10 +245,11 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_datagram_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_datagram_socket(basic_datagram_socket&& other)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -161,11 +262,12 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_datagram_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_datagram_socket& operator=(basic_datagram_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -178,13 +280,16 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_datagram_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
basic_datagram_socket(
|
||||
basic_datagram_socket<Protocol1 ASIO_SVC_TARG1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
template <typename Protocol1, typename Executor1>
|
||||
basic_datagram_socket(basic_datagram_socket<Protocol1, Executor1>&& other,
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -198,14 +303,17 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_datagram_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_datagram_socket>::type& operator=(
|
||||
basic_datagram_socket<Protocol1 ASIO_SVC_TARG1>&& other)
|
||||
template <typename Protocol1, typename Executor1>
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value,
|
||||
basic_datagram_socket&
|
||||
>::type operator=(basic_datagram_socket<Protocol1, Executor1>&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
@@ -245,8 +353,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -273,8 +381,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -300,8 +408,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
@@ -322,9 +430,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected datagram
|
||||
@@ -345,22 +453,10 @@ public:
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
@@ -383,9 +479,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected datagram
|
||||
@@ -398,22 +494,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
@@ -446,8 +529,8 @@ public:
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().send_to(
|
||||
this->impl_.get_implementation(), buffers, destination, 0, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
@@ -473,8 +556,8 @@ public:
|
||||
const endpoint_type& destination, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().send_to(
|
||||
this->impl_.get_implementation(), buffers, destination, flags, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
@@ -500,7 +583,7 @@ public:
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_to(this->get_implementation(),
|
||||
return this->impl_.get_service().send_to(this->impl_.get_implementation(),
|
||||
buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
@@ -525,9 +608,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
@@ -548,24 +631,10 @@ public:
|
||||
const endpoint_type& destination,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, 0,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, 0,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send_to(), handler, this, buffers,
|
||||
destination, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@@ -591,9 +660,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
@@ -602,24 +671,9 @@ public:
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send_to(), handler, this, buffers, destination, flags);
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
@@ -650,8 +704,8 @@ public:
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -679,8 +733,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -707,8 +761,8 @@ public:
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
@@ -729,9 +783,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
@@ -753,22 +807,10 @@ public:
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
@@ -791,9 +833,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
@@ -806,22 +848,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
@@ -855,8 +884,8 @@ public:
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().receive_from(
|
||||
this->impl_.get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
@@ -882,8 +911,8 @@ public:
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().receive_from(
|
||||
this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
@@ -909,8 +938,8 @@ public:
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive_from(this->get_implementation(),
|
||||
buffers, sender_endpoint, flags, ec);
|
||||
return this->impl_.get_service().receive_from(
|
||||
this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -936,9 +965,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
@@ -956,24 +985,10 @@ public:
|
||||
endpoint_type& sender_endpoint,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_from(), handler, this, buffers,
|
||||
&sender_endpoint, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -1001,9 +1016,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
@@ -1012,25 +1027,85 @@ public:
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_from(), handler,
|
||||
this, buffers, &sender_endpoint, flags);
|
||||
}
|
||||
|
||||
private:
|
||||
struct initiate_async_send
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_datagram_socket* self, const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_send(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_send_to
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_datagram_socket* self, const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_send_to(
|
||||
self->impl_.get_implementation(), buffers, destination, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_receive
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_datagram_socket* self, const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_receive(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_receive_from
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_datagram_socket* self, const MutableBufferSequence& buffers,
|
||||
endpoint_type* sender_endpoint, socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_receive_from(
|
||||
self->impl_.get_implementation(), buffers, *sender_endpoint, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_deadline_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -21,19 +21,16 @@
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <cstddef>
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/detail/deadline_timer_service.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/io_object_impl.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
#include "asio/time_traits.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/deadline_timer_service.hpp"
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/detail/deadline_timer_service.hpp"
|
||||
# define ASIO_SVC_T detail::deadline_timer_service<TimeTraits>
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
@@ -57,7 +54,7 @@ namespace asio {
|
||||
* Performing a blocking wait:
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* asio::deadline_timer timer(io_context);
|
||||
* asio::deadline_timer timer(my_context);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_from_now(boost::posix_time::seconds(5));
|
||||
@@ -80,7 +77,7 @@ namespace asio {
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* asio::deadline_timer timer(io_context,
|
||||
* asio::deadline_timer timer(my_context,
|
||||
* boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
@@ -127,14 +124,13 @@ namespace asio {
|
||||
* it contains the value asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Time,
|
||||
typename TimeTraits = asio::time_traits<Time>
|
||||
ASIO_SVC_TPARAM_DEF2(= deadline_timer_service<Time, TimeTraits>)>
|
||||
typename TimeTraits = asio::time_traits<Time>,
|
||||
typename Executor = executor>
|
||||
class basic_deadline_timer
|
||||
: ASIO_SVC_ACCESS basic_io_object<ASIO_SVC_T>
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef io_context::executor_type executor_type;
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// The time traits type.
|
||||
typedef TimeTraits traits_type;
|
||||
@@ -151,11 +147,30 @@ public:
|
||||
* expires_at() or expires_from_now() functions must be called to set an
|
||||
* expiry time before the timer can be waited on.
|
||||
*
|
||||
* @param io_context The io_context object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
* @param ex The I/O executor that the timer will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the timer.
|
||||
*/
|
||||
explicit basic_deadline_timer(asio::io_context& io_context)
|
||||
: basic_io_object<ASIO_SVC_T>(io_context)
|
||||
explicit basic_deadline_timer(const executor_type& ex)
|
||||
: impl_(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor.
|
||||
/**
|
||||
* This constructor creates a timer without setting an expiry time. The
|
||||
* expires_at() or expires_from_now() functions must be called to set an
|
||||
* expiry time before the timer can be waited on.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the timer will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the timer.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_deadline_timer(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -163,18 +178,40 @@ public:
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_context The io_context object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
* @param ex The I/O executor that the timer will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
basic_deadline_timer(asio::io_context& io_context,
|
||||
const time_type& expiry_time)
|
||||
: basic_io_object<ASIO_SVC_T>(io_context)
|
||||
basic_deadline_timer(const executor_type& ex, const time_type& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().expires_at(this->get_implementation(), expiry_time, ec);
|
||||
impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the timer will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_deadline_timer(ExecutionContext& context, const time_type& expiry_time,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
@@ -182,19 +219,44 @@ public:
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_context The io_context object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
* @param ex The I/O executor that the timer will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
basic_deadline_timer(asio::io_context& io_context,
|
||||
basic_deadline_timer(const executor_type& ex,
|
||||
const duration_type& expiry_time)
|
||||
: basic_io_object<ASIO_SVC_T>(io_context)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().expires_from_now(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the timer will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_deadline_timer(ExecutionContext& context,
|
||||
const duration_type& expiry_time,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
}
|
||||
|
||||
@@ -207,10 +269,11 @@ public:
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_deadline_timer(io_context&) constructor.
|
||||
* constructed using the @c basic_deadline_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_deadline_timer(basic_deadline_timer&& other)
|
||||
: basic_io_object<ASIO_SVC_T>(std::move(other))
|
||||
: impl_(std::move(other.impl_))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -223,11 +286,12 @@ public:
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_deadline_timer(io_context&) constructor.
|
||||
* constructed using the @c basic_deadline_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_deadline_timer& operator=(basic_deadline_timer&& other)
|
||||
{
|
||||
basic_io_object<ASIO_SVC_T>::operator=(std::move(other));
|
||||
impl_ = std::move(other.impl_);
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
@@ -241,45 +305,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
// These functions are provided by basic_io_object<>.
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
/**
|
||||
* This function may be used to obtain the io_context object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_context object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return basic_io_object<ASIO_SVC_T>::get_io_context();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
/**
|
||||
* This function may be used to obtain the io_context object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_context object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return basic_io_object<ASIO_SVC_T>::get_io_service();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return basic_io_object<ASIO_SVC_T>::get_executor();
|
||||
return impl_.get_executor();
|
||||
}
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
@@ -306,7 +336,7 @@ public:
|
||||
std::size_t cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().cancel(this->get_implementation(), ec);
|
||||
std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
@@ -335,7 +365,7 @@ public:
|
||||
*/
|
||||
std::size_t cancel(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().cancel(this->get_implementation(), ec);
|
||||
return impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
@@ -365,8 +395,8 @@ public:
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().cancel_one(
|
||||
this->get_implementation(), ec);
|
||||
std::size_t s = impl_.get_service().cancel_one(
|
||||
impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
@@ -397,7 +427,7 @@ public:
|
||||
*/
|
||||
std::size_t cancel_one(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().cancel_one(this->get_implementation(), ec);
|
||||
return impl_.get_service().cancel_one(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
@@ -407,7 +437,7 @@ public:
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return this->get_service().expires_at(this->get_implementation());
|
||||
return impl_.get_service().expires_at(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
@@ -435,8 +465,8 @@ public:
|
||||
std::size_t expires_at(const time_type& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().expires_at(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
std::size_t s = impl_.get_service().expires_at(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
return s;
|
||||
}
|
||||
@@ -466,8 +496,8 @@ public:
|
||||
std::size_t expires_at(const time_type& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().expires_at(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
return impl_.get_service().expires_at(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
@@ -477,7 +507,7 @@ public:
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return this->get_service().expires_from_now(this->get_implementation());
|
||||
return impl_.get_service().expires_from_now(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
@@ -505,8 +535,8 @@ public:
|
||||
std::size_t expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().expires_from_now(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
std::size_t s = impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
return s;
|
||||
}
|
||||
@@ -536,8 +566,8 @@ public:
|
||||
std::size_t expires_from_now(const duration_type& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().expires_from_now(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
return impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
@@ -550,7 +580,7 @@ public:
|
||||
void wait()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().wait(this->get_implementation(), ec);
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
@@ -563,7 +593,7 @@ public:
|
||||
*/
|
||||
void wait(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().wait(this->get_implementation(), ec);
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
@@ -586,42 +616,50 @@ public:
|
||||
* const asio::error_code& error // Result of operation.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename WaitHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WaitHandler.
|
||||
ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_wait(this->get_implementation(),
|
||||
ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WaitHandler,
|
||||
void (asio::error_code)> init(handler);
|
||||
|
||||
this->get_service().async_wait(this->get_implementation(),
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WaitHandler, void (asio::error_code)>(
|
||||
initiate_async_wait(), handler, this);
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_deadline_timer(const basic_deadline_timer&) ASIO_DELETED;
|
||||
basic_deadline_timer& operator=(
|
||||
const basic_deadline_timer&) ASIO_DELETED;
|
||||
|
||||
struct initiate_async_wait
|
||||
{
|
||||
template <typename WaitHandler>
|
||||
void operator()(ASIO_MOVE_ARG(WaitHandler) handler,
|
||||
basic_deadline_timer* self) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WaitHandler.
|
||||
ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WaitHandler> handler2(handler);
|
||||
self->impl_.get_service().async_wait(
|
||||
self->impl_.get_implementation(), handler2.value,
|
||||
self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
detail::io_object_impl<
|
||||
detail::deadline_timer_service<TimeTraits>, Executor> impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# undef ASIO_SVC_T
|
||||
#endif // !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_io_object.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_raw_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -19,18 +19,24 @@
|
||||
#include <cstddef>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/raw_socket_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if !defined(ASIO_BASIC_RAW_SOCKET_FWD_DECL)
|
||||
#define ASIO_BASIC_RAW_SOCKET_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Protocol, typename Executor = executor>
|
||||
class basic_raw_socket;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_RAW_SOCKET_FWD_DECL)
|
||||
|
||||
/// Provides raw-oriented socket functionality.
|
||||
/**
|
||||
* The basic_raw_socket class template provides asynchronous and blocking
|
||||
@@ -40,18 +46,28 @@ namespace asio {
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol
|
||||
ASIO_SVC_TPARAM_DEF1(= raw_socket_service<Protocol>)>
|
||||
template <typename Protocol, typename Executor>
|
||||
class basic_raw_socket
|
||||
: public basic_socket<Protocol ASIO_SVC_TARG>
|
||||
: public basic_socket<Protocol, Executor>
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the socket type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The socket type when rebound to the specified executor.
|
||||
typedef basic_raw_socket<Protocol, Executor1> other;
|
||||
};
|
||||
|
||||
/// The native representation of a socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_handle_type;
|
||||
#else
|
||||
typedef typename basic_socket<
|
||||
Protocol ASIO_SVC_TARG>::native_handle_type native_handle_type;
|
||||
typedef typename basic_socket<Protocol,
|
||||
Executor>::native_handle_type native_handle_type;
|
||||
#endif
|
||||
|
||||
/// The protocol type.
|
||||
@@ -65,12 +81,29 @@ public:
|
||||
* This constructor creates a raw socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param io_context The io_context object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_raw_socket(asio::io_context& io_context)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context)
|
||||
explicit basic_raw_socket(const executor_type& ex)
|
||||
: basic_socket<Protocol, Executor>(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a raw socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_raw_socket(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,17 +111,36 @@ public:
|
||||
/**
|
||||
* This constructor creates and opens a raw socket.
|
||||
*
|
||||
* @param io_context The io_context object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(asio::io_context& io_context,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, protocol)
|
||||
basic_raw_socket(const executor_type& ex, const protocol_type& protocol)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_raw_socket.
|
||||
/**
|
||||
* This constructor creates and opens a raw socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_raw_socket(ExecutionContext& context, const protocol_type& protocol,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,18 +151,41 @@ public:
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_context The io_context object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the raw
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(asio::io_context& io_context,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, endpoint)
|
||||
basic_raw_socket(const executor_type& ex, const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, Executor>(ex, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a raw socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the raw
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_raw_socket(ExecutionContext& context, const endpoint_type& endpoint,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -119,9 +194,8 @@ public:
|
||||
* This constructor creates a raw socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param io_context The io_context object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
@@ -129,10 +203,34 @@ public:
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(asio::io_context& io_context,
|
||||
basic_raw_socket(const executor_type& ex,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(
|
||||
io_context, protocol, native_socket)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a raw socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_raw_socket(ExecutionContext& context,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -145,10 +243,11 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_raw_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_raw_socket(basic_raw_socket&& other)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -160,28 +259,34 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_raw_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_raw_socket& operator=(basic_raw_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_raw_socket from a socket of another protocol type.
|
||||
/// Move-construct a basic_raw_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move will
|
||||
* occur.
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_raw_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
basic_raw_socket(basic_raw_socket<Protocol1 ASIO_SVC_TARG1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
template <typename Protocol1, typename Executor1>
|
||||
basic_raw_socket(basic_raw_socket<Protocol1, Executor1>&& other,
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -193,14 +298,17 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_raw_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_raw_socket>::type& operator=(
|
||||
basic_raw_socket<Protocol1 ASIO_SVC_TARG1>&& other)
|
||||
template <typename Protocol1, typename Executor1>
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value,
|
||||
basic_raw_socket&
|
||||
>::type operator=(basic_raw_socket<Protocol1, Executor1>&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
@@ -239,8 +347,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -266,8 +374,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -292,8 +400,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
@@ -314,9 +422,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected raw
|
||||
@@ -337,22 +445,10 @@ public:
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
@@ -375,9 +471,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected raw
|
||||
@@ -390,22 +486,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
@@ -438,8 +521,8 @@ public:
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().send_to(
|
||||
this->impl_.get_implementation(), buffers, destination, 0, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
@@ -465,8 +548,8 @@ public:
|
||||
const endpoint_type& destination, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().send_to(
|
||||
this->impl_.get_implementation(), buffers, destination, flags, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
@@ -492,7 +575,7 @@ public:
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_to(this->get_implementation(),
|
||||
return this->impl_.get_service().send_to(this->impl_.get_implementation(),
|
||||
buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
@@ -517,9 +600,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
@@ -540,22 +623,10 @@ public:
|
||||
const endpoint_type& destination,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send_to(this->get_implementation(),
|
||||
buffers, destination, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send_to(this->get_implementation(),
|
||||
buffers, destination, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send_to(), handler, this, buffers,
|
||||
destination, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@@ -581,9 +652,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
@@ -592,24 +663,9 @@ public:
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send_to(), handler, this, buffers, destination, flags);
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
@@ -640,8 +696,8 @@ public:
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -669,8 +725,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -697,8 +753,8 @@ public:
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
@@ -719,9 +775,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
@@ -743,22 +799,10 @@ public:
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
@@ -781,9 +825,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
@@ -796,22 +840,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
@@ -845,8 +876,8 @@ public:
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().receive_from(
|
||||
this->impl_.get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
@@ -872,8 +903,8 @@ public:
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().receive_from(
|
||||
this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
@@ -899,8 +930,8 @@ public:
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive_from(this->get_implementation(),
|
||||
buffers, sender_endpoint, flags, ec);
|
||||
return this->impl_.get_service().receive_from(
|
||||
this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -926,9 +957,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
@@ -946,24 +977,10 @@ public:
|
||||
endpoint_type& sender_endpoint,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_from(), handler, this, buffers,
|
||||
&sender_endpoint, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -991,9 +1008,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
@@ -1002,25 +1019,85 @@ public:
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_from(), handler,
|
||||
this, buffers, &sender_endpoint, flags);
|
||||
}
|
||||
|
||||
private:
|
||||
struct initiate_async_send
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_raw_socket* self, const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_send(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_send_to
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_raw_socket* self, const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_send_to(
|
||||
self->impl_.get_implementation(), buffers, destination, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_receive
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_raw_socket* self, const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_receive(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_receive_from
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_raw_socket* self, const MutableBufferSequence& buffers,
|
||||
endpoint_type* sender_endpoint, socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_receive_from(
|
||||
self->impl_.get_implementation(), buffers, *sender_endpoint, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_seq_packet_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -22,14 +22,19 @@
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/seq_packet_socket_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if !defined(ASIO_BASIC_SEQ_PACKET_SOCKET_FWD_DECL)
|
||||
#define ASIO_BASIC_SEQ_PACKET_SOCKET_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Protocol, typename Executor = executor>
|
||||
class basic_seq_packet_socket;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_SEQ_PACKET_SOCKET_FWD_DECL)
|
||||
|
||||
/// Provides sequenced packet socket functionality.
|
||||
/**
|
||||
* The basic_seq_packet_socket class template provides asynchronous and blocking
|
||||
@@ -39,18 +44,28 @@ namespace asio {
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol
|
||||
ASIO_SVC_TPARAM_DEF1(= seq_packet_socket_service<Protocol>)>
|
||||
template <typename Protocol, typename Executor>
|
||||
class basic_seq_packet_socket
|
||||
: public basic_socket<Protocol ASIO_SVC_TARG>
|
||||
: public basic_socket<Protocol, Executor>
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the socket type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The socket type when rebound to the specified executor.
|
||||
typedef basic_seq_packet_socket<Protocol, Executor1> other;
|
||||
};
|
||||
|
||||
/// The native representation of a socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_handle_type;
|
||||
#else
|
||||
typedef typename basic_socket<
|
||||
Protocol ASIO_SVC_TARG>::native_handle_type native_handle_type;
|
||||
typedef typename basic_socket<Protocol,
|
||||
Executor>::native_handle_type native_handle_type;
|
||||
#endif
|
||||
|
||||
/// The protocol type.
|
||||
@@ -65,12 +80,30 @@ public:
|
||||
* socket needs to be opened and then connected or accepted before data can
|
||||
* be sent or received on it.
|
||||
*
|
||||
* @param io_context The io_context object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_seq_packet_socket(asio::io_context& io_context)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context)
|
||||
explicit basic_seq_packet_socket(const executor_type& ex)
|
||||
: basic_socket<Protocol, Executor>(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket without opening it. The
|
||||
* socket needs to be opened and then connected or accepted before data can
|
||||
* be sent or received on it.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_seq_packet_socket(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -80,17 +113,40 @@ public:
|
||||
* needs to be connected or accepted before data can be sent or received on
|
||||
* it.
|
||||
*
|
||||
* @param io_context The io_context object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(asio::io_context& io_context,
|
||||
basic_seq_packet_socket(const executor_type& ex,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, protocol)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_seq_packet_socket.
|
||||
/**
|
||||
* This constructor creates and opens a sequenced_packet socket. The socket
|
||||
* needs to be connected or accepted before data can be sent or received on
|
||||
* it.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_seq_packet_socket(ExecutionContext& context,
|
||||
const protocol_type& protocol,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -101,18 +157,43 @@ public:
|
||||
* it bound to the specified endpoint on the local machine. The protocol used
|
||||
* is the protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_context The io_context object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the sequenced
|
||||
* packet socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(asio::io_context& io_context,
|
||||
basic_seq_packet_socket(const executor_type& ex,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, endpoint)
|
||||
: basic_socket<Protocol, Executor>(ex, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket, opening it and binding it to the
|
||||
/// given local endpoint.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket and automatically opens
|
||||
* it bound to the specified endpoint on the local machine. The protocol used
|
||||
* is the protocol associated with the given endpoint.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the sequenced
|
||||
* packet socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_seq_packet_socket(ExecutionContext& context,
|
||||
const endpoint_type& endpoint,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -121,9 +202,8 @@ public:
|
||||
* This constructor creates a sequenced packet socket object to hold an
|
||||
* existing native socket.
|
||||
*
|
||||
* @param io_context The io_context object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
@@ -131,10 +211,34 @@ public:
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(asio::io_context& io_context,
|
||||
basic_seq_packet_socket(const executor_type& ex,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(
|
||||
io_context, protocol, native_socket)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket object to hold an
|
||||
* existing native socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_seq_packet_socket(ExecutionContext& context,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -148,10 +252,11 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_seq_packet_socket(basic_seq_packet_socket&& other)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -164,11 +269,12 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_seq_packet_socket& operator=(basic_seq_packet_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -182,13 +288,16 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
basic_seq_packet_socket(
|
||||
basic_seq_packet_socket<Protocol1 ASIO_SVC_TARG1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
template <typename Protocol1, typename Executor1>
|
||||
basic_seq_packet_socket(basic_seq_packet_socket<Protocol1, Executor1>&& other,
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -202,14 +311,17 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_seq_packet_socket>::type& operator=(
|
||||
basic_seq_packet_socket<Protocol1 ASIO_SVC_TARG1>&& other)
|
||||
template <typename Protocol1, typename Executor1>
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value,
|
||||
basic_seq_packet_socket&
|
||||
>::type operator=(basic_seq_packet_socket<Protocol1, Executor1>&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
@@ -251,8 +363,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -279,8 +391,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@@ -303,9 +415,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
@@ -323,22 +435,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
@@ -375,13 +474,8 @@ public:
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, out_flags, ec);
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
std::size_t s = this->get_service().receive_with_flags(
|
||||
this->get_implementation(), buffers, 0, out_flags, ec);
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
std::size_t s = this->impl_.get_service().receive_with_flags(
|
||||
this->impl_.get_implementation(), buffers, 0, out_flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -427,13 +521,8 @@ public:
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
std::size_t s = this->get_service().receive_with_flags(
|
||||
this->get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
std::size_t s = this->impl_.get_service().receive_with_flags(
|
||||
this->impl_.get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -466,13 +555,8 @@ public:
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags, asio::error_code& ec)
|
||||
{
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().receive(this->get_implementation(),
|
||||
buffers, in_flags, out_flags, ec);
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().receive_with_flags(this->get_implementation(),
|
||||
buffers, in_flags, out_flags, ec);
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->impl_.get_service().receive_with_flags(
|
||||
this->impl_.get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -499,9 +583,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
@@ -520,24 +604,10 @@ public:
|
||||
socket_base::message_flags& out_flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(
|
||||
this->get_implementation(), buffers, 0, out_flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive_with_flags(
|
||||
this->get_implementation(), buffers, 0, out_flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_with_flags(), handler, this,
|
||||
buffers, socket_base::message_flags(0), &out_flags);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -566,9 +636,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
@@ -590,25 +660,49 @@ public:
|
||||
socket_base::message_flags& out_flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(
|
||||
this->get_implementation(), buffers, in_flags, out_flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive_with_flags(
|
||||
this->get_implementation(), buffers, in_flags, out_flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_with_flags(), handler,
|
||||
this, buffers, in_flags, &out_flags);
|
||||
}
|
||||
|
||||
private:
|
||||
struct initiate_async_send
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_seq_packet_socket* self, const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_send(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_receive_with_flags
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_seq_packet_socket* self, const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags* out_flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_receive_with_flags(
|
||||
self->impl_.get_implementation(), buffers, in_flags, *out_flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_serial_port.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
@@ -18,18 +18,29 @@
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#if defined(ASIO_HAS_SERIAL_PORT) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <string>
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/io_object_impl.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
#include "asio/serial_port_base.hpp"
|
||||
#include "asio/serial_port_service.hpp"
|
||||
#if defined(ASIO_HAS_IOCP)
|
||||
# include "asio/detail/win_iocp_serial_port_service.hpp"
|
||||
#else
|
||||
# include "asio/detail/reactive_serial_port_service.hpp"
|
||||
#endif
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
# include <utility>
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
@@ -37,34 +48,63 @@ namespace asio {
|
||||
|
||||
/// Provides serial port functionality.
|
||||
/**
|
||||
* The basic_serial_port class template provides functionality that is common
|
||||
* to all serial ports.
|
||||
* The basic_serial_port class provides a wrapper over serial port
|
||||
* functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename SerialPortService = serial_port_service>
|
||||
template <typename Executor = executor>
|
||||
class basic_serial_port
|
||||
: public basic_io_object<SerialPortService>,
|
||||
public serial_port_base
|
||||
: public serial_port_base
|
||||
{
|
||||
public:
|
||||
/// The native representation of a serial port.
|
||||
typedef typename SerialPortService::native_handle_type native_handle_type;
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// A basic_serial_port is always the lowest layer.
|
||||
typedef basic_serial_port<SerialPortService> lowest_layer_type;
|
||||
/// The native representation of a serial port.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_handle_type;
|
||||
#elif defined(ASIO_HAS_IOCP)
|
||||
typedef detail::win_iocp_serial_port_service::native_handle_type
|
||||
native_handle_type;
|
||||
#else
|
||||
typedef detail::reactive_serial_port_service::native_handle_type
|
||||
native_handle_type;
|
||||
#endif
|
||||
|
||||
/// A basic_basic_serial_port is always the lowest layer.
|
||||
typedef basic_serial_port lowest_layer_type;
|
||||
|
||||
/// Construct a basic_serial_port without opening it.
|
||||
/**
|
||||
* This constructor creates a serial port without opening it.
|
||||
*
|
||||
* @param io_context The io_context object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
* @param ex The I/O executor that the serial port will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* serial port.
|
||||
*/
|
||||
explicit basic_serial_port(asio::io_context& io_context)
|
||||
: basic_io_object<SerialPortService>(io_context)
|
||||
explicit basic_serial_port(const executor_type& ex)
|
||||
: impl_(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_serial_port without opening it.
|
||||
/**
|
||||
* This constructor creates a serial port without opening it.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the serial port will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the serial port.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_serial_port(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value,
|
||||
basic_serial_port
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -73,18 +113,18 @@ public:
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param io_context The io_context object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
* @param ex The I/O executor that the serial port will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* serial port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
explicit basic_serial_port(asio::io_context& io_context,
|
||||
const char* device)
|
||||
: basic_io_object<SerialPortService>(io_context)
|
||||
basic_serial_port(const executor_type& ex, const char* device)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
@@ -93,18 +133,66 @@ public:
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param io_context The io_context object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the serial port will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the serial port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
explicit basic_serial_port(asio::io_context& io_context,
|
||||
const std::string& device)
|
||||
: basic_io_object<SerialPortService>(io_context)
|
||||
template <typename ExecutionContext>
|
||||
basic_serial_port(ExecutionContext& context, const char* device,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Construct and open a basic_serial_port.
|
||||
/**
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param ex The I/O executor that the serial port will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* serial port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
basic_serial_port(const executor_type& ex, const std::string& device)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Construct and open a basic_serial_port.
|
||||
/**
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the serial port will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the serial port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_serial_port(ExecutionContext& context, const std::string& device,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
@@ -113,19 +201,47 @@ public:
|
||||
* This constructor creates a serial port object to hold an existing native
|
||||
* serial port.
|
||||
*
|
||||
* @param io_context The io_context object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
* @param ex The I/O executor that the serial port will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_serial_port(asio::io_context& io_context,
|
||||
basic_serial_port(const executor_type& ex,
|
||||
const native_handle_type& native_serial_port)
|
||||
: basic_io_object<SerialPortService>(io_context)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
impl_.get_service().assign(impl_.get_implementation(),
|
||||
native_serial_port, ec);
|
||||
asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
|
||||
/// Construct a basic_serial_port on an existing native serial port.
|
||||
/**
|
||||
* This constructor creates a serial port object to hold an existing native
|
||||
* serial port.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the serial port will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_serial_port(ExecutionContext& context,
|
||||
const native_handle_type& native_serial_port,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().assign(impl_.get_implementation(),
|
||||
native_serial_port, ec);
|
||||
asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
@@ -139,11 +255,11 @@ public:
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_serial_port(io_context&) constructor.
|
||||
* constructed using the @c basic_serial_port(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_serial_port(basic_serial_port&& other)
|
||||
: basic_io_object<SerialPortService>(
|
||||
ASIO_MOVE_CAST(basic_serial_port)(other))
|
||||
: impl_(std::move(other.impl_))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -155,16 +271,32 @@ public:
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_serial_port(io_context&) constructor.
|
||||
* constructed using the @c basic_serial_port(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_serial_port& operator=(basic_serial_port&& other)
|
||||
{
|
||||
basic_io_object<SerialPortService>::operator=(
|
||||
ASIO_MOVE_CAST(basic_serial_port)(other));
|
||||
impl_ = std::move(other.impl_);
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destroys the serial port.
|
||||
/**
|
||||
* This function destroys the serial port, cancelling any outstanding
|
||||
* asynchronous wait operations associated with the serial port as if by
|
||||
* calling @c cancel.
|
||||
*/
|
||||
~basic_serial_port()
|
||||
{
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return impl_.get_executor();
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
/**
|
||||
* This function returns a reference to the lowest layer in a stack of
|
||||
@@ -204,7 +336,7 @@ public:
|
||||
void open(const std::string& device)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
@@ -220,7 +352,7 @@ public:
|
||||
ASIO_SYNC_OP_VOID open(const std::string& device,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -235,7 +367,7 @@ public:
|
||||
void assign(const native_handle_type& native_serial_port)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
impl_.get_service().assign(impl_.get_implementation(),
|
||||
native_serial_port, ec);
|
||||
asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
@@ -251,7 +383,7 @@ public:
|
||||
ASIO_SYNC_OP_VOID assign(const native_handle_type& native_serial_port,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
impl_.get_service().assign(impl_.get_implementation(),
|
||||
native_serial_port, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
@@ -259,7 +391,7 @@ public:
|
||||
/// Determine whether the serial port is open.
|
||||
bool is_open() const
|
||||
{
|
||||
return this->get_service().is_open(this->get_implementation());
|
||||
return impl_.get_service().is_open(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
@@ -273,7 +405,7 @@ public:
|
||||
void close()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().close(this->get_implementation(), ec);
|
||||
impl_.get_service().close(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "close");
|
||||
}
|
||||
|
||||
@@ -287,7 +419,7 @@ public:
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID close(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().close(this->get_implementation(), ec);
|
||||
impl_.get_service().close(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -299,7 +431,7 @@ public:
|
||||
*/
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return this->get_service().native_handle(this->get_implementation());
|
||||
return impl_.get_service().native_handle(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
@@ -313,7 +445,7 @@ public:
|
||||
void cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().cancel(this->get_implementation(), ec);
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
@@ -327,7 +459,7 @@ public:
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID cancel(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().cancel(this->get_implementation(), ec);
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -341,7 +473,7 @@ public:
|
||||
void send_break()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().send_break(this->get_implementation(), ec);
|
||||
impl_.get_service().send_break(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "send_break");
|
||||
}
|
||||
|
||||
@@ -354,7 +486,7 @@ public:
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID send_break(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().send_break(this->get_implementation(), ec);
|
||||
impl_.get_service().send_break(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -377,7 +509,7 @@ public:
|
||||
void set_option(const SettableSerialPortOption& option)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().set_option(this->get_implementation(), option, ec);
|
||||
impl_.get_service().set_option(impl_.get_implementation(), option, ec);
|
||||
asio::detail::throw_error(ec, "set_option");
|
||||
}
|
||||
|
||||
@@ -400,7 +532,7 @@ public:
|
||||
ASIO_SYNC_OP_VOID set_option(const SettableSerialPortOption& option,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
this->get_service().set_option(this->get_implementation(), option, ec);
|
||||
impl_.get_service().set_option(impl_.get_implementation(), option, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -424,7 +556,7 @@ public:
|
||||
void get_option(GettableSerialPortOption& option)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().get_option(this->get_implementation(), option, ec);
|
||||
impl_.get_service().get_option(impl_.get_implementation(), option, ec);
|
||||
asio::detail::throw_error(ec, "get_option");
|
||||
}
|
||||
|
||||
@@ -448,7 +580,7 @@ public:
|
||||
ASIO_SYNC_OP_VOID get_option(GettableSerialPortOption& option,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
this->get_service().get_option(this->get_implementation(), option, ec);
|
||||
impl_.get_service().get_option(impl_.get_implementation(), option, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -473,7 +605,7 @@ public:
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.write_some(asio::buffer(data, size));
|
||||
* basic_serial_port.write_some(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
@@ -483,8 +615,8 @@ public:
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().write_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
std::size_t s = impl_.get_service().write_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
@@ -509,8 +641,8 @@ public:
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().write_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
return impl_.get_service().write_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
@@ -531,9 +663,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes written.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The write operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
@@ -542,7 +674,8 @@ public:
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.async_write_some(asio::buffer(data, size), handler);
|
||||
* basic_serial_port.async_write_some(
|
||||
* asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
@@ -554,12 +687,9 @@ public:
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_write_some(this->get_implementation(),
|
||||
buffers, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_write_some(), handler, this, buffers);
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
@@ -584,7 +714,7 @@ public:
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.read_some(asio::buffer(data, size));
|
||||
* basic_serial_port.read_some(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
@@ -594,8 +724,8 @@ public:
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().read_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
std::size_t s = impl_.get_service().read_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
@@ -621,8 +751,8 @@ public:
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().read_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
return impl_.get_service().read_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
@@ -643,9 +773,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes read.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The read operation may not read all of the requested number of bytes.
|
||||
* Consider using the @ref async_read function if you need to ensure that the
|
||||
@@ -655,7 +785,8 @@ public:
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.async_read_some(asio::buffer(data, size), handler);
|
||||
* basic_serial_port.async_read_some(
|
||||
* asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
@@ -667,13 +798,55 @@ public:
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_read_some(this->get_implementation(),
|
||||
buffers, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_read_some(), handler, this, buffers);
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_serial_port(const basic_serial_port&) ASIO_DELETED;
|
||||
basic_serial_port& operator=(const basic_serial_port&) ASIO_DELETED;
|
||||
|
||||
struct initiate_async_write_some
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_serial_port* self, const ConstBufferSequence& buffers) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_write_some(
|
||||
self->impl_.get_implementation(), buffers, handler2.value,
|
||||
self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_read_some
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_serial_port* self, const MutableBufferSequence& buffers) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_read_some(
|
||||
self->impl_.get_implementation(), buffers, handler2.value,
|
||||
self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_IOCP)
|
||||
detail::io_object_impl<detail::win_iocp_serial_port_service, Executor> impl_;
|
||||
#else
|
||||
detail::io_object_impl<detail::reactive_serial_port_service, Executor> impl_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
@@ -683,6 +856,4 @@ public:
|
||||
#endif // defined(ASIO_HAS_SERIAL_PORT)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#endif // ASIO_BASIC_SERIAL_PORT_HPP
|
||||
@@ -1,15 +1,15 @@
|
||||
//
|
||||
// signal_set.hpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
// basic_signal_set.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_SIGNAL_SET_HPP
|
||||
#define ASIO_SIGNAL_SET_HPP
|
||||
#ifndef ASIO_BASIC_SIGNAL_SET_HPP
|
||||
#define ASIO_BASIC_SIGNAL_SET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
@@ -18,28 +18,22 @@
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/io_object_impl.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/signal_set_service.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/basic_signal_set.hpp"
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/detail/signal_set_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
// Typedef for the typical usage of a signal set.
|
||||
typedef basic_signal_set<> signal_set;
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
/// Provides signal functionality.
|
||||
/**
|
||||
* The signal_set class provides the ability to perform an asynchronous wait
|
||||
* for one or more signals to occur.
|
||||
* The basic_signal_set class provides the ability to perform an asynchronous
|
||||
* wait for one or more signals to occur.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
@@ -61,7 +55,7 @@ typedef basic_signal_set<> signal_set;
|
||||
* ...
|
||||
*
|
||||
* // Construct a signal set registered for process termination.
|
||||
* asio::signal_set signals(io_context, SIGINT, SIGTERM);
|
||||
* asio::signal_set signals(my_context, SIGINT, SIGTERM);
|
||||
*
|
||||
* // Start an asynchronous wait for one of the signals to occur.
|
||||
* signals.async_wait(handler);
|
||||
@@ -96,22 +90,40 @@ typedef basic_signal_set<> signal_set;
|
||||
* that any signals registered using signal_set objects are unblocked in at
|
||||
* least one thread.
|
||||
*/
|
||||
class signal_set
|
||||
: ASIO_SVC_ACCESS basic_io_object<detail::signal_set_service>
|
||||
template <typename Executor = executor>
|
||||
class basic_signal_set
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef io_context::executor_type executor_type;
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Construct a signal set without adding any signals.
|
||||
/**
|
||||
* This constructor creates a signal set without registering for any signals.
|
||||
*
|
||||
* @param io_context The io_context object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
* @param ex The I/O executor that the signal set will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* signal set.
|
||||
*/
|
||||
explicit signal_set(asio::io_context& io_context)
|
||||
: basic_io_object<detail::signal_set_service>(io_context)
|
||||
explicit basic_signal_set(const executor_type& ex)
|
||||
: impl_(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a signal set without adding any signals.
|
||||
/**
|
||||
* This constructor creates a signal set without registering for any signals.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the signal set will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the signal set.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_signal_set(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -119,20 +131,47 @@ public:
|
||||
/**
|
||||
* This constructor creates a signal set and registers for one signal.
|
||||
*
|
||||
* @param io_context The io_context object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
* @param ex The I/O executor that the signal set will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* signal set.
|
||||
*
|
||||
* @param signal_number_1 The signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(io_context);
|
||||
* @code asio::signal_set signals(ex);
|
||||
* signals.add(signal_number_1); @endcode
|
||||
*/
|
||||
signal_set(asio::io_context& io_context, int signal_number_1)
|
||||
: basic_io_object<detail::signal_set_service>(io_context)
|
||||
basic_signal_set(const executor_type& ex, int signal_number_1)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().add(this->get_implementation(), signal_number_1, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add one signal.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for one signal.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the signal set will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the signal set.
|
||||
*
|
||||
* @param signal_number_1 The signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(context);
|
||||
* signals.add(signal_number_1); @endcode
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_signal_set(ExecutionContext& context, int signal_number_1,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
@@ -140,26 +179,59 @@ public:
|
||||
/**
|
||||
* This constructor creates a signal set and registers for two signals.
|
||||
*
|
||||
* @param io_context The io_context object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
* @param ex The I/O executor that the signal set will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* signal set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(io_context);
|
||||
* @code asio::signal_set signals(ex);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2); @endcode
|
||||
*/
|
||||
signal_set(asio::io_context& io_context, int signal_number_1,
|
||||
basic_signal_set(const executor_type& ex, int signal_number_1,
|
||||
int signal_number_2)
|
||||
: basic_io_object<detail::signal_set_service>(io_context)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().add(this->get_implementation(), signal_number_1, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
this->get_service().add(this->get_implementation(), signal_number_2, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add two signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for two signals.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the signal set will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the signal set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(context);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2); @endcode
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_signal_set(ExecutionContext& context, int signal_number_1,
|
||||
int signal_number_2,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
@@ -167,8 +239,9 @@ public:
|
||||
/**
|
||||
* This constructor creates a signal set and registers for three signals.
|
||||
*
|
||||
* @param io_context The io_context object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
* @param ex The I/O executor that the signal set will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* signal set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
@@ -177,21 +250,58 @@ public:
|
||||
* @param signal_number_3 The third signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(io_context);
|
||||
* @code asio::signal_set signals(ex);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2);
|
||||
* signals.add(signal_number_3); @endcode
|
||||
*/
|
||||
signal_set(asio::io_context& io_context, int signal_number_1,
|
||||
basic_signal_set(const executor_type& ex, int signal_number_1,
|
||||
int signal_number_2, int signal_number_3)
|
||||
: basic_io_object<detail::signal_set_service>(io_context)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().add(this->get_implementation(), signal_number_1, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
this->get_service().add(this->get_implementation(), signal_number_2, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
this->get_service().add(this->get_implementation(), signal_number_3, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_3, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add three signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for three signals.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the signal set will use, by default, to dispatch handlers for any
|
||||
* asynchronous operations performed on the signal set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @param signal_number_3 The third signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(context);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2);
|
||||
* signals.add(signal_number_3); @endcode
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_signal_set(ExecutionContext& context, int signal_number_1,
|
||||
int signal_number_2, int signal_number_3,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number_3, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
@@ -201,44 +311,14 @@ public:
|
||||
* asynchronous wait operations associated with the signal set as if by
|
||||
* calling @c cancel.
|
||||
*/
|
||||
~signal_set()
|
||||
~basic_signal_set()
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
/**
|
||||
* This function may be used to obtain the io_context object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_context object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return basic_io_object<detail::signal_set_service>::get_io_context();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
/**
|
||||
* This function may be used to obtain the io_context object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_context object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return basic_io_object<detail::signal_set_service>::get_io_service();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return basic_io_object<detail::signal_set_service>::get_executor();
|
||||
return impl_.get_executor();
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
@@ -253,7 +333,7 @@ public:
|
||||
void add(int signal_number)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().add(this->get_implementation(), signal_number, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
@@ -269,7 +349,7 @@ public:
|
||||
ASIO_SYNC_OP_VOID add(int signal_number,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
this->get_service().add(this->get_implementation(), signal_number, ec);
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -288,7 +368,7 @@ public:
|
||||
void remove(int signal_number)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().remove(this->get_implementation(), signal_number, ec);
|
||||
impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
|
||||
asio::detail::throw_error(ec, "remove");
|
||||
}
|
||||
|
||||
@@ -307,7 +387,7 @@ public:
|
||||
ASIO_SYNC_OP_VOID remove(int signal_number,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
this->get_service().remove(this->get_implementation(), signal_number, ec);
|
||||
impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -323,7 +403,7 @@ public:
|
||||
void clear()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().clear(this->get_implementation(), ec);
|
||||
impl_.get_service().clear(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "clear");
|
||||
}
|
||||
|
||||
@@ -338,7 +418,7 @@ public:
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID clear(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().clear(this->get_implementation(), ec);
|
||||
impl_.get_service().clear(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -366,7 +446,7 @@ public:
|
||||
void cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().cancel(this->get_implementation(), ec);
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
@@ -393,7 +473,7 @@ public:
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID cancel(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().cancel(this->get_implementation(), ec);
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
@@ -418,30 +498,44 @@ public:
|
||||
* int signal_number // Indicates which signal occurred.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename SignalHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(SignalHandler,
|
||||
void (asio::error_code, int))
|
||||
async_wait(ASIO_MOVE_ARG(SignalHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a SignalHandler.
|
||||
ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
|
||||
|
||||
async_completion<SignalHandler,
|
||||
void (asio::error_code, int)> init(handler);
|
||||
|
||||
this->get_service().async_wait(this->get_implementation(),
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
return async_initiate<SignalHandler, void (asio::error_code, int)>(
|
||||
initiate_async_wait(), handler, this);
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_signal_set(const basic_signal_set&) ASIO_DELETED;
|
||||
basic_signal_set& operator=(const basic_signal_set&) ASIO_DELETED;
|
||||
|
||||
struct initiate_async_wait
|
||||
{
|
||||
template <typename SignalHandler>
|
||||
void operator()(ASIO_MOVE_ARG(SignalHandler) handler,
|
||||
basic_signal_set* self) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a SignalHandler.
|
||||
ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<SignalHandler> handler2(handler);
|
||||
self->impl_.get_service().async_wait(
|
||||
self->impl_.get_implementation(), handler2.value,
|
||||
self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
detail::io_object_impl<detail::signal_set_service, Executor> impl_;
|
||||
};
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_SIGNAL_SET_HPP
|
||||
#endif // ASIO_BASIC_SIGNAL_SET_HPP
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
// basic_socket_iostream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -23,10 +23,6 @@
|
||||
#include <ostream>
|
||||
#include "asio/basic_socket_streambuf.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/stream_socket_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include "asio/detail/variadic_templates.hpp"
|
||||
@@ -36,8 +32,7 @@
|
||||
// explicit basic_socket_iostream(T1 x1, ..., Tn xn)
|
||||
// : std::basic_iostream<char>(
|
||||
// &this->detail::socket_iostream_base<
|
||||
// Protocol ASIO_SVC_TARG, Clock,
|
||||
// WaitTraits ASIO_SVC_TARG1>::streambuf_)
|
||||
// Protocol, Clock, WaitTraits>::streambuf_)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
@@ -49,8 +44,7 @@
|
||||
explicit basic_socket_iostream(ASIO_VARIADIC_BYVAL_PARAMS(n)) \
|
||||
: std::basic_iostream<char>( \
|
||||
&this->detail::socket_iostream_base< \
|
||||
Protocol ASIO_SVC_TARG, Clock, \
|
||||
WaitTraits ASIO_SVC_TARG1>::streambuf_) \
|
||||
Protocol, Clock, WaitTraits>::streambuf_) \
|
||||
{ \
|
||||
this->setf(std::ios_base::unitbuf); \
|
||||
if (rdbuf()->connect(ASIO_VARIADIC_BYVAL_ARGS(n)) == 0) \
|
||||
@@ -85,8 +79,7 @@ namespace detail {
|
||||
|
||||
// A separate base class is used to ensure that the streambuf is initialised
|
||||
// prior to the basic_socket_iostream's basic_iostream base class.
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
typename Clock, typename WaitTraits ASIO_SVC_TPARAM1>
|
||||
template <typename Protocol, typename Clock, typename WaitTraits>
|
||||
class socket_iostream_base
|
||||
{
|
||||
protected:
|
||||
@@ -112,8 +105,7 @@ protected:
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
basic_socket_streambuf<Protocol ASIO_SVC_TARG,
|
||||
Clock, WaitTraits ASIO_SVC_TARG1> streambuf_;
|
||||
basic_socket_streambuf<Protocol, Clock, WaitTraits> streambuf_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
@@ -122,17 +114,17 @@ protected:
|
||||
#define ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Protocol
|
||||
ASIO_SVC_TPARAM_DEF1(= stream_socket_service<Protocol>),
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
template <typename Protocol,
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typename Clock = boost::posix_time::ptime,
|
||||
typename WaitTraits = time_traits<Clock>
|
||||
ASIO_SVC_TPARAM1_DEF2(= deadline_timer_service<Clock, WaitTraits>)>
|
||||
#else
|
||||
typename WaitTraits = time_traits<Clock> >
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typename Clock = chrono::steady_clock,
|
||||
typename WaitTraits = wait_traits<Clock>
|
||||
ASIO_SVC_TPARAM1_DEF1(= steady_timer::service_type)>
|
||||
#endif
|
||||
typename WaitTraits = wait_traits<Clock> >
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
class basic_socket_iostream;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL)
|
||||
@@ -143,22 +135,23 @@ template <typename Protocol,
|
||||
typename Clock = chrono::steady_clock,
|
||||
typename WaitTraits = wait_traits<Clock> >
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
typename Clock, typename WaitTraits ASIO_SVC_TPARAM1>
|
||||
template <typename Protocol, typename Clock, typename WaitTraits>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
class basic_socket_iostream
|
||||
: private detail::socket_iostream_base<Protocol
|
||||
ASIO_SVC_TARG, Clock, WaitTraits ASIO_SVC_TARG1>,
|
||||
: private detail::socket_iostream_base<Protocol, Clock, WaitTraits>,
|
||||
public std::basic_iostream<char>
|
||||
{
|
||||
private:
|
||||
// These typedefs are intended keep this class's implementation independent
|
||||
// of whether it's using Boost.DateClock, Boost.Chrono or std::chrono.
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typedef WaitTraits traits_helper;
|
||||
#else
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typedef detail::chrono_time_traits<Clock, WaitTraits> traits_helper;
|
||||
#endif
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
|
||||
public:
|
||||
/// The protocol type.
|
||||
@@ -195,8 +188,7 @@ public:
|
||||
basic_socket_iostream()
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>::streambuf_)
|
||||
Protocol, Clock, WaitTraits>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
}
|
||||
@@ -205,12 +197,10 @@ public:
|
||||
/// Construct a basic_socket_iostream from the supplied socket.
|
||||
explicit basic_socket_iostream(basic_stream_socket<protocol_type> s)
|
||||
: detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>(std::move(s)),
|
||||
Protocol, Clock, WaitTraits>(std::move(s)),
|
||||
std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>::streambuf_)
|
||||
Protocol, Clock, WaitTraits>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
}
|
||||
@@ -220,13 +210,11 @@ public:
|
||||
/// Move-construct a basic_socket_iostream from another.
|
||||
basic_socket_iostream(basic_socket_iostream&& other)
|
||||
: detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>(std::move(other)),
|
||||
Protocol, Clock, WaitTraits>(std::move(other)),
|
||||
std::basic_iostream<char>(std::move(other))
|
||||
{
|
||||
this->set_rdbuf(&this->detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>::streambuf_);
|
||||
Protocol, Clock, WaitTraits>::streambuf_);
|
||||
}
|
||||
|
||||
/// Move-assign a basic_socket_iostream from another.
|
||||
@@ -234,8 +222,7 @@ public:
|
||||
{
|
||||
std::basic_iostream<char>::operator=(std::move(other));
|
||||
detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>::operator=(std::move(other));
|
||||
Protocol, Clock, WaitTraits>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_STD_IOSTREAM_MOVE)
|
||||
@@ -256,8 +243,7 @@ public:
|
||||
explicit basic_socket_iostream(T... x)
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>::streambuf_)
|
||||
Protocol, Clock, WaitTraits>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
@@ -295,18 +281,15 @@ public:
|
||||
}
|
||||
|
||||
/// Return a pointer to the underlying streambuf.
|
||||
basic_socket_streambuf<Protocol ASIO_SVC_TARG,
|
||||
Clock, WaitTraits ASIO_SVC_TARG1>* rdbuf() const
|
||||
basic_socket_streambuf<Protocol, Clock, WaitTraits>* rdbuf() const
|
||||
{
|
||||
return const_cast<basic_socket_streambuf<Protocol ASIO_SVC_TARG,
|
||||
Clock, WaitTraits ASIO_SVC_TARG1>*>(
|
||||
return const_cast<basic_socket_streambuf<Protocol, Clock, WaitTraits>*>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol ASIO_SVC_TARG, Clock,
|
||||
WaitTraits ASIO_SVC_TARG1>::streambuf_);
|
||||
Protocol, Clock, WaitTraits>::streambuf_);
|
||||
}
|
||||
|
||||
/// Get a reference to the underlying socket.
|
||||
basic_socket<Protocol ASIO_SVC_TARG>& socket()
|
||||
basic_socket<Protocol>& socket()
|
||||
{
|
||||
return rdbuf()->socket();
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_socket_streambuf.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -28,19 +28,14 @@
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/stream_socket_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/deadline_timer_service.hpp"
|
||||
# else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/detail/deadline_timer_service.hpp"
|
||||
# endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
#else
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
# include "asio/detail/deadline_timer_service.hpp"
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
# include "asio/steady_timer.hpp"
|
||||
#endif
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
@@ -52,7 +47,7 @@
|
||||
// {
|
||||
// init_buffers();
|
||||
// typedef typename Protocol::resolver resolver_type;
|
||||
// resolver_type resolver(socket().get_executor().context());
|
||||
// resolver_type resolver(socket().get_executor());
|
||||
// connect_to_endpoints(
|
||||
// resolver.resolve(x1, ..., xn, ec_));
|
||||
// return !ec_ ? this : 0;
|
||||
@@ -65,7 +60,7 @@
|
||||
{ \
|
||||
init_buffers(); \
|
||||
typedef typename Protocol::resolver resolver_type; \
|
||||
resolver_type resolver(socket().get_executor().context()); \
|
||||
resolver_type resolver(socket().get_executor()); \
|
||||
connect_to_endpoints( \
|
||||
resolver.resolve(ASIO_VARIADIC_BYVAL_ARGS(n), ec_)); \
|
||||
return !ec_ ? this : 0; \
|
||||
@@ -74,10 +69,6 @@
|
||||
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#if !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# define ASIO_SVC_T1 detail::deadline_timer_service<traits_helper>
|
||||
#endif // !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
@@ -121,17 +112,17 @@ protected:
|
||||
#define ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Protocol
|
||||
ASIO_SVC_TPARAM_DEF1(= stream_socket_service<Protocol>),
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
template <typename Protocol,
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typename Clock = boost::posix_time::ptime,
|
||||
typename WaitTraits = time_traits<Clock>
|
||||
ASIO_SVC_TPARAM1_DEF2(= deadline_timer_service<Clock, WaitTraits>)>
|
||||
#else
|
||||
typename WaitTraits = time_traits<Clock> >
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typename Clock = chrono::steady_clock,
|
||||
typename WaitTraits = wait_traits<Clock>
|
||||
ASIO_SVC_TPARAM1_DEF1(= steady_timer::service_type)>
|
||||
#endif
|
||||
typename WaitTraits = wait_traits<Clock> >
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
class basic_socket_streambuf;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL)
|
||||
@@ -142,27 +133,29 @@ template <typename Protocol,
|
||||
typename Clock = chrono::steady_clock,
|
||||
typename WaitTraits = wait_traits<Clock> >
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
typename Clock, typename WaitTraits ASIO_SVC_TPARAM1>
|
||||
template <typename Protocol, typename Clock, typename WaitTraits>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
class basic_socket_streambuf
|
||||
: public std::streambuf,
|
||||
private detail::socket_streambuf_io_context,
|
||||
private detail::socket_streambuf_buffers,
|
||||
#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
|
||||
private basic_socket<Protocol ASIO_SVC_TARG>
|
||||
private basic_socket<Protocol>
|
||||
#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
|
||||
public basic_socket<Protocol ASIO_SVC_TARG>
|
||||
public basic_socket<Protocol>
|
||||
#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
private:
|
||||
// These typedefs are intended keep this class's implementation independent
|
||||
// of whether it's using Boost.DateClock, Boost.Chrono or std::chrono.
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typedef WaitTraits traits_helper;
|
||||
#else
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typedef detail::chrono_time_traits<Clock, WaitTraits> traits_helper;
|
||||
#endif
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
|
||||
public:
|
||||
/// The protocol type.
|
||||
@@ -198,7 +191,7 @@ public:
|
||||
/// Construct a basic_socket_streambuf without establishing a connection.
|
||||
basic_socket_streambuf()
|
||||
: detail::socket_streambuf_io_context(new io_context),
|
||||
basic_socket<Protocol ASIO_SVC_TARG>(*default_io_context_),
|
||||
basic_socket<Protocol>(*default_io_context_),
|
||||
expiry_time_(max_expiry_time())
|
||||
{
|
||||
init_buffers();
|
||||
@@ -208,7 +201,7 @@ public:
|
||||
/// Construct a basic_socket_streambuf from the supplied socket.
|
||||
explicit basic_socket_streambuf(basic_stream_socket<protocol_type> s)
|
||||
: detail::socket_streambuf_io_context(0),
|
||||
basic_socket<Protocol ASIO_SVC_TARG>(std::move(s)),
|
||||
basic_socket<Protocol>(std::move(s)),
|
||||
expiry_time_(max_expiry_time())
|
||||
{
|
||||
init_buffers();
|
||||
@@ -217,7 +210,7 @@ public:
|
||||
/// Move-construct a basic_socket_streambuf from another.
|
||||
basic_socket_streambuf(basic_socket_streambuf&& other)
|
||||
: detail::socket_streambuf_io_context(other),
|
||||
basic_socket<Protocol ASIO_SVC_TARG>(std::move(other.socket())),
|
||||
basic_socket<Protocol>(std::move(other.socket())),
|
||||
ec_(other.ec_),
|
||||
expiry_time_(other.expiry_time_)
|
||||
{
|
||||
@@ -290,7 +283,7 @@ public:
|
||||
{
|
||||
init_buffers();
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
resolver_type resolver(socket().get_executor().context());
|
||||
resolver_type resolver(socket().get_executor());
|
||||
connect_to_endpoints(resolver.resolve(x..., ec_));
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
@@ -313,7 +306,7 @@ public:
|
||||
}
|
||||
|
||||
/// Get a reference to the underlying socket.
|
||||
basic_socket<Protocol ASIO_SVC_TARG>& socket()
|
||||
basic_socket<Protocol>& socket()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
@@ -666,11 +659,14 @@ private:
|
||||
// Helper function to get the maximum expiry time.
|
||||
static time_point max_expiry_time()
|
||||
{
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
return boost::posix_time::pos_infin;
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
return (time_point::max)();
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
}
|
||||
|
||||
enum { putback_max = 8 };
|
||||
@@ -682,10 +678,6 @@ private:
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# undef ASIO_SVC_T1
|
||||
#endif // !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_stream_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -20,17 +20,23 @@
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/stream_socket_service.hpp"
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if !defined(ASIO_BASIC_STREAM_SOCKET_FWD_DECL)
|
||||
#define ASIO_BASIC_STREAM_SOCKET_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Protocol, typename Executor = executor>
|
||||
class basic_stream_socket;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_STREAM_SOCKET_FWD_DECL)
|
||||
|
||||
/// Provides stream-oriented socket functionality.
|
||||
/**
|
||||
* The basic_stream_socket class template provides asynchronous and blocking
|
||||
@@ -43,18 +49,28 @@ namespace asio {
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Protocol
|
||||
ASIO_SVC_TPARAM_DEF1(= stream_socket_service<Protocol>)>
|
||||
template <typename Protocol, typename Executor>
|
||||
class basic_stream_socket
|
||||
: public basic_socket<Protocol ASIO_SVC_TARG>
|
||||
: public basic_socket<Protocol, Executor>
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the socket type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The socket type when rebound to the specified executor.
|
||||
typedef basic_stream_socket<Protocol, Executor1> other;
|
||||
};
|
||||
|
||||
/// The native representation of a socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_handle_type;
|
||||
#else
|
||||
typedef typename basic_socket<
|
||||
Protocol ASIO_SVC_TARG>::native_handle_type native_handle_type;
|
||||
typedef typename basic_socket<Protocol,
|
||||
Executor>::native_handle_type native_handle_type;
|
||||
#endif
|
||||
|
||||
/// The protocol type.
|
||||
@@ -69,11 +85,30 @@ public:
|
||||
* needs to be opened and then connected or accepted before data can be sent
|
||||
* or received on it.
|
||||
*
|
||||
* @param io_context The io_context object that the stream socket will use to
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_stream_socket(asio::io_context& io_context)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context)
|
||||
explicit basic_stream_socket(const executor_type& ex)
|
||||
: basic_socket<Protocol, Executor>(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a stream socket without opening it. The socket
|
||||
* needs to be opened and then connected or accepted before data can be sent
|
||||
* or received on it.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_stream_socket(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -82,16 +117,37 @@ public:
|
||||
* This constructor creates and opens a stream socket. The socket needs to be
|
||||
* connected or accepted before data can be sent or received on it.
|
||||
*
|
||||
* @param io_context The io_context object that the stream socket will use to
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(asio::io_context& io_context,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, protocol)
|
||||
basic_stream_socket(const executor_type& ex, const protocol_type& protocol)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_stream_socket.
|
||||
/**
|
||||
* This constructor creates and opens a stream socket. The socket needs to be
|
||||
* connected or accepted before data can be sent or received on it.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_stream_socket(ExecutionContext& context, const protocol_type& protocol,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -102,7 +158,7 @@ public:
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_context The io_context object that the stream socket will use to
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the stream
|
||||
@@ -110,9 +166,33 @@ public:
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(asio::io_context& io_context,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(io_context, endpoint)
|
||||
basic_stream_socket(const executor_type& ex, const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, Executor>(ex, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a stream socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the stream
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_stream_socket(ExecutionContext& context, const endpoint_type& endpoint,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -121,7 +201,7 @@ public:
|
||||
* This constructor creates a stream socket object to hold an existing native
|
||||
* socket.
|
||||
*
|
||||
* @param io_context The io_context object that the stream socket will use to
|
||||
* @param ex The I/O executor that the socket will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
@@ -130,10 +210,34 @@ public:
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(asio::io_context& io_context,
|
||||
basic_stream_socket(const executor_type& ex,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(
|
||||
io_context, protocol, native_socket)
|
||||
: basic_socket<Protocol, Executor>(ex, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a stream socket object to hold an existing native
|
||||
* socket.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the socket will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
basic_stream_socket(ExecutionContext& context,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(context, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -146,10 +250,11 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_stream_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_stream_socket(basic_stream_socket&& other)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -161,11 +266,12 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_stream_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_stream_socket& operator=(basic_stream_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -178,13 +284,16 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_stream_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
basic_stream_socket(
|
||||
basic_stream_socket<Protocol1 ASIO_SVC_TARG1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol ASIO_SVC_TARG>(std::move(other))
|
||||
template <typename Protocol1, typename Executor1>
|
||||
basic_stream_socket(basic_stream_socket<Protocol1, Executor1>&& other,
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value
|
||||
>::type* = 0)
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -196,14 +305,17 @@ public:
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_context&) constructor.
|
||||
* constructed using the @c basic_stream_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
template <typename Protocol1 ASIO_SVC_TPARAM1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_stream_socket>::type& operator=(
|
||||
basic_stream_socket<Protocol1 ASIO_SVC_TARG1>&& other)
|
||||
template <typename Protocol1, typename Executor1>
|
||||
typename enable_if<
|
||||
is_convertible<Protocol1, Protocol>::value
|
||||
&& is_convertible<Executor1, Executor>::value,
|
||||
basic_stream_socket&
|
||||
>::type operator=(basic_stream_socket<Protocol1, Executor1>&& other)
|
||||
{
|
||||
basic_socket<Protocol ASIO_SVC_TARG>::operator=(std::move(other));
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
@@ -246,8 +358,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -284,8 +396,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
@@ -312,8 +424,8 @@ public:
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@@ -334,9 +446,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
@@ -357,24 +469,10 @@ public:
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(
|
||||
this->get_implementation(), buffers, 0,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(
|
||||
this->get_implementation(), buffers, 0,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@@ -397,9 +495,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
@@ -421,24 +519,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(
|
||||
this->get_implementation(), buffers, flags,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(
|
||||
this->get_implementation(), buffers, flags,
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
@@ -473,8 +556,8 @@ public:
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -514,8 +597,8 @@ public:
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
@@ -542,8 +625,8 @@ public:
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
return this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -564,9 +647,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref async_read function if you need to ensure
|
||||
@@ -589,22 +672,10 @@ public:
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@@ -627,9 +698,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref async_read function if you need to ensure
|
||||
@@ -653,22 +724,9 @@ public:
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this, buffers, flags);
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
@@ -702,8 +760,8 @@ public:
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
@@ -728,7 +786,8 @@ public:
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(this->get_implementation(), buffers, 0, ec);
|
||||
return this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
@@ -749,9 +808,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes written.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The write operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
@@ -772,22 +831,10 @@ public:
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WriteHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
@@ -822,8 +869,8 @@ public:
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
std::size_t s = this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
@@ -849,8 +896,8 @@ public:
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
return this->impl_.get_service().receive(
|
||||
this->impl_.get_implementation(), buffers, 0, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
@@ -871,9 +918,9 @@ public:
|
||||
* std::size_t bytes_transferred // Number of bytes read.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note The read operation may not read all of the requested number of bytes.
|
||||
* Consider using the @ref async_read function if you need to ensure that the
|
||||
@@ -895,23 +942,48 @@ public:
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<ReadHandler,
|
||||
void (asio::error_code, std::size_t)> init(handler);
|
||||
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive(), handler, this,
|
||||
buffers, socket_base::message_flags(0));
|
||||
}
|
||||
|
||||
private:
|
||||
struct initiate_async_send
|
||||
{
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
basic_stream_socket* self, const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WriteHandler> handler2(handler);
|
||||
self->impl_.get_service().async_send(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
struct initiate_async_receive
|
||||
{
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
basic_stream_socket* self, const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<ReadHandler> handler2(handler);
|
||||
self->impl_.get_service().async_receive(
|
||||
self->impl_.get_implementation(), buffers, flags,
|
||||
handler2.value, self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_streambuf.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_streambuf_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// basic_waitable_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -17,26 +17,20 @@
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/detail/chrono_time_traits.hpp"
|
||||
#include "asio/detail/deadline_timer_service.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/io_object_impl.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
#include "asio/wait_traits.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
# include <utility>
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/waitable_timer_service.hpp"
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# include "asio/detail/chrono_time_traits.hpp"
|
||||
# include "asio/detail/deadline_timer_service.hpp"
|
||||
# define ASIO_SVC_T \
|
||||
detail::deadline_timer_service< \
|
||||
detail::chrono_time_traits<Clock, WaitTraits> >
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
@@ -46,8 +40,8 @@ namespace asio {
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Clock,
|
||||
typename WaitTraits = asio::wait_traits<Clock>
|
||||
ASIO_SVC_TPARAM_DEF2(= waitable_timer_service<Clock, WaitTraits>)>
|
||||
typename WaitTraits = asio::wait_traits<Clock>,
|
||||
typename Executor = executor>
|
||||
class basic_waitable_timer;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_WAITABLE_TIMER_FWD_DECL)
|
||||
@@ -75,7 +69,7 @@ class basic_waitable_timer;
|
||||
* Performing a blocking wait (C++11):
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* asio::steady_timer timer(io_context);
|
||||
* asio::steady_timer timer(my_context);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_after(std::chrono::seconds(5));
|
||||
@@ -98,7 +92,7 @@ class basic_waitable_timer;
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* asio::steady_timer timer(io_context,
|
||||
* asio::steady_timer timer(my_context,
|
||||
* std::chrono::steady_clock::now() + std::chrono::seconds(60));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
@@ -144,13 +138,12 @@ class basic_waitable_timer;
|
||||
* @li If a wait handler is cancelled, the asio::error_code passed to
|
||||
* it contains the value asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Clock, typename WaitTraits ASIO_SVC_TPARAM>
|
||||
template <typename Clock, typename WaitTraits, typename Executor>
|
||||
class basic_waitable_timer
|
||||
: ASIO_SVC_ACCESS basic_io_object<ASIO_SVC_T>
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef io_context::executor_type executor_type;
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// The clock type.
|
||||
typedef Clock clock_type;
|
||||
@@ -170,11 +163,30 @@ public:
|
||||
* expires_at() or expires_after() functions must be called to set an expiry
|
||||
* time before the timer can be waited on.
|
||||
*
|
||||
* @param io_context The io_context object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
* @param ex The I/O executor that the timer will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the timer.
|
||||
*/
|
||||
explicit basic_waitable_timer(asio::io_context& io_context)
|
||||
: basic_io_object<ASIO_SVC_T>(io_context)
|
||||
explicit basic_waitable_timer(const executor_type& ex)
|
||||
: impl_(ex)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor.
|
||||
/**
|
||||
* This constructor creates a timer without setting an expiry time. The
|
||||
* expires_at() or expires_after() functions must be called to set an expiry
|
||||
* time before the timer can be waited on.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the timer will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the timer.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_waitable_timer(ExecutionContext& context,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -182,18 +194,41 @@ public:
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_context The io_context object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
* @param ex The I/O executor object that the timer will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
basic_waitable_timer(asio::io_context& io_context,
|
||||
const time_point& expiry_time)
|
||||
: basic_io_object<ASIO_SVC_T>(io_context)
|
||||
basic_waitable_timer(const executor_type& ex, const time_point& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().expires_at(this->get_implementation(), expiry_time, ec);
|
||||
impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the timer will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_waitable_timer(ExecutionContext& context,
|
||||
const time_point& expiry_time,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
@@ -201,19 +236,43 @@ public:
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_context The io_context object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
* @param ex The I/O executor that the timer will use, by default, to
|
||||
* dispatch handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
basic_waitable_timer(asio::io_context& io_context,
|
||||
const duration& expiry_time)
|
||||
: basic_io_object<ASIO_SVC_T>(io_context)
|
||||
basic_waitable_timer(const executor_type& ex, const duration& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().expires_after(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
impl_.get_service().expires_after(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_after");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param context An execution context which provides the I/O executor that
|
||||
* the timer will use, by default, to dispatch handlers for any asynchronous
|
||||
* operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
template <typename ExecutionContext>
|
||||
explicit basic_waitable_timer(ExecutionContext& context,
|
||||
const duration& expiry_time,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0)
|
||||
: impl_(context)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().expires_after(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_after");
|
||||
}
|
||||
|
||||
@@ -226,10 +285,11 @@ public:
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_waitable_timer(io_context&) constructor.
|
||||
* constructed using the @c basic_waitable_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_waitable_timer(basic_waitable_timer&& other)
|
||||
: basic_io_object<ASIO_SVC_T>(std::move(other))
|
||||
: impl_(std::move(other.impl_))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -242,11 +302,12 @@ public:
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_waitable_timer(io_context&) constructor.
|
||||
* constructed using the @c basic_waitable_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_waitable_timer& operator=(basic_waitable_timer&& other)
|
||||
{
|
||||
basic_io_object<ASIO_SVC_T>::operator=(std::move(other));
|
||||
impl_ = std::move(other.impl_);
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
@@ -260,45 +321,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
// These functions are provided by basic_io_object<>.
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
/**
|
||||
* This function may be used to obtain the io_context object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_context object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return basic_io_object<ASIO_SVC_T>::get_io_context();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
/**
|
||||
* This function may be used to obtain the io_context object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_context object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return basic_io_object<ASIO_SVC_T>::get_io_service();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return basic_io_object<ASIO_SVC_T>::get_executor();
|
||||
return impl_.get_executor();
|
||||
}
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
@@ -325,7 +352,7 @@ public:
|
||||
std::size_t cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().cancel(this->get_implementation(), ec);
|
||||
std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
@@ -356,7 +383,7 @@ public:
|
||||
*/
|
||||
std::size_t cancel(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().cancel(this->get_implementation(), ec);
|
||||
return impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
@@ -387,8 +414,8 @@ public:
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().cancel_one(
|
||||
this->get_implementation(), ec);
|
||||
std::size_t s = impl_.get_service().cancel_one(
|
||||
impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
@@ -421,7 +448,7 @@ public:
|
||||
*/
|
||||
std::size_t cancel_one(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().cancel_one(this->get_implementation(), ec);
|
||||
return impl_.get_service().cancel_one(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expiry().) Get the timer's expiry time as an absolute
|
||||
@@ -432,7 +459,7 @@ public:
|
||||
*/
|
||||
time_point expires_at() const
|
||||
{
|
||||
return this->get_service().expires_at(this->get_implementation());
|
||||
return impl_.get_service().expires_at(impl_.get_implementation());
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
@@ -443,7 +470,7 @@ public:
|
||||
*/
|
||||
time_point expiry() const
|
||||
{
|
||||
return this->get_service().expiry(this->get_implementation());
|
||||
return impl_.get_service().expiry(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
@@ -471,8 +498,8 @@ public:
|
||||
std::size_t expires_at(const time_point& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().expires_at(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
std::size_t s = impl_.get_service().expires_at(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
return s;
|
||||
}
|
||||
@@ -504,8 +531,8 @@ public:
|
||||
std::size_t expires_at(const time_point& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().expires_at(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
return impl_.get_service().expires_at(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
@@ -534,8 +561,8 @@ public:
|
||||
std::size_t expires_after(const duration& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().expires_after(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
std::size_t s = impl_.get_service().expires_after(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_after");
|
||||
return s;
|
||||
}
|
||||
@@ -548,7 +575,7 @@ public:
|
||||
*/
|
||||
duration expires_from_now() const
|
||||
{
|
||||
return this->get_service().expires_from_now(this->get_implementation());
|
||||
return impl_.get_service().expires_from_now(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expires_after().) Set the timer's expiry time relative
|
||||
@@ -577,8 +604,8 @@ public:
|
||||
std::size_t expires_from_now(const duration& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().expires_from_now(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
std::size_t s = impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
return s;
|
||||
}
|
||||
@@ -609,8 +636,8 @@ public:
|
||||
std::size_t expires_from_now(const duration& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().expires_from_now(
|
||||
this->get_implementation(), expiry_time, ec);
|
||||
return impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
@@ -624,7 +651,7 @@ public:
|
||||
void wait()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().wait(this->get_implementation(), ec);
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
@@ -637,7 +664,7 @@ public:
|
||||
*/
|
||||
void wait(asio::error_code& ec)
|
||||
{
|
||||
this->get_service().wait(this->get_implementation(), ec);
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
@@ -660,31 +687,17 @@ public:
|
||||
* const asio::error_code& error // Result of operation.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <typename WaitHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WaitHandler.
|
||||
ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return this->get_service().async_wait(this->get_implementation(),
|
||||
ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
async_completion<WaitHandler,
|
||||
void (asio::error_code)> init(handler);
|
||||
|
||||
this->get_service().async_wait(this->get_implementation(),
|
||||
init.completion_handler);
|
||||
|
||||
return init.result.get();
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
return async_initiate<WaitHandler, void (asio::error_code)>(
|
||||
initiate_async_wait(), handler, this);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -692,14 +705,32 @@ private:
|
||||
basic_waitable_timer(const basic_waitable_timer&) ASIO_DELETED;
|
||||
basic_waitable_timer& operator=(
|
||||
const basic_waitable_timer&) ASIO_DELETED;
|
||||
|
||||
struct initiate_async_wait
|
||||
{
|
||||
template <typename WaitHandler>
|
||||
void operator()(ASIO_MOVE_ARG(WaitHandler) handler,
|
||||
basic_waitable_timer* self) const
|
||||
{
|
||||
// If you get an error on the following line it means that your handler
|
||||
// does not meet the documented type requirements for a WaitHandler.
|
||||
ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<WaitHandler> handler2(handler);
|
||||
self->impl_.get_service().async_wait(
|
||||
self->impl_.get_implementation(), handler2.value,
|
||||
self->impl_.get_implementation_executor());
|
||||
}
|
||||
};
|
||||
|
||||
detail::io_object_impl<
|
||||
detail::deadline_timer_service<
|
||||
detail::chrono_time_traits<Clock, WaitTraits> >,
|
||||
executor_type > impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# undef ASIO_SVC_T
|
||||
#endif // !defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
#endif // ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// bind_executor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -547,37 +547,6 @@ private:
|
||||
async_result<T, Signature> target_;
|
||||
};
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename T, typename Executor, typename Signature>
|
||||
struct handler_type<executor_binder<T, Executor>, Signature>
|
||||
{
|
||||
typedef executor_binder<
|
||||
typename handler_type<T, Signature>::type, Executor> type;
|
||||
};
|
||||
|
||||
template <typename T, typename Executor>
|
||||
class async_result<executor_binder<T, Executor> >
|
||||
{
|
||||
public:
|
||||
typedef typename async_result<T>::type type;
|
||||
|
||||
explicit async_result(executor_binder<T, Executor>& b)
|
||||
: target_(b.get())
|
||||
{
|
||||
}
|
||||
|
||||
type get()
|
||||
{
|
||||
return target_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
async_result<T> target_;
|
||||
};
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename T, typename Executor, typename Allocator>
|
||||
struct associated_allocator<executor_binder<T, Executor>, Allocator>
|
||||
{
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffer.hpp
|
||||
// ~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "asio/detail/array_fwd.hpp"
|
||||
#include "asio/detail/is_buffer_sequence.hpp"
|
||||
#include "asio/detail/memory.hpp"
|
||||
#include "asio/detail/string_view.hpp"
|
||||
#include "asio/detail/throw_exception.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
@@ -346,41 +346,6 @@ public:
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Trait to determine whether a type satisfies the MutableBufferSequence
|
||||
/// requirements.
|
||||
template <typename T>
|
||||
struct is_mutable_buffer_sequence
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_buffer_sequence<T, mutable_buffer>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
/// Trait to determine whether a type satisfies the ConstBufferSequence
|
||||
/// requirements.
|
||||
template <typename T>
|
||||
struct is_const_buffer_sequence
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_buffer_sequence<T, const_buffer>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
/// Trait to determine whether a type satisfies the DynamicBuffer requirements.
|
||||
template <typename T>
|
||||
struct is_dynamic_buffer
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_dynamic_buffer<T>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
/// (Deprecated: Use the socket/descriptor wait() and async_wait() member
|
||||
/// functions.) An implementation of both the ConstBufferSequence and
|
||||
/// MutableBufferSequence concepts to represent a null buffer sequence.
|
||||
@@ -417,29 +382,45 @@ private:
|
||||
/*@{*/
|
||||
|
||||
/// Get an iterator to the first element in a buffer sequence.
|
||||
inline const mutable_buffer* buffer_sequence_begin(const mutable_buffer& b)
|
||||
template <typename MutableBuffer>
|
||||
inline const mutable_buffer* buffer_sequence_begin(const MutableBuffer& b,
|
||||
typename enable_if<
|
||||
is_convertible<const MutableBuffer*, const mutable_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return &b;
|
||||
return static_cast<const mutable_buffer*>(detail::addressof(b));
|
||||
}
|
||||
|
||||
/// Get an iterator to the first element in a buffer sequence.
|
||||
inline const const_buffer* buffer_sequence_begin(const const_buffer& b)
|
||||
template <typename ConstBuffer>
|
||||
inline const const_buffer* buffer_sequence_begin(const ConstBuffer& b,
|
||||
typename enable_if<
|
||||
is_convertible<const ConstBuffer*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return &b;
|
||||
return static_cast<const const_buffer*>(detail::addressof(b));
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_DECLTYPE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get an iterator to the first element in a buffer sequence.
|
||||
template <typename C>
|
||||
inline auto buffer_sequence_begin(C& c) -> decltype(c.begin())
|
||||
inline auto buffer_sequence_begin(C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT -> decltype(c.begin())
|
||||
{
|
||||
return c.begin();
|
||||
}
|
||||
|
||||
/// Get an iterator to the first element in a buffer sequence.
|
||||
template <typename C>
|
||||
inline auto buffer_sequence_begin(const C& c) -> decltype(c.begin())
|
||||
inline auto buffer_sequence_begin(const C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT -> decltype(c.begin())
|
||||
{
|
||||
return c.begin();
|
||||
}
|
||||
@@ -447,13 +428,21 @@ inline auto buffer_sequence_begin(const C& c) -> decltype(c.begin())
|
||||
#else // defined(ASIO_HAS_DECLTYPE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename C>
|
||||
inline typename C::iterator buffer_sequence_begin(C& c)
|
||||
inline typename C::iterator buffer_sequence_begin(C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return c.begin();
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
inline typename C::const_iterator buffer_sequence_begin(const C& c)
|
||||
inline typename C::const_iterator buffer_sequence_begin(const C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return c.begin();
|
||||
}
|
||||
@@ -470,29 +459,45 @@ inline typename C::const_iterator buffer_sequence_begin(const C& c)
|
||||
/*@{*/
|
||||
|
||||
/// Get an iterator to one past the end element in a buffer sequence.
|
||||
inline const mutable_buffer* buffer_sequence_end(const mutable_buffer& b)
|
||||
template <typename MutableBuffer>
|
||||
inline const mutable_buffer* buffer_sequence_end(const MutableBuffer& b,
|
||||
typename enable_if<
|
||||
is_convertible<const MutableBuffer*, const mutable_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return &b + 1;
|
||||
return static_cast<const mutable_buffer*>(detail::addressof(b)) + 1;
|
||||
}
|
||||
|
||||
/// Get an iterator to one past the end element in a buffer sequence.
|
||||
inline const const_buffer* buffer_sequence_end(const const_buffer& b)
|
||||
template <typename ConstBuffer>
|
||||
inline const const_buffer* buffer_sequence_end(const ConstBuffer& b,
|
||||
typename enable_if<
|
||||
is_convertible<const ConstBuffer*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return &b + 1;
|
||||
return static_cast<const const_buffer*>(detail::addressof(b)) + 1;
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_DECLTYPE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get an iterator to one past the end element in a buffer sequence.
|
||||
template <typename C>
|
||||
inline auto buffer_sequence_end(C& c) -> decltype(c.end())
|
||||
inline auto buffer_sequence_end(C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT -> decltype(c.end())
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
|
||||
/// Get an iterator to one past the end element in a buffer sequence.
|
||||
template <typename C>
|
||||
inline auto buffer_sequence_end(const C& c) -> decltype(c.end())
|
||||
inline auto buffer_sequence_end(const C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT -> decltype(c.end())
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
@@ -500,13 +505,21 @@ inline auto buffer_sequence_end(const C& c) -> decltype(c.end())
|
||||
#else // defined(ASIO_HAS_DECLTYPE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename C>
|
||||
inline typename C::iterator buffer_sequence_end(C& c)
|
||||
inline typename C::iterator buffer_sequence_end(C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
inline typename C::const_iterator buffer_sequence_end(const C& c)
|
||||
inline typename C::const_iterator buffer_sequence_end(const C& c,
|
||||
typename enable_if<
|
||||
!is_convertible<const C*, const mutable_buffer*>::value
|
||||
&& !is_convertible<const C*, const const_buffer*>::value
|
||||
>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
@@ -706,7 +719,7 @@ public:
|
||||
|
||||
void operator()()
|
||||
{
|
||||
*iter_;
|
||||
(void)*iter_;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -1403,7 +1416,7 @@ inline ASIO_MUTABLE_BUFFER buffer(
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a new non-modifiable buffer that represents the given string.
|
||||
/// Create a new modifiable buffer that represents the given string.
|
||||
/**
|
||||
* @returns A mutable_buffer value equivalent to:
|
||||
* @code mutable_buffer(
|
||||
@@ -1475,7 +1488,7 @@ inline ASIO_CONST_BUFFER buffer(
|
||||
);
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_STD_STRING_VIEW) \
|
||||
#if defined(ASIO_HAS_STRING_VIEW) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Create a new modifiable buffer that represents the given string_view.
|
||||
@@ -1520,7 +1533,7 @@ inline ASIO_CONST_BUFFER buffer(
|
||||
);
|
||||
}
|
||||
|
||||
#endif // defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
#endif // defined(ASIO_HAS_STRING_VIEW)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/*@}*/
|
||||
@@ -1533,19 +1546,23 @@ template <typename Elem, typename Traits, typename Allocator>
|
||||
class dynamic_string_buffer
|
||||
{
|
||||
public:
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
/// The type used to represent a sequence of constant buffers that refers to
|
||||
/// the underlying memory.
|
||||
typedef ASIO_CONST_BUFFER const_buffers_type;
|
||||
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
/// The type used to represent a sequence of mutable buffers that refers to
|
||||
/// the underlying memory.
|
||||
typedef ASIO_MUTABLE_BUFFER mutable_buffers_type;
|
||||
|
||||
/// Construct a dynamic buffer from a string.
|
||||
/**
|
||||
* @param s The string to be used as backing storage for the dynamic buffer.
|
||||
* Any existing data in the string is treated as the dynamic buffer's input
|
||||
* sequence. The object stores a reference to the string and the user is
|
||||
* responsible for ensuring that the string object remains valid until the
|
||||
* dynamic_string_buffer object is destroyed.
|
||||
* The object stores a reference to the string and the user is responsible
|
||||
* for ensuring that the string object remains valid while the
|
||||
* dynamic_string_buffer object, and copies of the object, are in use.
|
||||
*
|
||||
* @b DynamicBuffer_v1: Any existing data in the string is treated as the
|
||||
* dynamic buffer's input sequence.
|
||||
*
|
||||
* @param maximum_size Specifies a maximum size for the buffer, in bytes.
|
||||
*/
|
||||
@@ -1553,64 +1570,131 @@ public:
|
||||
std::size_t maximum_size =
|
||||
(std::numeric_limits<std::size_t>::max)()) ASIO_NOEXCEPT
|
||||
: string_(s),
|
||||
size_(string_.size()),
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
size_((std::numeric_limits<std::size_t>::max)()),
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
max_size_(maximum_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v2: Copy construct a dynamic buffer.
|
||||
dynamic_string_buffer(const dynamic_string_buffer& other) ASIO_NOEXCEPT
|
||||
: string_(other.string_),
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
size_(other.size_),
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
max_size_(other.max_size_)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move construct a dynamic buffer.
|
||||
dynamic_string_buffer(dynamic_string_buffer&& other) ASIO_NOEXCEPT
|
||||
: string_(other.string_),
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
size_(other.size_),
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
max_size_(other.max_size_)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get the size of the input sequence.
|
||||
/// @b DynamicBuffer_v1: Get the size of the input sequence.
|
||||
/// @b DynamicBuffer_v2: Get the current size of the underlying memory.
|
||||
/**
|
||||
* @returns @b DynamicBuffer_v1 The current size of the input sequence.
|
||||
* @b DynamicBuffer_v2: The current size of the underlying string if less than
|
||||
* max_size(). Otherwise returns max_size().
|
||||
*/
|
||||
std::size_t size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return size_;
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
if (size_ != (std::numeric_limits<std::size_t>::max)())
|
||||
return size_;
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
return (std::min)(string_.size(), max_size());
|
||||
}
|
||||
|
||||
/// Get the maximum size of the dynamic buffer.
|
||||
/**
|
||||
* @returns The allowed maximum of the sum of the sizes of the input sequence
|
||||
* and output sequence.
|
||||
* @returns The allowed maximum size of the underlying memory.
|
||||
*/
|
||||
std::size_t max_size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return max_size_;
|
||||
}
|
||||
|
||||
/// Get the current capacity of the dynamic buffer.
|
||||
/// Get the maximum size that the buffer may grow to without triggering
|
||||
/// reallocation.
|
||||
/**
|
||||
* @returns The current total capacity of the buffer, i.e. for both the input
|
||||
* sequence and output sequence.
|
||||
* @returns The current capacity of the underlying string if less than
|
||||
* max_size(). Otherwise returns max_size().
|
||||
*/
|
||||
std::size_t capacity() const ASIO_NOEXCEPT
|
||||
{
|
||||
return string_.capacity();
|
||||
return (std::min)(string_.capacity(), max_size());
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the input sequence.
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
/// @b DynamicBuffer_v1: Get a list of buffers that represents the input
|
||||
/// sequence.
|
||||
/**
|
||||
* @returns An object of type @c const_buffers_type that satisfies
|
||||
* ConstBufferSequence requirements, representing the basic_string memory in
|
||||
* input sequence.
|
||||
* the input sequence.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_string_buffer
|
||||
* or @c basic_string member function that modifies the input sequence or
|
||||
* output sequence.
|
||||
* or @c basic_string member function that resizes or erases the string.
|
||||
*/
|
||||
const_buffers_type data() const ASIO_NOEXCEPT
|
||||
{
|
||||
return const_buffers_type(asio::buffer(string_, size_));
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
|
||||
/// Get a list of buffers that represents the output sequence, with the given
|
||||
/// size.
|
||||
/// @b DynamicBuffer_v2: Get a sequence of buffers that represents the
|
||||
/// underlying memory.
|
||||
/**
|
||||
* @param pos Position of the first byte to represent in the buffer sequence
|
||||
*
|
||||
* @param n The number of bytes to return in the buffer sequence. If the
|
||||
* underlying memory is shorter, the buffer sequence represents as many bytes
|
||||
* as are available.
|
||||
*
|
||||
* @returns An object of type @c mutable_buffers_type that satisfies
|
||||
* MutableBufferSequence requirements, representing the basic_string memory.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_string_buffer
|
||||
* or @c basic_string member function that resizes or erases the string.
|
||||
*/
|
||||
mutable_buffers_type data(std::size_t pos, std::size_t n) ASIO_NOEXCEPT
|
||||
{
|
||||
return mutable_buffers_type(asio::buffer(
|
||||
asio::buffer(string_, max_size_) + pos, n));
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v2: Get a sequence of buffers that represents the
|
||||
/// underlying memory.
|
||||
/**
|
||||
* @param pos Position of the first byte to represent in the buffer sequence
|
||||
*
|
||||
* @param n The number of bytes to return in the buffer sequence. If the
|
||||
* underlying memory is shorter, the buffer sequence represents as many bytes
|
||||
* as are available.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_string_buffer
|
||||
* or @c basic_string member function that resizes or erases the string.
|
||||
*/
|
||||
const_buffers_type data(std::size_t pos,
|
||||
std::size_t n) const ASIO_NOEXCEPT
|
||||
{
|
||||
return const_buffers_type(asio::buffer(
|
||||
asio::buffer(string_, max_size_) + pos, n));
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
/// @b DynamicBuffer_v1: Get a list of buffers that represents the output
|
||||
/// sequence, with the given size.
|
||||
/**
|
||||
* Ensures that the output sequence can accommodate @c n bytes, resizing the
|
||||
* basic_string object as necessary.
|
||||
@@ -1627,18 +1711,22 @@ public:
|
||||
*/
|
||||
mutable_buffers_type prepare(std::size_t n)
|
||||
{
|
||||
if (size () > max_size() || max_size() - size() < n)
|
||||
if (size() > max_size() || max_size() - size() < n)
|
||||
{
|
||||
std::length_error ex("dynamic_string_buffer too long");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
|
||||
if (size_ == (std::numeric_limits<std::size_t>::max)())
|
||||
size_ = string_.size(); // Enable v1 behaviour.
|
||||
|
||||
string_.resize(size_ + n);
|
||||
|
||||
return asio::buffer(asio::buffer(string_) + size_, n);
|
||||
}
|
||||
|
||||
/// Move bytes from the output sequence to the input sequence.
|
||||
/// @b DynamicBuffer_v1: Move bytes from the output sequence to the input
|
||||
/// sequence.
|
||||
/**
|
||||
* @param n The number of bytes to append from the start of the output
|
||||
* sequence to the end of the input sequence. The remainder of the output
|
||||
@@ -1655,24 +1743,69 @@ public:
|
||||
size_ += (std::min)(n, string_.size() - size_);
|
||||
string_.resize(size_);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
|
||||
/// Remove characters from the input sequence.
|
||||
/// @b DynamicBuffer_v2: Grow the underlying memory by the specified number of
|
||||
/// bytes.
|
||||
/**
|
||||
* Removes @c n characters from the beginning of the input sequence.
|
||||
* Resizes the string to accommodate an additional @c n bytes at the end.
|
||||
*
|
||||
* @note If @c n is greater than the size of the input sequence, the entire
|
||||
* input sequence is consumed and no error is issued.
|
||||
* @throws std::length_error If <tt>size() + n > max_size()</tt>.
|
||||
*/
|
||||
void grow(std::size_t n)
|
||||
{
|
||||
if (size() > max_size() || max_size() - size() < n)
|
||||
{
|
||||
std::length_error ex("dynamic_string_buffer too long");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
|
||||
string_.resize(size() + n);
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v2: Shrink the underlying memory by the specified number
|
||||
/// of bytes.
|
||||
/**
|
||||
* Erases @c n bytes from the end of the string by resizing the basic_string
|
||||
* object. If @c n is greater than the current size of the string, the string
|
||||
* is emptied.
|
||||
*/
|
||||
void shrink(std::size_t n)
|
||||
{
|
||||
string_.resize(n > size() ? 0 : size() - n);
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v1: Remove characters from the input sequence.
|
||||
/// @b DynamicBuffer_v2: Consume the specified number of bytes from the
|
||||
/// beginning of the underlying memory.
|
||||
/**
|
||||
* @b DynamicBuffer_v1: Removes @c n characters from the beginning of the
|
||||
* input sequence. @note If @c n is greater than the size of the input
|
||||
* sequence, the entire input sequence is consumed and no error is issued.
|
||||
*
|
||||
* @b DynamicBuffer_v2: Erases @c n bytes from the beginning of the string.
|
||||
* If @c n is greater than the current size of the string, the string is
|
||||
* emptied.
|
||||
*/
|
||||
void consume(std::size_t n)
|
||||
{
|
||||
std::size_t consume_length = (std::min)(n, size_);
|
||||
string_.erase(0, consume_length);
|
||||
size_ -= consume_length;
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
if (size_ != (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
std::size_t consume_length = (std::min)(n, size_);
|
||||
string_.erase(0, consume_length);
|
||||
size_ -= consume_length;
|
||||
return;
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
string_.erase(0, n);
|
||||
}
|
||||
|
||||
private:
|
||||
std::basic_string<Elem, Traits, Allocator>& string_;
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
std::size_t size_;
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
const std::size_t max_size_;
|
||||
};
|
||||
|
||||
@@ -1684,19 +1817,20 @@ template <typename Elem, typename Allocator>
|
||||
class dynamic_vector_buffer
|
||||
{
|
||||
public:
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
/// The type used to represent a sequence of constant buffers that refers to
|
||||
/// the underlying memory.
|
||||
typedef ASIO_CONST_BUFFER const_buffers_type;
|
||||
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
/// The type used to represent a sequence of mutable buffers that refers to
|
||||
/// the underlying memory.
|
||||
typedef ASIO_MUTABLE_BUFFER mutable_buffers_type;
|
||||
|
||||
/// Construct a dynamic buffer from a string.
|
||||
/// Construct a dynamic buffer from a vector.
|
||||
/**
|
||||
* @param v The vector to be used as backing storage for the dynamic buffer.
|
||||
* Any existing data in the vector is treated as the dynamic buffer's input
|
||||
* sequence. The object stores a reference to the vector and the user is
|
||||
* responsible for ensuring that the vector object remains valid until the
|
||||
* dynamic_vector_buffer object is destroyed.
|
||||
* The object stores a reference to the vector and the user is responsible
|
||||
* for ensuring that the vector object remains valid while the
|
||||
* dynamic_vector_buffer object, and copies of the object, are in use.
|
||||
*
|
||||
* @param maximum_size Specifies a maximum size for the buffer, in bytes.
|
||||
*/
|
||||
@@ -1704,77 +1838,149 @@ public:
|
||||
std::size_t maximum_size =
|
||||
(std::numeric_limits<std::size_t>::max)()) ASIO_NOEXCEPT
|
||||
: vector_(v),
|
||||
size_(vector_.size()),
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
size_((std::numeric_limits<std::size_t>::max)()),
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
max_size_(maximum_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v2: Copy construct a dynamic buffer.
|
||||
dynamic_vector_buffer(const dynamic_vector_buffer& other) ASIO_NOEXCEPT
|
||||
: vector_(other.vector_),
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
size_(other.size_),
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
max_size_(other.max_size_)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move construct a dynamic buffer.
|
||||
dynamic_vector_buffer(dynamic_vector_buffer&& other) ASIO_NOEXCEPT
|
||||
: vector_(other.vector_),
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
size_(other.size_),
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
max_size_(other.max_size_)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get the size of the input sequence.
|
||||
/// @b DynamicBuffer_v1: Get the size of the input sequence.
|
||||
/// @b DynamicBuffer_v2: Get the current size of the underlying memory.
|
||||
/**
|
||||
* @returns @b DynamicBuffer_v1 The current size of the input sequence.
|
||||
* @b DynamicBuffer_v2: The current size of the underlying vector if less than
|
||||
* max_size(). Otherwise returns max_size().
|
||||
*/
|
||||
std::size_t size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return size_;
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
if (size_ != (std::numeric_limits<std::size_t>::max)())
|
||||
return size_;
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
return (std::min)(vector_.size(), max_size());
|
||||
}
|
||||
|
||||
/// Get the maximum size of the dynamic buffer.
|
||||
/**
|
||||
* @returns The allowed maximum of the sum of the sizes of the input sequence
|
||||
* and output sequence.
|
||||
* @returns @b DynamicBuffer_v1: The allowed maximum of the sum of the sizes
|
||||
* of the input sequence and output sequence. @b DynamicBuffer_v2: The allowed
|
||||
* maximum size of the underlying memory.
|
||||
*/
|
||||
std::size_t max_size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return max_size_;
|
||||
}
|
||||
|
||||
/// Get the current capacity of the dynamic buffer.
|
||||
/// Get the maximum size that the buffer may grow to without triggering
|
||||
/// reallocation.
|
||||
/**
|
||||
* @returns The current total capacity of the buffer, i.e. for both the input
|
||||
* sequence and output sequence.
|
||||
* @returns @b DynamicBuffer_v1: The current total capacity of the buffer,
|
||||
* i.e. for both the input sequence and output sequence. @b DynamicBuffer_v2:
|
||||
* The current capacity of the underlying vector if less than max_size().
|
||||
* Otherwise returns max_size().
|
||||
*/
|
||||
std::size_t capacity() const ASIO_NOEXCEPT
|
||||
{
|
||||
return vector_.capacity();
|
||||
return (std::min)(vector_.capacity(), max_size());
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the input sequence.
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
/// @b DynamicBuffer_v1: Get a list of buffers that represents the input
|
||||
/// sequence.
|
||||
/**
|
||||
* @returns An object of type @c const_buffers_type that satisfies
|
||||
* ConstBufferSequence requirements, representing the basic_string memory in
|
||||
* ConstBufferSequence requirements, representing the vector memory in the
|
||||
* input sequence.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_vector_buffer
|
||||
* or @c basic_string member function that modifies the input sequence or
|
||||
* output sequence.
|
||||
* or @c vector member function that modifies the input sequence or output
|
||||
* sequence.
|
||||
*/
|
||||
const_buffers_type data() const ASIO_NOEXCEPT
|
||||
{
|
||||
return const_buffers_type(asio::buffer(vector_, size_));
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
|
||||
/// Get a list of buffers that represents the output sequence, with the given
|
||||
/// size.
|
||||
/// @b DynamicBuffer_v2: Get a sequence of buffers that represents the
|
||||
/// underlying memory.
|
||||
/**
|
||||
* Ensures that the output sequence can accommodate @c n bytes, resizing the
|
||||
* basic_string object as necessary.
|
||||
* @param pos Position of the first byte to represent in the buffer sequence
|
||||
*
|
||||
* @param n The number of bytes to return in the buffer sequence. If the
|
||||
* underlying memory is shorter, the buffer sequence represents as many bytes
|
||||
* as are available.
|
||||
*
|
||||
* @returns An object of type @c mutable_buffers_type that satisfies
|
||||
* MutableBufferSequence requirements, representing basic_string memory
|
||||
* at the start of the output sequence of size @c n.
|
||||
* MutableBufferSequence requirements, representing the vector memory.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_vector_buffer
|
||||
* or @c vector member function that resizes or erases the vector.
|
||||
*/
|
||||
mutable_buffers_type data(std::size_t pos, std::size_t n) ASIO_NOEXCEPT
|
||||
{
|
||||
return mutable_buffers_type(asio::buffer(
|
||||
asio::buffer(vector_, max_size_) + pos, n));
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v2: Get a sequence of buffers that represents the
|
||||
/// underlying memory.
|
||||
/**
|
||||
* @param pos Position of the first byte to represent in the buffer sequence
|
||||
*
|
||||
* @param n The number of bytes to return in the buffer sequence. If the
|
||||
* underlying memory is shorter, the buffer sequence represents as many bytes
|
||||
* as are available.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_vector_buffer
|
||||
* or @c vector member function that resizes or erases the vector.
|
||||
*/
|
||||
const_buffers_type data(std::size_t pos,
|
||||
std::size_t n) const ASIO_NOEXCEPT
|
||||
{
|
||||
return const_buffers_type(asio::buffer(
|
||||
asio::buffer(vector_, max_size_) + pos, n));
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
/// @b DynamicBuffer_v1: Get a list of buffers that represents the output
|
||||
/// sequence, with the given size.
|
||||
/**
|
||||
* Ensures that the output sequence can accommodate @c n bytes, resizing the
|
||||
* vector object as necessary.
|
||||
*
|
||||
* @returns An object of type @c mutable_buffers_type that satisfies
|
||||
* MutableBufferSequence requirements, representing vector memory at the
|
||||
* start of the output sequence of size @c n.
|
||||
*
|
||||
* @throws std::length_error If <tt>size() + n > max_size()</tt>.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c dynamic_vector_buffer
|
||||
* or @c basic_string member function that modifies the input sequence or
|
||||
* output sequence.
|
||||
* or @c vector member function that modifies the input sequence or output
|
||||
* sequence.
|
||||
*/
|
||||
mutable_buffers_type prepare(std::size_t n)
|
||||
{
|
||||
@@ -1784,12 +1990,16 @@ public:
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
|
||||
if (size_ == (std::numeric_limits<std::size_t>::max)())
|
||||
size_ = vector_.size(); // Enable v1 behaviour.
|
||||
|
||||
vector_.resize(size_ + n);
|
||||
|
||||
return asio::buffer(asio::buffer(vector_) + size_, n);
|
||||
}
|
||||
|
||||
/// Move bytes from the output sequence to the input sequence.
|
||||
/// @b DynamicBuffer_v1: Move bytes from the output sequence to the input
|
||||
/// sequence.
|
||||
/**
|
||||
* @param n The number of bytes to append from the start of the output
|
||||
* sequence to the end of the input sequence. The remainder of the output
|
||||
@@ -1806,24 +2016,69 @@ public:
|
||||
size_ += (std::min)(n, vector_.size() - size_);
|
||||
vector_.resize(size_);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
|
||||
/// Remove characters from the input sequence.
|
||||
/// @b DynamicBuffer_v2: Grow the underlying memory by the specified number of
|
||||
/// bytes.
|
||||
/**
|
||||
* Removes @c n characters from the beginning of the input sequence.
|
||||
* Resizes the vector to accommodate an additional @c n bytes at the end.
|
||||
*
|
||||
* @note If @c n is greater than the size of the input sequence, the entire
|
||||
* input sequence is consumed and no error is issued.
|
||||
* @throws std::length_error If <tt>size() + n > max_size()</tt>.
|
||||
*/
|
||||
void grow(std::size_t n)
|
||||
{
|
||||
if (size() > max_size() || max_size() - size() < n)
|
||||
{
|
||||
std::length_error ex("dynamic_vector_buffer too long");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
|
||||
vector_.resize(size() + n);
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v2: Shrink the underlying memory by the specified number
|
||||
/// of bytes.
|
||||
/**
|
||||
* Erases @c n bytes from the end of the vector by resizing the vector
|
||||
* object. If @c n is greater than the current size of the vector, the vector
|
||||
* is emptied.
|
||||
*/
|
||||
void shrink(std::size_t n)
|
||||
{
|
||||
vector_.resize(n > size() ? 0 : size() - n);
|
||||
}
|
||||
|
||||
/// @b DynamicBuffer_v1: Remove characters from the input sequence.
|
||||
/// @b DynamicBuffer_v2: Consume the specified number of bytes from the
|
||||
/// beginning of the underlying memory.
|
||||
/**
|
||||
* @b DynamicBuffer_v1: Removes @c n characters from the beginning of the
|
||||
* input sequence. @note If @c n is greater than the size of the input
|
||||
* sequence, the entire input sequence is consumed and no error is issued.
|
||||
*
|
||||
* @b DynamicBuffer_v2: Erases @c n bytes from the beginning of the vector.
|
||||
* If @c n is greater than the current size of the vector, the vector is
|
||||
* emptied.
|
||||
*/
|
||||
void consume(std::size_t n)
|
||||
{
|
||||
std::size_t consume_length = (std::min)(n, size_);
|
||||
vector_.erase(vector_.begin(), vector_.begin() + consume_length);
|
||||
size_ -= consume_length;
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
if (size_ != (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
std::size_t consume_length = (std::min)(n, size_);
|
||||
vector_.erase(vector_.begin(), vector_.begin() + consume_length);
|
||||
size_ -= consume_length;
|
||||
return;
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
vector_.erase(vector_.begin(), vector_.begin() + (std::min)(size(), n));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Elem, Allocator>& vector_;
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
std::size_t size_;
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
const std::size_t max_size_;
|
||||
};
|
||||
|
||||
@@ -2157,6 +2412,83 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
#include "asio/detail/is_buffer_sequence.hpp"
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Trait to determine whether a type satisfies the MutableBufferSequence
|
||||
/// requirements.
|
||||
template <typename T>
|
||||
struct is_mutable_buffer_sequence
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_buffer_sequence<T, mutable_buffer>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
/// Trait to determine whether a type satisfies the ConstBufferSequence
|
||||
/// requirements.
|
||||
template <typename T>
|
||||
struct is_const_buffer_sequence
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_buffer_sequence<T, const_buffer>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
/// Trait to determine whether a type satisfies the DynamicBuffer_v1
|
||||
/// requirements.
|
||||
template <typename T>
|
||||
struct is_dynamic_buffer_v1
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_dynamic_buffer_v1<T>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
|
||||
/// Trait to determine whether a type satisfies the DynamicBuffer_v2
|
||||
/// requirements.
|
||||
template <typename T>
|
||||
struct is_dynamic_buffer_v2
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
: asio::detail::is_dynamic_buffer_v2<T>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
/// Trait to determine whether a type satisfies the DynamicBuffer requirements.
|
||||
/**
|
||||
* If @c ASIO_NO_DYNAMIC_BUFFER_V1 is not defined, determines whether the
|
||||
* type satisfies the DynamicBuffer_v1 requirements. Otherwise, if @c
|
||||
* ASIO_NO_DYNAMIC_BUFFER_V1 is defined, determines whether the type
|
||||
* satisfies the DynamicBuffer_v1 requirements.
|
||||
*/
|
||||
template <typename T>
|
||||
struct is_dynamic_buffer
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: integral_constant<bool, automatically_determined>
|
||||
#elif defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
: asio::is_dynamic_buffer_v2<T>
|
||||
#else // defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
: asio::is_dynamic_buffer_v1<T>
|
||||
#endif // defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BUFFER_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffered_read_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
@@ -105,22 +104,6 @@ public:
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return next_layer_.get_io_context();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return next_layer_.get_io_service();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffered_read_stream_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffered_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "asio/buffered_stream_fwd.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
@@ -96,22 +95,6 @@ public:
|
||||
return stream_impl_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return stream_impl_.get_io_context();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return stream_impl_.get_io_service();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffered_stream_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffered_write_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/write.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
@@ -105,22 +104,6 @@ public:
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return next_layer_.get_io_context();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_executor().) Get the io_context associated with the
|
||||
/// object.
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return next_layer_.get_io_service();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffered_write_stream_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// buffers_iterator.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
88
Sources/ASIO/asio/include/asio/co_spawn.hpp
Normal file
88
Sources/ASIO/asio/include/asio/co_spawn.hpp
Normal file
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// co_spawn.hpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_CO_SPAWN_HPP
|
||||
#define ASIO_CO_SPAWN_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include "asio/awaitable.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/is_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
struct awaitable_signature;
|
||||
|
||||
template <typename T, typename Executor>
|
||||
struct awaitable_signature<awaitable<T, Executor>>
|
||||
{
|
||||
typedef void type(std::exception_ptr, T);
|
||||
};
|
||||
|
||||
template <typename Executor>
|
||||
struct awaitable_signature<awaitable<void, Executor>>
|
||||
{
|
||||
typedef void type(std::exception_ptr);
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Spawn a new thread of execution.
|
||||
/**
|
||||
* The entry point function object @c f must have the signature:
|
||||
*
|
||||
* @code awaitable<void, E> f(); @endcode
|
||||
*
|
||||
* where @c E is convertible from @c Executor.
|
||||
*/
|
||||
template <typename Executor, typename F, typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
typename detail::awaitable_signature<typename result_of<F()>::type>::type)
|
||||
co_spawn(const Executor& ex, F&& f, CompletionToken&& token,
|
||||
typename enable_if<
|
||||
is_executor<Executor>::value
|
||||
>::type* = 0);
|
||||
|
||||
/// Spawn a new thread of execution.
|
||||
/**
|
||||
* The entry point function object @c f must have the signature:
|
||||
*
|
||||
* @code awaitable<void, E> f(); @endcode
|
||||
*
|
||||
* where @c E is convertible from @c ExecutionContext::executor_type.
|
||||
*/
|
||||
template <typename ExecutionContext, typename F, typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
typename detail::awaitable_signature<typename result_of<F()>::type>::type)
|
||||
co_spawn(ExecutionContext& ctx, F&& f, CompletionToken&& token,
|
||||
typename enable_if<
|
||||
is_convertible<ExecutionContext&, execution_context&>::value
|
||||
>::type* = 0);
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/co_spawn.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_CO_SPAWN_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// completion_condition.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
136
Sources/ASIO/asio/include/asio/compose.hpp
Normal file
136
Sources/ASIO/asio/include/asio/compose.hpp
Normal file
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// compose.hpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_COMPOSE_HPP
|
||||
#define ASIO_COMPOSE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Launch an asynchronous operation with a stateful implementation.
|
||||
/**
|
||||
* The async_compose function simplifies the implementation of composed
|
||||
* asynchronous operations automatically wrapping a stateful function object
|
||||
* with a conforming intermediate completion handler.
|
||||
*
|
||||
* @param implementation A function object that contains the implementation of
|
||||
* the composed asynchronous operation. The first argument to the function
|
||||
* object is a non-const reference to the enclosing intermediate completion
|
||||
* handler. The remaining arguments are any arguments that originate from the
|
||||
* completion handlers of any asynchronous operations performed by the
|
||||
* implementation.
|
||||
|
||||
* @param token The completion token.
|
||||
*
|
||||
* @param io_objects_or_executors Zero or more I/O objects or I/O executors for
|
||||
* which outstanding work must be maintained.
|
||||
*
|
||||
* @par Example:
|
||||
*
|
||||
* @code struct async_echo_implementation
|
||||
* {
|
||||
* tcp::socket& socket_;
|
||||
* asio::mutable_buffer buffer_;
|
||||
* enum { starting, reading, writing } state_;
|
||||
*
|
||||
* template <typename Self>
|
||||
* void operator()(Self& self,
|
||||
* asio::error_code error = {},
|
||||
* std::size_t n = 0)
|
||||
* {
|
||||
* switch (state_)
|
||||
* {
|
||||
* case starting:
|
||||
* state_ = reading;
|
||||
* socket_.async_read_some(
|
||||
* buffer_, std::move(self));
|
||||
* break;
|
||||
* case reading:
|
||||
* if (error)
|
||||
* {
|
||||
* self.complete(error, 0);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* state_ = writing;
|
||||
* asio::async_write(socket_, buffer_,
|
||||
* asio::transfer_exactly(n),
|
||||
* std::move(self));
|
||||
* }
|
||||
* break;
|
||||
* case writing:
|
||||
* self.complete(error, n);
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* template <typename CompletionToken>
|
||||
* auto async_echo(tcp::socket& socket,
|
||||
* asio::mutable_buffer buffer,
|
||||
* CompletionToken&& token) ->
|
||||
* typename asio::async_result<
|
||||
* typename std::decay<CompletionToken>::type,
|
||||
* void(asio::error_code, std::size_t)>::return_type
|
||||
* {
|
||||
* return asio::async_compose<CompletionToken,
|
||||
* void(asio::error_code, std::size_t)>(
|
||||
* async_echo_implementation{socket, buffer,
|
||||
* async_echo_implementation::starting},
|
||||
* token, socket);
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename CompletionToken, typename Signature,
|
||||
typename Implementation, typename... IoObjectsOrExecutors>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
|
||||
async_compose(ASIO_MOVE_ARG(Implementation) implementation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
|
||||
ASIO_MOVE_ARG(IoObjectsOrExecutors)... io_objects_or_executors);
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename CompletionToken, typename Signature, typename Implementation>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
|
||||
async_compose(ASIO_MOVE_ARG(Implementation) implementation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token);
|
||||
|
||||
#define ASIO_PRIVATE_ASYNC_COMPOSE_DEF(n) \
|
||||
template <typename CompletionToken, typename Signature, \
|
||||
typename Implementation, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature) \
|
||||
async_compose(ASIO_MOVE_ARG(Implementation) implementation, \
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n));
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_ASYNC_COMPOSE_DEF)
|
||||
#undef ASIO_PRIVATE_ASYNC_COMPOSE_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/compose.hpp"
|
||||
|
||||
#endif // ASIO_COMPOSE_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// connect.hpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -58,7 +58,8 @@ struct is_endpoint_sequence
|
||||
/**
|
||||
* @defgroup connect asio::connect
|
||||
*
|
||||
* @brief Establishes a socket connection by trying each endpoint in a sequence.
|
||||
* @brief The @c connect function is a composed operation that establishes a
|
||||
* socket connection by trying each endpoint in a sequence.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
@@ -81,14 +82,13 @@ struct is_endpoint_sequence
|
||||
* Otherwise, contains the error from the last connection attempt.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::connect(s, r.resolve(q)); @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename EndpointSequence>
|
||||
typename Protocol::endpoint connect(
|
||||
basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence>
|
||||
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
@@ -113,9 +113,9 @@ typename Protocol::endpoint connect(
|
||||
* default-constructed endpoint.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::error_code ec;
|
||||
* asio::connect(s, r.resolve(q), ec);
|
||||
* if (ec)
|
||||
@@ -123,16 +123,15 @@ typename Protocol::endpoint connect(
|
||||
* // An error occurred.
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename EndpointSequence>
|
||||
typename Protocol::endpoint connect(
|
||||
basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence>
|
||||
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints, asio::error_code& ec,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/// (Deprecated: Use range overload.) Establishes a socket connection by trying
|
||||
/// each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
@@ -155,12 +154,12 @@ typename Protocol::endpoint connect(
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
template <typename Protocol, typename Executor, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
|
||||
|
||||
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/// (Deprecated: Use range overload.) Establishes a socket connection by trying
|
||||
/// each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
@@ -183,8 +182,8 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
template <typename Protocol, typename Executor, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s,
|
||||
Iterator begin, asio::error_code& ec,
|
||||
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
@@ -210,14 +209,14 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* Otherwise, contains the error from the last connection attempt.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::results_type e = r.resolve(q);
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::connect(s, e.begin(), e.end()); @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
template <typename Protocol, typename Executor, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s,
|
||||
Iterator begin, Iterator end);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
@@ -242,10 +241,10 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::results_type e = r.resolve(q);
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::error_code ec;
|
||||
* asio::connect(s, e.begin(), e.end(), ec);
|
||||
* if (ec)
|
||||
@@ -253,8 +252,8 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* // An error occurred.
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
template <typename Protocol, typename Executor, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s,
|
||||
Iterator begin, Iterator end, asio::error_code& ec);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
@@ -301,17 +300,16 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* tcp::endpoint e = asio::connect(s,
|
||||
* r.resolve(q), my_connect_condition());
|
||||
* std::cout << "Connected to: " << e << std::endl; @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename EndpointSequence, typename ConnectCondition>
|
||||
typename Protocol::endpoint connect(
|
||||
basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints, ConnectCondition connect_condition,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
@@ -361,9 +359,9 @@ typename Protocol::endpoint connect(
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::error_code ec;
|
||||
* tcp::endpoint e = asio::connect(s,
|
||||
* r.resolve(q), my_connect_condition(), ec);
|
||||
@@ -376,18 +374,17 @@ typename Protocol::endpoint connect(
|
||||
* std::cout << "Connected to: " << e << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename EndpointSequence, typename ConnectCondition>
|
||||
typename Protocol::endpoint connect(
|
||||
basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints, ConnectCondition connect_condition,
|
||||
asio::error_code& ec,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/// (Deprecated: Use range overload.) Establishes a socket connection by trying
|
||||
/// each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
@@ -421,14 +418,14 @@ typename Protocol::endpoint connect(
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s,
|
||||
Iterator begin, ConnectCondition connect_condition,
|
||||
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
|
||||
|
||||
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/// (Deprecated: Use range overload.) Establishes a socket connection by trying
|
||||
/// each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
@@ -462,9 +459,9 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
ConnectCondition connect_condition, asio::error_code& ec,
|
||||
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
@@ -515,17 +512,17 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::results_type e = r.resolve(q);
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* tcp::resolver::results_type::iterator i = asio::connect(
|
||||
* s, e.begin(), e.end(), my_connect_condition());
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
Iterator end, ConnectCondition connect_condition);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
@@ -575,10 +572,10 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::results_type e = r.resolve(q);
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::error_code ec;
|
||||
* tcp::resolver::results_type::iterator i = asio::connect(
|
||||
* s, e.begin(), e.end(), my_connect_condition());
|
||||
@@ -591,9 +588,9 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s,
|
||||
Iterator begin, Iterator end, ConnectCondition connect_condition,
|
||||
asio::error_code& ec);
|
||||
|
||||
@@ -602,8 +599,8 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
/**
|
||||
* @defgroup async_connect asio::async_connect
|
||||
*
|
||||
* @brief Asynchronously establishes a socket connection by trying each
|
||||
* endpoint in a sequence.
|
||||
* @brief The @c async_connect function is a composed asynchronous operation
|
||||
* that establishes a socket connection by trying each endpoint in a sequence.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
@@ -634,14 +631,14 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* const typename Protocol::endpoint& endpoint
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
@@ -668,19 +665,19 @@ Iterator connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* // ...
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename EndpointSequence, typename RangeConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(RangeConnectHandler,
|
||||
void (asio::error_code, typename Protocol::endpoint))
|
||||
async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
async_connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints,
|
||||
ASIO_MOVE_ARG(RangeConnectHandler) handler,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Asynchronously establishes a socket connection by trying each
|
||||
/// endpoint in a sequence.
|
||||
/// (Deprecated: Use range overload.) Asynchronously establishes a socket
|
||||
/// connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c async_connect
|
||||
@@ -706,20 +703,20 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename IteratorConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
Iterator begin, ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
@@ -752,13 +749,13 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* @code std::vector<tcp::endpoint> endpoints = ...;
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
* asio::async_connect(s,
|
||||
* endpoints.begin(), endpoints.end(),
|
||||
* connect_handler);
|
||||
@@ -772,12 +769,11 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* // ...
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM,
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename IteratorConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
Iterator begin, Iterator end,
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin, Iterator end,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler);
|
||||
|
||||
/// Asynchronously establishes a socket connection by trying each endpoint in a
|
||||
@@ -818,9 +814,9 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
@@ -837,9 +833,9 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
@@ -875,19 +871,19 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* }
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename EndpointSequence,
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence,
|
||||
typename ConnectCondition, typename RangeConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(RangeConnectHandler,
|
||||
void (asio::error_code, typename Protocol::endpoint))
|
||||
async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
async_connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints, ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(RangeConnectHandler) handler,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Asynchronously establishes a socket connection by trying each
|
||||
/// endpoint in a sequence.
|
||||
/// (Deprecated: Use range overload.) Asynchronously establishes a socket
|
||||
/// connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c async_connect
|
||||
@@ -924,19 +920,19 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename Iterator,
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
|
||||
@@ -982,9 +978,9 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_context::post().
|
||||
* not, the handler will not be invoked from within this function. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
@@ -1001,9 +997,9 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_context);
|
||||
* @code tcp::resolver r(my_context);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_context);
|
||||
* tcp::socket s(my_context);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
@@ -1040,12 +1036,12 @@ async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s, Iterator begin,
|
||||
* }
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol ASIO_SVC_TPARAM, typename Iterator,
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol ASIO_SVC_TARG>& s,
|
||||
Iterator begin, Iterator end, ConnectCondition connect_condition,
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
Iterator end, ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler);
|
||||
|
||||
/*@}*/
|
||||
@@ -2,7 +2,7 @@
|
||||
// coroutine.hpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -205,7 +205,7 @@ class coroutine_ref;
|
||||
* {
|
||||
* do
|
||||
* {
|
||||
* socket_.reset(new tcp::socket(io_context_));
|
||||
* socket_.reset(new tcp::socket(my_context_));
|
||||
* yield acceptor->async_accept(*socket_, *this);
|
||||
* fork server(*this)();
|
||||
* } while (is_parent());
|
||||
@@ -227,7 +227,7 @@ class coroutine_ref;
|
||||
* Note that @c fork doesn't do the actual forking by itself. It is the
|
||||
* application's responsibility to create a clone of the coroutine and call it.
|
||||
* The clone can be called immediately, as above, or scheduled for delayed
|
||||
* execution using something like io_context::post().
|
||||
* execution using something like asio::post().
|
||||
*
|
||||
* @par Alternate macro names
|
||||
*
|
||||
@@ -2,7 +2,7 @@
|
||||
// deadline_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// defer.hpp
|
||||
// ~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -31,6 +31,11 @@ namespace asio {
|
||||
* executor. The function object is queued for execution, and is never called
|
||||
* from the current thread prior to returning from <tt>defer()</tt>.
|
||||
*
|
||||
* The use of @c defer(), rather than @ref post(), indicates the caller's
|
||||
* preference that the executor defer the queueing of the function object. This
|
||||
* may allow the executor to optimise queueing for cases when the function
|
||||
* object represents a continuation of the current call context.
|
||||
*
|
||||
* This function has the following effects:
|
||||
*
|
||||
* @li Constructs a function object handler of type @c Handler, initialized
|
||||
@@ -59,6 +64,11 @@ ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
* The function object is queued for execution, and is never called from the
|
||||
* current thread prior to returning from <tt>defer()</tt>.
|
||||
*
|
||||
* The use of @c defer(), rather than @ref post(), indicates the caller's
|
||||
* preference that the executor defer the queueing of the function object. This
|
||||
* may allow the executor to optimise queueing for cases when the function
|
||||
* object represents a continuation of the current call context.
|
||||
*
|
||||
* This function has the following effects:
|
||||
*
|
||||
* @li Constructs a function object handler of type @c Handler, initialized
|
||||
62
Sources/ASIO/asio/include/asio/detached.hpp
Normal file
62
Sources/ASIO/asio/include/asio/detached.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// detached.hpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETACHED_HPP
|
||||
#define ASIO_DETACHED_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <memory>
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Class used to specify that an asynchronous operation is detached.
|
||||
/**
|
||||
|
||||
* The detached_t class is used to indicate that an asynchronous operation is
|
||||
* detached. That is, there is no completion handler waiting for the
|
||||
* operation's result. A detached_t object may be passed as a handler to an
|
||||
* asynchronous operation, typically using the special value
|
||||
* @c asio::detached. For example:
|
||||
|
||||
* @code my_socket.async_send(my_buffer, asio::detached);
|
||||
* @endcode
|
||||
*/
|
||||
class detached_t
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
ASIO_CONSTEXPR detached_t()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// A special value, similar to std::nothrow.
|
||||
/**
|
||||
* See the documentation for asio::detached_t for a usage example.
|
||||
*/
|
||||
#if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
|
||||
constexpr detached_t detached;
|
||||
#elif defined(ASIO_MSVC)
|
||||
__declspec(selectany) detached_t detached;
|
||||
#endif
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/detached.hpp"
|
||||
|
||||
#endif // ASIO_DETACHED_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/array.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/array_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/assert.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/atomic_count.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/base_from_completion_cond.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -27,8 +27,9 @@ template <typename CompletionCondition>
|
||||
class base_from_completion_cond
|
||||
{
|
||||
protected:
|
||||
explicit base_from_completion_cond(CompletionCondition completion_condition)
|
||||
: completion_condition_(completion_condition)
|
||||
explicit base_from_completion_cond(CompletionCondition& completion_condition)
|
||||
: completion_condition_(
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/bind_handler.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/buffer_resize_guard.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/buffer_sequence_adapter.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/buffered_stream_storage.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/call_stack.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/chrono.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/chrono_time_traits.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/completion_handler.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/concurrency_hint.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/conditionally_enabled_event.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/conditionally_enabled_mutex.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -2,7 +2,7 @@
|
||||
// detail/config.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -11,6 +11,20 @@
|
||||
#ifndef ASIO_DETAIL_CONFIG_HPP
|
||||
#define ASIO_DETAIL_CONFIG_HPP
|
||||
|
||||
// boostify: non-boost code starts here
|
||||
#if !defined(ASIO_STANDALONE)
|
||||
# if !defined(ASIO_ENABLE_BOOST)
|
||||
# if (__cplusplus >= 201103)
|
||||
# define ASIO_STANDALONE 1
|
||||
# elif defined(_MSC_VER) && defined(_MSVC_LANG)
|
||||
# if (_MSC_VER >= 1900) && (_MSVC_LANG >= 201103)
|
||||
# define ASIO_STANDALONE 1
|
||||
# endif // (_MSC_VER >= 1900) && (_MSVC_LANG >= 201103)
|
||||
# endif // defined(_MSC_VER) && defined(_MSVC_LANG)
|
||||
# endif // !defined(ASIO_ENABLE_BOOST)
|
||||
#endif // !defined(ASIO_STANDALONE)
|
||||
|
||||
// boostify: non-boost code ends here
|
||||
#if defined(ASIO_STANDALONE)
|
||||
# define ASIO_DISABLE_BOOST_ARRAY 1
|
||||
# define ASIO_DISABLE_BOOST_ASSERT 1
|
||||
@@ -69,7 +83,7 @@
|
||||
|| (!defined(__MWERKS__) && !defined(__EDG_VERSION__)))
|
||||
# define ASIO_MSVC _MSC_VER
|
||||
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC)
|
||||
#endif // defined(ASIO_MSVC)
|
||||
#endif // !defined(ASIO_MSVC)
|
||||
|
||||
// Clang / libc++ detection.
|
||||
#if defined(__clang__)
|
||||
@@ -108,15 +122,26 @@
|
||||
# define ASIO_HAS_MOVE 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# if defined(__INTEL_CXX11_MODE__)
|
||||
# if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1500)
|
||||
# define BOOST_ASIO_HAS_MOVE 1
|
||||
# endif // defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1500)
|
||||
# if defined(__ICL) && (__ICL >= 1500)
|
||||
# define BOOST_ASIO_HAS_MOVE 1
|
||||
# endif // defined(__ICL) && (__ICL >= 1500)
|
||||
# endif // defined(__INTEL_CXX11_MODE__)
|
||||
# endif // !defined(ASIO_DISABLE_MOVE)
|
||||
#endif // !defined(ASIO_HAS_MOVE)
|
||||
|
||||
// If ASIO_MOVE_CAST isn't defined, and move support is available, define
|
||||
// ASIO_MOVE_ARG and ASIO_MOVE_CAST to take advantage of rvalue
|
||||
// references and perfect forwarding.
|
||||
// * ASIO_MOVE_ARG,
|
||||
// * ASIO_NONDEDUCED_MOVE_ARG, and
|
||||
// * ASIO_MOVE_CAST
|
||||
// to take advantage of rvalue references and perfect forwarding.
|
||||
#if defined(ASIO_HAS_MOVE) && !defined(ASIO_MOVE_CAST)
|
||||
# define ASIO_MOVE_ARG(type) type&&
|
||||
# define ASIO_MOVE_ARG2(type1, type2) type1, type2&&
|
||||
# define ASIO_NONDEDUCED_MOVE_ARG(type) type&
|
||||
# define ASIO_MOVE_CAST(type) static_cast<type&&>
|
||||
# define ASIO_MOVE_CAST2(type1, type2) static_cast<type1, type2&&>
|
||||
#endif // defined(ASIO_HAS_MOVE) && !defined(ASIO_MOVE_CAST)
|
||||
@@ -142,6 +167,7 @@
|
||||
# else
|
||||
# define ASIO_MOVE_ARG(type) type
|
||||
# endif
|
||||
# define ASIO_NONDEDUCED_MOVE_ARG(type) const type&
|
||||
# define ASIO_MOVE_CAST(type) static_cast<const type&>
|
||||
# define ASIO_MOVE_CAST2(type1, type2) static_cast<const type1, type2&>
|
||||
#endif // !defined(ASIO_MOVE_CAST)
|
||||
@@ -226,7 +252,7 @@
|
||||
// Support noexcept on compilers known to allow it.
|
||||
#if !defined(ASIO_NOEXCEPT)
|
||||
# if !defined(ASIO_DISABLE_NOEXCEPT)
|
||||
# if (BOOST_VERSION >= 105300)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 105300)
|
||||
# define ASIO_NOEXCEPT BOOST_NOEXCEPT
|
||||
# define ASIO_NOEXCEPT_OR_NOTHROW BOOST_NOEXCEPT_OR_NOTHROW
|
||||
# elif defined(__clang__)
|
||||
@@ -272,9 +298,9 @@
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# if (_MSC_VER >= 1800)
|
||||
# define ASIO_HAS_DECLTYPE 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // (_MSC_VER >= 1800)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_DECLTYPE)
|
||||
#endif // !defined(ASIO_HAS_DECLTYPE)
|
||||
@@ -440,7 +466,13 @@
|
||||
# if __has_include(<atomic>)
|
||||
# define ASIO_HAS_STD_ATOMIC 1
|
||||
# endif // __has_include(<atomic>)
|
||||
# endif // (__cplusplus >= 201103)
|
||||
# elif defined(__apple_build_version__) && defined(_LIBCPP_VERSION)
|
||||
# if (__clang_major__ >= 10)
|
||||
# if __has_include(<atomic>)
|
||||
# define ASIO_HAS_STD_ATOMIC 1
|
||||
# endif // __has_include(<atomic>)
|
||||
# endif // (__clang_major__ >= 10)
|
||||
# endif /// defined(__apple_build_version__) && defined(_LIBCPP_VERSION)
|
||||
# endif // defined(__clang__)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
@@ -770,32 +802,77 @@
|
||||
# endif // !defined(ASIO_DISABLE_STD_FUTURE)
|
||||
#endif // !defined(ASIO_HAS_STD_FUTURE)
|
||||
|
||||
// Standard library support for experimental::string_view.
|
||||
// Standard library support for std::string_view.
|
||||
#if !defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
# if !defined(ASIO_DISABLE_STD_STRING_VIEW)
|
||||
# if defined(__clang__)
|
||||
# if (__cplusplus >= 201402)
|
||||
# if __has_include(<experimental/string_view>)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if (__cplusplus >= 201402)
|
||||
# if __has_include(<string_view>)
|
||||
# define ASIO_HAS_STD_STRING_VIEW 1
|
||||
# endif // __has_include(<string_view>)
|
||||
# endif // (__cplusplus >= 201402)
|
||||
# else // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if (__cplusplus >= 201703)
|
||||
# if __has_include(<string_view>)
|
||||
# define ASIO_HAS_STD_STRING_VIEW 1
|
||||
# endif // __has_include(<string_view>)
|
||||
# endif // (__cplusplus >= 201703)
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# elif defined(__GNUC__)
|
||||
# if (__GNUC__ >= 7)
|
||||
# if (__cplusplus >= 201703)
|
||||
# define ASIO_HAS_STD_STRING_VIEW 1
|
||||
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
|
||||
# endif // __has_include(<experimental/string_view>)
|
||||
# endif // (__cplusplus >= 201402)
|
||||
# endif // (__cplusplus >= 201703)
|
||||
# endif // (__GNUC__ >= 7)
|
||||
# elif defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1910 && _MSVC_LANG >= 201703)
|
||||
# define ASIO_HAS_STD_STRING_VIEW 1
|
||||
# endif // (_MSC_VER >= 1910 && _MSVC_LANG >= 201703)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_STRING_VIEW)
|
||||
#endif // !defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
|
||||
// Standard library support for std::experimental::string_view.
|
||||
#if !defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
# if !defined(ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
# if defined(__clang__)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if (_LIBCPP_VERSION < 7000)
|
||||
# if (__cplusplus >= 201402)
|
||||
# if __has_include(<experimental/string_view>)
|
||||
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
|
||||
# endif // __has_include(<experimental/string_view>)
|
||||
# endif // (__cplusplus >= 201402)
|
||||
# endif // (_LIBCPP_VERSION < 7000)
|
||||
# else // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if (__cplusplus >= 201402)
|
||||
# if __has_include(<experimental/string_view>)
|
||||
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
|
||||
# endif // __has_include(<experimental/string_view>)
|
||||
# endif // (__cplusplus >= 201402)
|
||||
# endif // // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# endif // defined(__clang__)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
|
||||
# if (__cplusplus >= 201402)
|
||||
# define ASIO_HAS_STD_STRING_VIEW 1
|
||||
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
|
||||
# endif // (__cplusplus >= 201402)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1910 && _HAS_CXX17)
|
||||
# define ASIO_HAS_STD_STRING_VIEW
|
||||
# endif // (_MSC_VER >= 1910)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_STRING_VIEW)
|
||||
#endif // !defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
# endif // !defined(ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
#endif // !defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
|
||||
// Standard library has a string_view that we can use.
|
||||
#if !defined(ASIO_HAS_STRING_VIEW)
|
||||
# if !defined(ASIO_DISABLE_STRING_VIEW)
|
||||
# if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
# define ASIO_HAS_STRING_VIEW 1
|
||||
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
# define ASIO_HAS_STRING_VIEW 1
|
||||
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
# endif // !defined(ASIO_DISABLE_STRING_VIEW)
|
||||
#endif // !defined(ASIO_HAS_STRING_VIEW)
|
||||
|
||||
// Standard library support for iostream move construction and assignment.
|
||||
#if !defined(ASIO_HAS_STD_IOSTREAM_MOVE)
|
||||
@@ -815,6 +892,17 @@
|
||||
# endif // !defined(ASIO_DISABLE_STD_IOSTREAM_MOVE)
|
||||
#endif // !defined(ASIO_HAS_STD_IOSTREAM_MOVE)
|
||||
|
||||
// Standard library has invoke_result (which supersedes result_of).
|
||||
#if !defined(ASIO_HAS_STD_INVOKE_RESULT)
|
||||
# if !defined(ASIO_DISABLE_STD_INVOKE_RESULT)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1911 && _MSVC_LANG >= 201703)
|
||||
# define ASIO_HAS_STD_INVOKE_RESULT 1
|
||||
# endif // (_MSC_VER >= 1911 && _MSVC_LANG >= 201703)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_INVOKE_RESULT)
|
||||
#endif // !defined(ASIO_HAS_STD_INVOKE_RESULT)
|
||||
|
||||
// Windows App target. Windows but with a limited API.
|
||||
#if !defined(ASIO_WINDOWS_APP)
|
||||
# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0603)
|
||||
@@ -860,15 +948,15 @@
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
# pragma message( \
|
||||
"Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:\n"\
|
||||
"- add -D_WIN32_WINNT=0x0501 to the compiler command line; or\n"\
|
||||
"- add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.\n"\
|
||||
"Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).")
|
||||
"- add -D_WIN32_WINNT=0x0601 to the compiler command line; or\n"\
|
||||
"- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.\n"\
|
||||
"Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).")
|
||||
# else // defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
# warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
|
||||
# warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line.
|
||||
# warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
|
||||
# warning For example, add -D_WIN32_WINNT=0x0601 to the compiler command line.
|
||||
# warning Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
|
||||
# endif // defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
# define _WIN32_WINNT 0x0501
|
||||
# define _WIN32_WINNT 0x0601
|
||||
# endif // !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS)
|
||||
# if defined(_MSC_VER)
|
||||
# if defined(_WIN32) && !defined(WIN32)
|
||||
@@ -939,7 +1027,8 @@
|
||||
|| defined(__FreeBSD__) \
|
||||
|| defined(__NetBSD__) \
|
||||
|| defined(__OpenBSD__) \
|
||||
|| defined(__linux__)
|
||||
|| defined(__linux__) \
|
||||
|| defined(__HAIKU__)
|
||||
# define ASIO_HAS_UNISTD_H 1
|
||||
# endif
|
||||
# endif // !defined(ASIO_HAS_BOOST_CONFIG)
|
||||
@@ -1303,33 +1392,6 @@
|
||||
// || (defined(__MACH__) && defined(__APPLE__))
|
||||
#endif // !defined(ASIO_DISABLE_SSIZE_T)
|
||||
|
||||
// Helper macros to manage the transition away from the old services-based API.
|
||||
#if defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# define ASIO_SVC_TPARAM , typename Service
|
||||
# define ASIO_SVC_TPARAM_DEF1(d1) , typename Service d1
|
||||
# define ASIO_SVC_TPARAM_DEF2(d1, d2) , typename Service d1, d2
|
||||
# define ASIO_SVC_TARG , Service
|
||||
# define ASIO_SVC_T Service
|
||||
# define ASIO_SVC_TPARAM1 , typename Service1
|
||||
# define ASIO_SVC_TPARAM1_DEF1(d1) , typename Service1 d1
|
||||
# define ASIO_SVC_TPARAM1_DEF2(d1, d2) , typename Service1 d1, d2
|
||||
# define ASIO_SVC_TARG1 , Service1
|
||||
# define ASIO_SVC_T1 Service1
|
||||
# define ASIO_SVC_ACCESS public
|
||||
#else // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
# define ASIO_SVC_TPARAM
|
||||
# define ASIO_SVC_TPARAM_DEF1(d1)
|
||||
# define ASIO_SVC_TPARAM_DEF2(d1, d2)
|
||||
# define ASIO_SVC_TARG
|
||||
// ASIO_SVC_T is defined at each point of use.
|
||||
# define ASIO_SVC_TPARAM1
|
||||
# define ASIO_SVC_TPARAM1_DEF1(d1)
|
||||
# define ASIO_SVC_TPARAM1_DEF2(d1, d2)
|
||||
# define ASIO_SVC_TARG1
|
||||
// ASIO_SVC_T1 is defined at each point of use.
|
||||
# define ASIO_SVC_ACCESS protected
|
||||
#endif // defined(ASIO_ENABLE_OLD_SERVICES)
|
||||
|
||||
// Helper macros to manage transition away from error_code return values.
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
# define ASIO_SYNC_OP_VOID void
|
||||
@@ -1369,4 +1431,24 @@
|
||||
# define ASIO_UNUSED_VARIABLE
|
||||
#endif // !defined(ASIO_UNUSED_VARIABLE)
|
||||
|
||||
// Support co_await on compilers known to allow it.
|
||||
#if !defined(ASIO_HAS_CO_AWAIT)
|
||||
# if !defined(ASIO_DISABLE_CO_AWAIT)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_FULL_VER >= 190023506)
|
||||
# if defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
|
||||
# define ASIO_HAS_CO_AWAIT 1
|
||||
# endif // defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
|
||||
# endif // (_MSC_FULL_VER >= 190023506)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_CO_AWAIT)
|
||||
# if defined(__clang__)
|
||||
# if (__cpp_coroutines >= 201703)
|
||||
# if __has_include(<experimental/coroutine>)
|
||||
# define ASIO_HAS_CO_AWAIT 1
|
||||
# endif // __has_include(<experimental/coroutine>)
|
||||
# endif // (__cpp_coroutines >= 201703)
|
||||
# endif // defined(__clang__)
|
||||
#endif // !defined(ASIO_HAS_CO_AWAIT)
|
||||
|
||||
#endif // ASIO_DETAIL_CONFIG_HPP
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user