Prvni ulozeni z chegewara githubu
This commit is contained in:
BIN
tools/espota.exe
Normal file
BIN
tools/espota.exe
Normal file
Binary file not shown.
353
tools/espota.py
Executable file
353
tools/espota.py
Executable file
@ -0,0 +1,353 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Original espota.py by Ivan Grokhotkov:
|
||||
# https://gist.github.com/igrr/d35ab8446922179dc58c
|
||||
#
|
||||
# Modified since 2015-09-18 from Pascal Gollor (https://github.com/pgollor)
|
||||
# Modified since 2015-11-09 from Hristo Gochkov (https://github.com/me-no-dev)
|
||||
# Modified since 2016-01-03 from Matthew O'Gorman (https://githumb.com/mogorman)
|
||||
#
|
||||
# This script will push an OTA update to the ESP
|
||||
# use it like: python espota.py -i <ESP_IP_address> -I <Host_IP_address> -p <ESP_port> -P <Host_port> [-a password] -f <sketch.bin>
|
||||
# Or to upload SPIFFS image:
|
||||
# python espota.py -i <ESP_IP_address> -I <Host_IP_address> -p <ESP_port> -P <HOST_port> [-a password] -s -f <spiffs.bin>
|
||||
#
|
||||
# Changes
|
||||
# 2015-09-18:
|
||||
# - Add option parser.
|
||||
# - Add logging.
|
||||
# - Send command to controller to differ between flashing and transmitting SPIFFS image.
|
||||
#
|
||||
# Changes
|
||||
# 2015-11-09:
|
||||
# - Added digest authentication
|
||||
# - Enhanced error tracking and reporting
|
||||
#
|
||||
# Changes
|
||||
# 2016-01-03:
|
||||
# - Added more options to parser.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
import socket
|
||||
import sys
|
||||
import os
|
||||
import optparse
|
||||
import logging
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
# Commands
|
||||
FLASH = 0
|
||||
SPIFFS = 100
|
||||
AUTH = 200
|
||||
PROGRESS = False
|
||||
# update_progress() : Displays or updates a console progress bar
|
||||
## Accepts a float between 0 and 1. Any int will be converted to a float.
|
||||
## A value under 0 represents a 'halt'.
|
||||
## A value at 1 or bigger represents 100%
|
||||
def update_progress(progress):
|
||||
if (PROGRESS):
|
||||
barLength = 60 # Modify this to change the length of the progress bar
|
||||
status = ""
|
||||
if isinstance(progress, int):
|
||||
progress = float(progress)
|
||||
if not isinstance(progress, float):
|
||||
progress = 0
|
||||
status = "error: progress var must be float\r\n"
|
||||
if progress < 0:
|
||||
progress = 0
|
||||
status = "Halt...\r\n"
|
||||
if progress >= 1:
|
||||
progress = 1
|
||||
status = "Done...\r\n"
|
||||
block = int(round(barLength*progress))
|
||||
text = "\rUploading: [{0}] {1}% {2}".format( "="*block + " "*(barLength-block), int(progress*100), status)
|
||||
sys.stderr.write(text)
|
||||
sys.stderr.flush()
|
||||
else:
|
||||
sys.stderr.write('.')
|
||||
sys.stderr.flush()
|
||||
|
||||
def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, command = FLASH):
|
||||
# Create a TCP/IP socket
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server_address = (localAddr, localPort)
|
||||
logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1]))
|
||||
try:
|
||||
sock.bind(server_address)
|
||||
sock.listen(1)
|
||||
except:
|
||||
logging.error("Listen Failed")
|
||||
return 1
|
||||
|
||||
content_size = os.path.getsize(filename)
|
||||
f = open(filename,'rb')
|
||||
file_md5 = hashlib.md5(f.read()).hexdigest()
|
||||
f.close()
|
||||
logging.info('Upload size: %d', content_size)
|
||||
message = '%d %d %d %s\n' % (command, localPort, content_size, file_md5)
|
||||
|
||||
# Wait for a connection
|
||||
inv_trys = 0
|
||||
data = ''
|
||||
msg = 'Sending invitation to %s ' % (remoteAddr)
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.flush()
|
||||
while (inv_trys < 10):
|
||||
inv_trys += 1
|
||||
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
remote_address = (remoteAddr, int(remotePort))
|
||||
try:
|
||||
sent = sock2.sendto(message.encode(), remote_address)
|
||||
except:
|
||||
sys.stderr.write('failed\n')
|
||||
sys.stderr.flush()
|
||||
sock2.close()
|
||||
logging.error('Host %s Not Found', remoteAddr)
|
||||
return 1
|
||||
sock2.settimeout(TIMEOUT)
|
||||
try:
|
||||
data = sock2.recv(37).decode()
|
||||
break;
|
||||
except:
|
||||
sys.stderr.write('.')
|
||||
sys.stderr.flush()
|
||||
sock2.close()
|
||||
sys.stderr.write('\n')
|
||||
sys.stderr.flush()
|
||||
if (inv_trys == 10):
|
||||
logging.error('No response from the ESP')
|
||||
return 1
|
||||
if (data != "OK"):
|
||||
if(data.startswith('AUTH')):
|
||||
nonce = data.split()[1]
|
||||
cnonce_text = '%s%u%s%s' % (filename, content_size, file_md5, remoteAddr)
|
||||
cnonce = hashlib.md5(cnonce_text.encode()).hexdigest()
|
||||
passmd5 = hashlib.md5(password.encode()).hexdigest()
|
||||
result_text = '%s:%s:%s' % (passmd5 ,nonce, cnonce)
|
||||
result = hashlib.md5(result_text.encode()).hexdigest()
|
||||
sys.stderr.write('Authenticating...')
|
||||
sys.stderr.flush()
|
||||
message = '%d %s %s\n' % (AUTH, cnonce, result)
|
||||
sock2.sendto(message.encode(), remote_address)
|
||||
sock2.settimeout(10)
|
||||
try:
|
||||
data = sock2.recv(32).decode()
|
||||
except:
|
||||
sys.stderr.write('FAIL\n')
|
||||
logging.error('No Answer to our Authentication')
|
||||
sock2.close()
|
||||
return 1
|
||||
if (data != "OK"):
|
||||
sys.stderr.write('FAIL\n')
|
||||
logging.error('%s', data)
|
||||
sock2.close()
|
||||
sys.exit(1);
|
||||
return 1
|
||||
sys.stderr.write('OK\n')
|
||||
else:
|
||||
logging.error('Bad Answer: %s', data)
|
||||
sock2.close()
|
||||
return 1
|
||||
sock2.close()
|
||||
|
||||
logging.info('Waiting for device...')
|
||||
try:
|
||||
sock.settimeout(10)
|
||||
connection, client_address = sock.accept()
|
||||
sock.settimeout(None)
|
||||
connection.settimeout(None)
|
||||
except:
|
||||
logging.error('No response from device')
|
||||
sock.close()
|
||||
return 1
|
||||
try:
|
||||
f = open(filename, "rb")
|
||||
if (PROGRESS):
|
||||
update_progress(0)
|
||||
else:
|
||||
sys.stderr.write('Uploading')
|
||||
sys.stderr.flush()
|
||||
offset = 0
|
||||
while True:
|
||||
chunk = f.read(1024)
|
||||
if not chunk: break
|
||||
offset += len(chunk)
|
||||
update_progress(offset/float(content_size))
|
||||
connection.settimeout(10)
|
||||
try:
|
||||
connection.sendall(chunk)
|
||||
res = connection.recv(10)
|
||||
lastResponseContainedOK = 'OK' in res.decode()
|
||||
except:
|
||||
sys.stderr.write('\n')
|
||||
logging.error('Error Uploading')
|
||||
connection.close()
|
||||
f.close()
|
||||
sock.close()
|
||||
return 1
|
||||
|
||||
if lastResponseContainedOK:
|
||||
logging.info('Success')
|
||||
connection.close()
|
||||
f.close()
|
||||
sock.close()
|
||||
return 0
|
||||
|
||||
sys.stderr.write('\n')
|
||||
logging.info('Waiting for result...')
|
||||
try:
|
||||
count = 0
|
||||
while True:
|
||||
count=count+1
|
||||
connection.settimeout(60)
|
||||
data = connection.recv(32).decode()
|
||||
logging.info('Result: %s' ,data)
|
||||
|
||||
if "OK" in data:
|
||||
logging.info('Success')
|
||||
connection.close()
|
||||
f.close()
|
||||
sock.close()
|
||||
return 0;
|
||||
if count == 5:
|
||||
logging.error('Error response from device')
|
||||
connection.close()
|
||||
f.close()
|
||||
sock.close()
|
||||
return 1
|
||||
except e:
|
||||
logging.error('No Result!')
|
||||
connection.close()
|
||||
f.close()
|
||||
sock.close()
|
||||
return 1
|
||||
|
||||
finally:
|
||||
connection.close()
|
||||
f.close()
|
||||
|
||||
sock.close()
|
||||
return 1
|
||||
# end serve
|
||||
|
||||
|
||||
def parser(unparsed_args):
|
||||
parser = optparse.OptionParser(
|
||||
usage = "%prog [options]",
|
||||
description = "Transmit image over the air to the esp32 module with OTA support."
|
||||
)
|
||||
|
||||
# destination ip and port
|
||||
group = optparse.OptionGroup(parser, "Destination")
|
||||
group.add_option("-i", "--ip",
|
||||
dest = "esp_ip",
|
||||
action = "store",
|
||||
help = "ESP32 IP Address.",
|
||||
default = False
|
||||
)
|
||||
group.add_option("-I", "--host_ip",
|
||||
dest = "host_ip",
|
||||
action = "store",
|
||||
help = "Host IP Address.",
|
||||
default = "0.0.0.0"
|
||||
)
|
||||
group.add_option("-p", "--port",
|
||||
dest = "esp_port",
|
||||
type = "int",
|
||||
help = "ESP32 ota Port. Default 3232",
|
||||
default = 3232
|
||||
)
|
||||
group.add_option("-P", "--host_port",
|
||||
dest = "host_port",
|
||||
type = "int",
|
||||
help = "Host server ota Port. Default random 10000-60000",
|
||||
default = random.randint(10000,60000)
|
||||
)
|
||||
parser.add_option_group(group)
|
||||
|
||||
# auth
|
||||
group = optparse.OptionGroup(parser, "Authentication")
|
||||
group.add_option("-a", "--auth",
|
||||
dest = "auth",
|
||||
help = "Set authentication password.",
|
||||
action = "store",
|
||||
default = ""
|
||||
)
|
||||
parser.add_option_group(group)
|
||||
|
||||
# image
|
||||
group = optparse.OptionGroup(parser, "Image")
|
||||
group.add_option("-f", "--file",
|
||||
dest = "image",
|
||||
help = "Image file.",
|
||||
metavar="FILE",
|
||||
default = None
|
||||
)
|
||||
group.add_option("-s", "--spiffs",
|
||||
dest = "spiffs",
|
||||
action = "store_true",
|
||||
help = "Use this option to transmit a SPIFFS image and do not flash the module.",
|
||||
default = False
|
||||
)
|
||||
parser.add_option_group(group)
|
||||
|
||||
# output group
|
||||
group = optparse.OptionGroup(parser, "Output")
|
||||
group.add_option("-d", "--debug",
|
||||
dest = "debug",
|
||||
help = "Show debug output. And override loglevel with debug.",
|
||||
action = "store_true",
|
||||
default = False
|
||||
)
|
||||
group.add_option("-r", "--progress",
|
||||
dest = "progress",
|
||||
help = "Show progress output. Does not work for ArduinoIDE",
|
||||
action = "store_true",
|
||||
default = False
|
||||
)
|
||||
group.add_option("-t", "--timeout",
|
||||
dest = "timeout",
|
||||
type = "int",
|
||||
help = "Timeout to wait for the ESP32 to accept invitation",
|
||||
default = 10
|
||||
)
|
||||
parser.add_option_group(group)
|
||||
|
||||
(options, args) = parser.parse_args(unparsed_args)
|
||||
|
||||
return options
|
||||
# end parser
|
||||
|
||||
|
||||
def main(args):
|
||||
options = parser(args)
|
||||
loglevel = logging.WARNING
|
||||
if (options.debug):
|
||||
loglevel = logging.DEBUG
|
||||
|
||||
logging.basicConfig(level = loglevel, format = '%(asctime)-8s [%(levelname)s]: %(message)s', datefmt = '%H:%M:%S')
|
||||
logging.debug("Options: %s", str(options))
|
||||
|
||||
# check options
|
||||
global PROGRESS
|
||||
PROGRESS = options.progress
|
||||
|
||||
global TIMEOUT
|
||||
TIMEOUT = options.timeout
|
||||
|
||||
if (not options.esp_ip or not options.image):
|
||||
logging.critical("Not enough arguments.")
|
||||
return 1
|
||||
|
||||
command = FLASH
|
||||
if (options.spiffs):
|
||||
command = SPIFFS
|
||||
|
||||
return serve(options.esp_ip, options.host_ip, options.esp_port, options.host_port, options.auth, options.image, command)
|
||||
# end main
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
5482
tools/esptool.py
Executable file
5482
tools/esptool.py
Executable file
File diff suppressed because it is too large
Load Diff
227
tools/gen_crt_bundle.py
Normal file
227
tools/gen_crt_bundle.py
Normal file
@ -0,0 +1,227 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# ESP32 x509 certificate bundle generation utility
|
||||
#
|
||||
# Converts PEM and DER certificates to a custom bundle format which stores just the
|
||||
# subject name and public key to reduce space
|
||||
#
|
||||
# The bundle will have the format: number of certificates; crt 1 subject name length; crt 1 public key length;
|
||||
# crt 1 subject name; crt 1 public key; crt 2...
|
||||
#
|
||||
# Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http:#www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
from io import open
|
||||
|
||||
try:
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
except ImportError:
|
||||
print('The cryptography package is not installed.'
|
||||
'Please refer to the Get Started section of the ESP-IDF Programming Guide for '
|
||||
'setting up the required packages.')
|
||||
raise
|
||||
|
||||
ca_bundle_bin_file = 'x509_crt_bundle'
|
||||
|
||||
quiet = False
|
||||
|
||||
|
||||
def status(msg):
|
||||
""" Print status message to stderr """
|
||||
if not quiet:
|
||||
critical(msg)
|
||||
|
||||
|
||||
def critical(msg):
|
||||
""" Print critical message to stderr """
|
||||
sys.stderr.write('gen_crt_bundle.py: ')
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.write('\n')
|
||||
|
||||
|
||||
class CertificateBundle:
|
||||
def __init__(self):
|
||||
self.certificates = []
|
||||
self.compressed_crts = []
|
||||
|
||||
if os.path.isfile(ca_bundle_bin_file):
|
||||
os.remove(ca_bundle_bin_file)
|
||||
|
||||
def add_from_path(self, crts_path):
|
||||
|
||||
found = False
|
||||
for file_path in os.listdir(crts_path):
|
||||
found |= self.add_from_file(os.path.join(crts_path, file_path))
|
||||
|
||||
if found is False:
|
||||
raise InputError('No valid x509 certificates found in %s' % crts_path)
|
||||
|
||||
def add_from_file(self, file_path):
|
||||
try:
|
||||
if file_path.endswith('.pem'):
|
||||
status('Parsing certificates from %s' % file_path)
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
crt_str = f.read()
|
||||
self.add_from_pem(crt_str)
|
||||
return True
|
||||
|
||||
elif file_path.endswith('.der'):
|
||||
status('Parsing certificates from %s' % file_path)
|
||||
with open(file_path, 'rb') as f:
|
||||
crt_str = f.read()
|
||||
self.add_from_der(crt_str)
|
||||
return True
|
||||
|
||||
except ValueError:
|
||||
critical('Invalid certificate in %s' % file_path)
|
||||
raise InputError('Invalid certificate')
|
||||
|
||||
return False
|
||||
|
||||
def add_from_pem(self, crt_str):
|
||||
""" A single PEM file may have multiple certificates """
|
||||
|
||||
crt = ''
|
||||
count = 0
|
||||
start = False
|
||||
|
||||
for strg in crt_str.splitlines(True):
|
||||
if strg == '-----BEGIN CERTIFICATE-----\n' and start is False:
|
||||
crt = ''
|
||||
start = True
|
||||
elif strg == '-----END CERTIFICATE-----\n' and start is True:
|
||||
crt += strg + '\n'
|
||||
start = False
|
||||
self.certificates.append(x509.load_pem_x509_certificate(crt.encode(), default_backend()))
|
||||
count += 1
|
||||
if start is True:
|
||||
crt += strg
|
||||
|
||||
if(count == 0):
|
||||
raise InputError('No certificate found')
|
||||
|
||||
status('Successfully added %d certificates' % count)
|
||||
|
||||
def add_from_der(self, crt_str):
|
||||
self.certificates.append(x509.load_der_x509_certificate(crt_str, default_backend()))
|
||||
status('Successfully added 1 certificate')
|
||||
|
||||
def create_bundle(self):
|
||||
# Sort certificates in order to do binary search when looking up certificates
|
||||
self.certificates = sorted(self.certificates, key=lambda cert: cert.subject.public_bytes(default_backend()))
|
||||
|
||||
bundle = struct.pack('>H', len(self.certificates))
|
||||
|
||||
for crt in self.certificates:
|
||||
""" Read the public key as DER format """
|
||||
pub_key = crt.public_key()
|
||||
pub_key_der = pub_key.public_bytes(serialization.Encoding.DER, serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
|
||||
""" Read the subject name as DER format """
|
||||
sub_name_der = crt.subject.public_bytes(default_backend())
|
||||
|
||||
name_len = len(sub_name_der)
|
||||
key_len = len(pub_key_der)
|
||||
len_data = struct.pack('>HH', name_len, key_len)
|
||||
|
||||
bundle += len_data
|
||||
bundle += sub_name_der
|
||||
bundle += pub_key_der
|
||||
|
||||
return bundle
|
||||
|
||||
def add_with_filter(self, crts_path, filter_path):
|
||||
|
||||
filter_set = set()
|
||||
with open(filter_path, 'r', encoding='utf-8') as f:
|
||||
csv_reader = csv.reader(f, delimiter=',')
|
||||
|
||||
# Skip header
|
||||
next(csv_reader)
|
||||
for row in csv_reader:
|
||||
filter_set.add(row[1])
|
||||
|
||||
status('Parsing certificates from %s' % crts_path)
|
||||
crt_str = []
|
||||
with open(crts_path, 'r', encoding='utf-8') as f:
|
||||
crt_str = f.read()
|
||||
|
||||
# Split all certs into a list of (name, certificate string) tuples
|
||||
pem_crts = re.findall(r'(^.+?)\n(=+\n[\s\S]+?END CERTIFICATE-----\n)', crt_str, re.MULTILINE)
|
||||
|
||||
filtered_crts = ''
|
||||
for name, crt in pem_crts:
|
||||
if name in filter_set:
|
||||
filtered_crts += crt
|
||||
|
||||
self.add_from_pem(filtered_crts)
|
||||
|
||||
|
||||
class InputError(RuntimeError):
|
||||
def __init__(self, e):
|
||||
super(InputError, self).__init__(e)
|
||||
|
||||
|
||||
def main():
|
||||
global quiet
|
||||
|
||||
parser = argparse.ArgumentParser(description='ESP-IDF x509 certificate bundle utility')
|
||||
|
||||
parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true')
|
||||
parser.add_argument('--input', '-i', nargs='+', required=True,
|
||||
help='Paths to the custom certificate folders or files to parse, parses all .pem or .der files')
|
||||
parser.add_argument('--filter', '-f', help='Path to CSV-file where the second columns contains the name of the certificates \
|
||||
that should be included from cacrt_all.pem')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
quiet = args.quiet
|
||||
|
||||
bundle = CertificateBundle()
|
||||
|
||||
for path in args.input:
|
||||
if os.path.isfile(path):
|
||||
if os.path.basename(path) == 'cacrt_all.pem' and args.filter:
|
||||
bundle.add_with_filter(path, args.filter)
|
||||
else:
|
||||
bundle.add_from_file(path)
|
||||
elif os.path.isdir(path):
|
||||
bundle.add_from_path(path)
|
||||
else:
|
||||
raise InputError('Invalid --input=%s, is neither file nor folder' % args.input)
|
||||
|
||||
status('Successfully added %d certificates in total' % len(bundle.certificates))
|
||||
|
||||
crt_bundle = bundle.create_bundle()
|
||||
|
||||
with open(ca_bundle_bin_file, 'wb') as f:
|
||||
f.write(crt_bundle)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except InputError as e:
|
||||
print(e)
|
||||
sys.exit(2)
|
BIN
tools/gen_esp32part.exe
Normal file
BIN
tools/gen_esp32part.exe
Normal file
Binary file not shown.
577
tools/gen_esp32part.py
Executable file
577
tools/gen_esp32part.py
Executable file
@ -0,0 +1,577 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# ESP32 partition table generation tool
|
||||
#
|
||||
# Converts partition tables to/from CSV and binary formats.
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/partition-tables.html
|
||||
# for explanation of partition table structure and uses.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import binascii
|
||||
import errno
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
|
||||
MAX_PARTITION_LENGTH = 0xC00 # 3K for partition data (96 entries) leaves 1K in a 4K sector for signature
|
||||
MD5_PARTITION_BEGIN = b'\xEB\xEB' + b'\xFF' * 14 # The first 2 bytes are like magic numbers for MD5 sum
|
||||
PARTITION_TABLE_SIZE = 0x1000 # Size of partition table
|
||||
|
||||
MIN_PARTITION_SUBTYPE_APP_OTA = 0x10
|
||||
NUM_PARTITION_SUBTYPE_APP_OTA = 16
|
||||
|
||||
__version__ = '1.2'
|
||||
|
||||
APP_TYPE = 0x00
|
||||
DATA_TYPE = 0x01
|
||||
|
||||
TYPES = {
|
||||
'app': APP_TYPE,
|
||||
'data': DATA_TYPE,
|
||||
}
|
||||
|
||||
|
||||
def get_ptype_as_int(ptype):
|
||||
""" Convert a string which might be numeric or the name of a partition type to an integer """
|
||||
try:
|
||||
return TYPES[ptype]
|
||||
except KeyError:
|
||||
try:
|
||||
return int(ptype, 0)
|
||||
except TypeError:
|
||||
return ptype
|
||||
|
||||
|
||||
# Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h
|
||||
SUBTYPES = {
|
||||
APP_TYPE: {
|
||||
'factory': 0x00,
|
||||
'test': 0x20,
|
||||
},
|
||||
DATA_TYPE: {
|
||||
'ota': 0x00,
|
||||
'phy': 0x01,
|
||||
'nvs': 0x02,
|
||||
'coredump': 0x03,
|
||||
'nvs_keys': 0x04,
|
||||
'efuse': 0x05,
|
||||
'undefined': 0x06,
|
||||
'esphttpd': 0x80,
|
||||
'fat': 0x81,
|
||||
'spiffs': 0x82,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def get_subtype_as_int(ptype, subtype):
|
||||
""" Convert a string which might be numeric or the name of a partition subtype to an integer """
|
||||
try:
|
||||
return SUBTYPES[get_ptype_as_int(ptype)][subtype]
|
||||
except KeyError:
|
||||
try:
|
||||
return int(subtype, 0)
|
||||
except TypeError:
|
||||
return subtype
|
||||
|
||||
|
||||
ALIGNMENT = {
|
||||
APP_TYPE: 0x10000,
|
||||
DATA_TYPE: 0x4,
|
||||
}
|
||||
|
||||
|
||||
STRICT_DATA_ALIGNMENT = 0x1000
|
||||
|
||||
|
||||
def get_alignment_for_type(ptype):
|
||||
return ALIGNMENT.get(ptype, ALIGNMENT[DATA_TYPE])
|
||||
|
||||
|
||||
quiet = False
|
||||
md5sum = True
|
||||
secure = False
|
||||
offset_part_table = 0
|
||||
|
||||
|
||||
def status(msg):
|
||||
""" Print status message to stderr """
|
||||
if not quiet:
|
||||
critical(msg)
|
||||
|
||||
|
||||
def critical(msg):
|
||||
""" Print critical message to stderr """
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.write('\n')
|
||||
|
||||
|
||||
class PartitionTable(list):
|
||||
def __init__(self):
|
||||
super(PartitionTable, self).__init__(self)
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, f):
|
||||
data = f.read()
|
||||
data_is_binary = data[0:2] == PartitionDefinition.MAGIC_BYTES
|
||||
if data_is_binary:
|
||||
status('Parsing binary partition input...')
|
||||
return cls.from_binary(data), True
|
||||
|
||||
data = data.decode()
|
||||
status('Parsing CSV input...')
|
||||
return cls.from_csv(data), False
|
||||
|
||||
@classmethod
|
||||
def from_csv(cls, csv_contents):
|
||||
res = PartitionTable()
|
||||
lines = csv_contents.splitlines()
|
||||
|
||||
def expand_vars(f):
|
||||
f = os.path.expandvars(f)
|
||||
m = re.match(r'(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)', f)
|
||||
if m:
|
||||
raise InputError("unknown variable '%s'" % m.group(1))
|
||||
return f
|
||||
|
||||
for line_no in range(len(lines)):
|
||||
line = expand_vars(lines[line_no]).strip()
|
||||
if line.startswith('#') or len(line) == 0:
|
||||
continue
|
||||
try:
|
||||
res.append(PartitionDefinition.from_csv(line, line_no + 1))
|
||||
except InputError as err:
|
||||
raise InputError('Error at line %d: %s' % (line_no + 1, err))
|
||||
except Exception:
|
||||
critical('Unexpected error parsing CSV line %d: %s' % (line_no + 1, line))
|
||||
raise
|
||||
|
||||
# fix up missing offsets & negative sizes
|
||||
last_end = offset_part_table + PARTITION_TABLE_SIZE # first offset after partition table
|
||||
for e in res:
|
||||
if e.offset is not None and e.offset < last_end:
|
||||
if e == res[0]:
|
||||
raise InputError('CSV Error: First partition offset 0x%x overlaps end of partition table 0x%x'
|
||||
% (e.offset, last_end))
|
||||
else:
|
||||
raise InputError('CSV Error: Partitions overlap. Partition at line %d sets offset 0x%x. Previous partition ends 0x%x'
|
||||
% (e.line_no, e.offset, last_end))
|
||||
if e.offset is None:
|
||||
pad_to = get_alignment_for_type(e.type)
|
||||
if last_end % pad_to != 0:
|
||||
last_end += pad_to - (last_end % pad_to)
|
||||
e.offset = last_end
|
||||
if e.size < 0:
|
||||
e.size = -e.size - e.offset
|
||||
last_end = e.offset + e.size
|
||||
|
||||
return res
|
||||
|
||||
def __getitem__(self, item):
|
||||
""" Allow partition table access via name as well as by
|
||||
numeric index. """
|
||||
if isinstance(item, str):
|
||||
for x in self:
|
||||
if x.name == item:
|
||||
return x
|
||||
raise ValueError("No partition entry named '%s'" % item)
|
||||
else:
|
||||
return super(PartitionTable, self).__getitem__(item)
|
||||
|
||||
def find_by_type(self, ptype, subtype):
|
||||
""" Return a partition by type & subtype, returns
|
||||
None if not found """
|
||||
# convert ptype & subtypes names (if supplied this way) to integer values
|
||||
ptype = get_ptype_as_int(ptype)
|
||||
subtype = get_subtype_as_int(ptype, subtype)
|
||||
|
||||
for p in self:
|
||||
if p.type == ptype and p.subtype == subtype:
|
||||
yield p
|
||||
return
|
||||
|
||||
def find_by_name(self, name):
|
||||
for p in self:
|
||||
if p.name == name:
|
||||
return p
|
||||
return None
|
||||
|
||||
def verify(self):
|
||||
# verify each partition individually
|
||||
for p in self:
|
||||
p.verify()
|
||||
|
||||
# check on duplicate name
|
||||
names = [p.name for p in self]
|
||||
duplicates = set(n for n in names if names.count(n) > 1)
|
||||
|
||||
# print sorted duplicate partitions by name
|
||||
if len(duplicates) != 0:
|
||||
critical('A list of partitions that have the same name:')
|
||||
for p in sorted(self, key=lambda x:x.name):
|
||||
if len(duplicates.intersection([p.name])) != 0:
|
||||
critical('%s' % (p.to_csv()))
|
||||
raise InputError('Partition names must be unique')
|
||||
|
||||
# check for overlaps
|
||||
last = None
|
||||
for p in sorted(self, key=lambda x:x.offset):
|
||||
if p.offset < offset_part_table + PARTITION_TABLE_SIZE:
|
||||
raise InputError('Partition offset 0x%x is below 0x%x' % (p.offset, offset_part_table + PARTITION_TABLE_SIZE))
|
||||
if last is not None and p.offset < last.offset + last.size:
|
||||
raise InputError('Partition at 0x%x overlaps 0x%x-0x%x' % (p.offset, last.offset, last.offset + last.size - 1))
|
||||
last = p
|
||||
|
||||
# check that otadata should be unique
|
||||
otadata_duplicates = [p for p in self if p.type == TYPES['data'] and p.subtype == SUBTYPES[DATA_TYPE]['ota']]
|
||||
if len(otadata_duplicates) > 1:
|
||||
for p in otadata_duplicates:
|
||||
critical('%s' % (p.to_csv()))
|
||||
raise InputError('Found multiple otadata partitions. Only one partition can be defined with type="data"(1) and subtype="ota"(0).')
|
||||
|
||||
if len(otadata_duplicates) == 1 and otadata_duplicates[0].size != 0x2000:
|
||||
p = otadata_duplicates[0]
|
||||
critical('%s' % (p.to_csv()))
|
||||
raise InputError('otadata partition must have size = 0x2000')
|
||||
|
||||
def flash_size(self):
|
||||
""" Return the size that partitions will occupy in flash
|
||||
(ie the offset the last partition ends at)
|
||||
"""
|
||||
try:
|
||||
last = sorted(self, reverse=True)[0]
|
||||
except IndexError:
|
||||
return 0 # empty table!
|
||||
return last.offset + last.size
|
||||
|
||||
def verify_size_fits(self, flash_size_bytes: int) -> None:
|
||||
""" Check that partition table fits into the given flash size.
|
||||
Raises InputError otherwise.
|
||||
"""
|
||||
table_size = self.flash_size()
|
||||
if flash_size_bytes < table_size:
|
||||
mb = 1024 * 1024
|
||||
raise InputError('Partitions tables occupies %.1fMB of flash (%d bytes) which does not fit in configured '
|
||||
"flash size %dMB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu." %
|
||||
(table_size / mb, table_size, flash_size_bytes / mb))
|
||||
|
||||
@classmethod
|
||||
def from_binary(cls, b):
|
||||
md5 = hashlib.md5()
|
||||
result = cls()
|
||||
for o in range(0,len(b),32):
|
||||
data = b[o:o + 32]
|
||||
if len(data) != 32:
|
||||
raise InputError('Partition table length must be a multiple of 32 bytes')
|
||||
if data == b'\xFF' * 32:
|
||||
return result # got end marker
|
||||
if md5sum and data[:2] == MD5_PARTITION_BEGIN[:2]: # check only the magic number part
|
||||
if data[16:] == md5.digest():
|
||||
continue # the next iteration will check for the end marker
|
||||
else:
|
||||
raise InputError("MD5 checksums don't match! (computed: 0x%s, parsed: 0x%s)" % (md5.hexdigest(), binascii.hexlify(data[16:])))
|
||||
else:
|
||||
md5.update(data)
|
||||
result.append(PartitionDefinition.from_binary(data))
|
||||
raise InputError('Partition table is missing an end-of-table marker')
|
||||
|
||||
def to_binary(self):
|
||||
result = b''.join(e.to_binary() for e in self)
|
||||
if md5sum:
|
||||
result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest()
|
||||
if len(result) >= MAX_PARTITION_LENGTH:
|
||||
raise InputError('Binary partition table length (%d) longer than max' % len(result))
|
||||
result += b'\xFF' * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing
|
||||
return result
|
||||
|
||||
def to_csv(self, simple_formatting=False):
|
||||
rows = ['# ESP-IDF Partition Table',
|
||||
'# Name, Type, SubType, Offset, Size, Flags']
|
||||
rows += [x.to_csv(simple_formatting) for x in self]
|
||||
return '\n'.join(rows) + '\n'
|
||||
|
||||
|
||||
class PartitionDefinition(object):
|
||||
MAGIC_BYTES = b'\xAA\x50'
|
||||
|
||||
# dictionary maps flag name (as used in CSV flags list, property name)
|
||||
# to bit set in flags words in binary format
|
||||
FLAGS = {
|
||||
'encrypted': 0
|
||||
}
|
||||
|
||||
# add subtypes for the 16 OTA slot values ("ota_XX, etc.")
|
||||
for ota_slot in range(NUM_PARTITION_SUBTYPE_APP_OTA):
|
||||
SUBTYPES[TYPES['app']]['ota_%d' % ota_slot] = MIN_PARTITION_SUBTYPE_APP_OTA + ota_slot
|
||||
|
||||
def __init__(self):
|
||||
self.name = ''
|
||||
self.type = None
|
||||
self.subtype = None
|
||||
self.offset = None
|
||||
self.size = None
|
||||
self.encrypted = False
|
||||
|
||||
@classmethod
|
||||
def from_csv(cls, line, line_no):
|
||||
""" Parse a line from the CSV """
|
||||
line_w_defaults = line + ',,,,' # lazy way to support default fields
|
||||
fields = [f.strip() for f in line_w_defaults.split(',')]
|
||||
|
||||
res = PartitionDefinition()
|
||||
res.line_no = line_no
|
||||
res.name = fields[0]
|
||||
res.type = res.parse_type(fields[1])
|
||||
res.subtype = res.parse_subtype(fields[2])
|
||||
res.offset = res.parse_address(fields[3])
|
||||
res.size = res.parse_address(fields[4])
|
||||
if res.size is None:
|
||||
raise InputError("Size field can't be empty")
|
||||
|
||||
flags = fields[5].split(':')
|
||||
for flag in flags:
|
||||
if flag in cls.FLAGS:
|
||||
setattr(res, flag, True)
|
||||
elif len(flag) > 0:
|
||||
raise InputError("CSV flag column contains unknown flag '%s'" % (flag))
|
||||
|
||||
return res
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.name == other.name and self.type == other.type \
|
||||
and self.subtype == other.subtype and self.offset == other.offset \
|
||||
and self.size == other.size
|
||||
|
||||
def __repr__(self):
|
||||
def maybe_hex(x):
|
||||
return '0x%x' % x if x is not None else 'None'
|
||||
return "PartitionDefinition('%s', 0x%x, 0x%x, %s, %s)" % (self.name, self.type, self.subtype or 0,
|
||||
maybe_hex(self.offset), maybe_hex(self.size))
|
||||
|
||||
def __str__(self):
|
||||
return "Part '%s' %d/%d @ 0x%x size 0x%x" % (self.name, self.type, self.subtype, self.offset or -1, self.size or -1)
|
||||
|
||||
def __cmp__(self, other):
|
||||
return self.offset - other.offset
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.offset < other.offset
|
||||
|
||||
def __gt__(self, other):
|
||||
return self.offset > other.offset
|
||||
|
||||
def __le__(self, other):
|
||||
return self.offset <= other.offset
|
||||
|
||||
def __ge__(self, other):
|
||||
return self.offset >= other.offset
|
||||
|
||||
def parse_type(self, strval):
|
||||
if strval == '':
|
||||
raise InputError("Field 'type' can't be left empty.")
|
||||
return parse_int(strval, TYPES)
|
||||
|
||||
def parse_subtype(self, strval):
|
||||
if strval == '':
|
||||
if self.type == TYPES['app']:
|
||||
raise InputError('App partition cannot have an empty subtype')
|
||||
return SUBTYPES[DATA_TYPE]['undefined']
|
||||
return parse_int(strval, SUBTYPES.get(self.type, {}))
|
||||
|
||||
def parse_address(self, strval):
|
||||
if strval == '':
|
||||
return None # PartitionTable will fill in default
|
||||
return parse_int(strval)
|
||||
|
||||
def verify(self):
|
||||
if self.type is None:
|
||||
raise ValidationError(self, 'Type field is not set')
|
||||
if self.subtype is None:
|
||||
raise ValidationError(self, 'Subtype field is not set')
|
||||
if self.offset is None:
|
||||
raise ValidationError(self, 'Offset field is not set')
|
||||
align = get_alignment_for_type(self.type)
|
||||
if self.offset % align:
|
||||
raise ValidationError(self, 'Offset 0x%x is not aligned to 0x%x' % (self.offset, align))
|
||||
# The alignment requirement for non-app partition is 4 bytes, but it should be 4 kB.
|
||||
# Print a warning for now, make it an error in IDF 5.0 (IDF-3742).
|
||||
if self.type != APP_TYPE and self.offset % STRICT_DATA_ALIGNMENT:
|
||||
critical('WARNING: Partition %s not aligned to 0x%x.'
|
||||
'This is deprecated and will be considered an error in the future release.' % (self.name, STRICT_DATA_ALIGNMENT))
|
||||
if self.size % align and secure and self.type == APP_TYPE:
|
||||
raise ValidationError(self, 'Size 0x%x is not aligned to 0x%x' % (self.size, align))
|
||||
if self.size is None:
|
||||
raise ValidationError(self, 'Size field is not set')
|
||||
|
||||
if self.name in TYPES and TYPES.get(self.name, '') != self.type:
|
||||
critical("WARNING: Partition has name '%s' which is a partition type, but does not match this partition's "
|
||||
'type (0x%x). Mistake in partition table?' % (self.name, self.type))
|
||||
all_subtype_names = []
|
||||
for names in (t.keys() for t in SUBTYPES.values()):
|
||||
all_subtype_names += names
|
||||
if self.name in all_subtype_names and SUBTYPES.get(self.type, {}).get(self.name, '') != self.subtype:
|
||||
critical("WARNING: Partition has name '%s' which is a partition subtype, but this partition has "
|
||||
'non-matching type 0x%x and subtype 0x%x. Mistake in partition table?' % (self.name, self.type, self.subtype))
|
||||
|
||||
STRUCT_FORMAT = b'<2sBBLL16sL'
|
||||
|
||||
@classmethod
|
||||
def from_binary(cls, b):
|
||||
if len(b) != 32:
|
||||
raise InputError('Partition definition length must be exactly 32 bytes. Got %d bytes.' % len(b))
|
||||
res = cls()
|
||||
(magic, res.type, res.subtype, res.offset,
|
||||
res.size, res.name, flags) = struct.unpack(cls.STRUCT_FORMAT, b)
|
||||
if b'\x00' in res.name: # strip null byte padding from name string
|
||||
res.name = res.name[:res.name.index(b'\x00')]
|
||||
res.name = res.name.decode()
|
||||
if magic != cls.MAGIC_BYTES:
|
||||
raise InputError('Invalid magic bytes (%r) for partition definition' % magic)
|
||||
for flag,bit in cls.FLAGS.items():
|
||||
if flags & (1 << bit):
|
||||
setattr(res, flag, True)
|
||||
flags &= ~(1 << bit)
|
||||
if flags != 0:
|
||||
critical('WARNING: Partition definition had unknown flag(s) 0x%08x. Newer binary format?' % flags)
|
||||
return res
|
||||
|
||||
def get_flags_list(self):
|
||||
return [flag for flag in self.FLAGS.keys() if getattr(self, flag)]
|
||||
|
||||
def to_binary(self):
|
||||
flags = sum((1 << self.FLAGS[flag]) for flag in self.get_flags_list())
|
||||
return struct.pack(self.STRUCT_FORMAT,
|
||||
self.MAGIC_BYTES,
|
||||
self.type, self.subtype,
|
||||
self.offset, self.size,
|
||||
self.name.encode(),
|
||||
flags)
|
||||
|
||||
def to_csv(self, simple_formatting=False):
|
||||
def addr_format(a, include_sizes):
|
||||
if not simple_formatting and include_sizes:
|
||||
for (val, suffix) in [(0x100000, 'M'), (0x400, 'K')]:
|
||||
if a % val == 0:
|
||||
return '%d%s' % (a // val, suffix)
|
||||
return '0x%x' % a
|
||||
|
||||
def lookup_keyword(t, keywords):
|
||||
for k,v in keywords.items():
|
||||
if simple_formatting is False and t == v:
|
||||
return k
|
||||
return '%d' % t
|
||||
|
||||
def generate_text_flags():
|
||||
""" colon-delimited list of flags """
|
||||
return ':'.join(self.get_flags_list())
|
||||
|
||||
return ','.join([self.name,
|
||||
lookup_keyword(self.type, TYPES),
|
||||
lookup_keyword(self.subtype, SUBTYPES.get(self.type, {})),
|
||||
addr_format(self.offset, False),
|
||||
addr_format(self.size, True),
|
||||
generate_text_flags()])
|
||||
|
||||
|
||||
def parse_int(v, keywords={}):
|
||||
"""Generic parser for integer fields - int(x,0) with provision for
|
||||
k/m/K/M suffixes and 'keyword' value lookup.
|
||||
"""
|
||||
try:
|
||||
for letter, multiplier in [('k', 1024), ('m', 1024 * 1024)]:
|
||||
if v.lower().endswith(letter):
|
||||
return parse_int(v[:-1], keywords) * multiplier
|
||||
return int(v, 0)
|
||||
except ValueError:
|
||||
if len(keywords) == 0:
|
||||
raise InputError('Invalid field value %s' % v)
|
||||
try:
|
||||
return keywords[v.lower()]
|
||||
except KeyError:
|
||||
raise InputError("Value '%s' is not valid. Known keywords: %s" % (v, ', '.join(keywords)))
|
||||
|
||||
|
||||
def main():
|
||||
global quiet
|
||||
global md5sum
|
||||
global offset_part_table
|
||||
global secure
|
||||
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
||||
|
||||
parser.add_argument('--flash-size', help='Optional flash size limit, checks partition table fits in flash',
|
||||
nargs='?', choices=['1MB', '2MB', '4MB', '8MB', '16MB', '32MB', '64MB', '128MB'])
|
||||
parser.add_argument('--disable-md5sum', help='Disable md5 checksum for the partition table', default=False, action='store_true')
|
||||
parser.add_argument('--no-verify', help="Don't verify partition table fields", action='store_true')
|
||||
parser.add_argument('--verify', '-v', help='Verify partition table fields (deprecated, this behaviour is '
|
||||
'enabled by default and this flag does nothing.', action='store_true')
|
||||
parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true')
|
||||
parser.add_argument('--offset', '-o', help='Set offset partition table', default='0x8000')
|
||||
parser.add_argument('--secure', help='Require app partitions to be suitable for secure boot', action='store_true')
|
||||
parser.add_argument('input', help='Path to CSV or binary file to parse.', type=argparse.FileType('rb'))
|
||||
parser.add_argument('output', help='Path to output converted binary or CSV file. Will use stdout if omitted.',
|
||||
nargs='?', default='-')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
quiet = args.quiet
|
||||
md5sum = not args.disable_md5sum
|
||||
secure = args.secure
|
||||
offset_part_table = int(args.offset, 0)
|
||||
table, input_is_binary = PartitionTable.from_file(args.input)
|
||||
|
||||
if not args.no_verify:
|
||||
status('Verifying table...')
|
||||
table.verify()
|
||||
|
||||
if args.flash_size:
|
||||
size_mb = int(args.flash_size.replace('MB', ''))
|
||||
table.verify_size_fits(size_mb * 1024 * 1024)
|
||||
|
||||
# Make sure that the output directory is created
|
||||
output_dir = os.path.abspath(os.path.dirname(args.output))
|
||||
|
||||
if not os.path.exists(output_dir):
|
||||
try:
|
||||
os.makedirs(output_dir)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
if input_is_binary:
|
||||
output = table.to_csv()
|
||||
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
|
||||
f.write(output)
|
||||
else:
|
||||
output = table.to_binary()
|
||||
try:
|
||||
stdout_binary = sys.stdout.buffer # Python 3
|
||||
except AttributeError:
|
||||
stdout_binary = sys.stdout
|
||||
with stdout_binary if args.output == '-' else open(args.output, 'wb') as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
class InputError(RuntimeError):
|
||||
def __init__(self, e):
|
||||
super(InputError, self).__init__(e)
|
||||
|
||||
|
||||
class ValidationError(InputError):
|
||||
def __init__(self, partition, message):
|
||||
super(ValidationError, self).__init__(
|
||||
'Partition %s invalid: %s' % (partition.name, message))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except InputError as e:
|
||||
print(e, file=sys.stderr)
|
||||
sys.exit(2)
|
BIN
tools/get.exe
Normal file
BIN
tools/get.exe
Normal file
Binary file not shown.
208
tools/get.py
Executable file
208
tools/get.py
Executable file
@ -0,0 +1,208 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Script to download and extract tools
|
||||
|
||||
This script will download and extract required tools into the current directory.
|
||||
Tools list is obtained from package/package_esp8266com_index.template.json file.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
__author__ = "Ivan Grokhotkov"
|
||||
__version__ = "2015"
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import errno
|
||||
import os.path
|
||||
import hashlib
|
||||
import json
|
||||
import platform
|
||||
import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
import re
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
from urllib.request import urlretrieve
|
||||
from urllib.request import urlopen
|
||||
unicode = lambda s: str(s)
|
||||
else:
|
||||
# Not Python 3 - today, it is most likely to be Python 2
|
||||
from urllib import urlretrieve
|
||||
from urllib import urlopen
|
||||
|
||||
if 'Windows' in platform.system():
|
||||
import requests
|
||||
|
||||
current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
|
||||
dist_dir = current_dir + '/dist/'
|
||||
|
||||
def sha256sum(filename, blocksize=65536):
|
||||
hash = hashlib.sha256()
|
||||
with open(filename, "rb") as f:
|
||||
for block in iter(lambda: f.read(blocksize), b""):
|
||||
hash.update(block)
|
||||
return hash.hexdigest()
|
||||
|
||||
def mkdir_p(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.EEXIST or not os.path.isdir(path):
|
||||
raise
|
||||
|
||||
def report_progress(count, blockSize, totalSize):
|
||||
if sys.stdout.isatty():
|
||||
if totalSize > 0:
|
||||
percent = int(count*blockSize*100/totalSize)
|
||||
percent = min(100, percent)
|
||||
sys.stdout.write("\r%d%%" % percent)
|
||||
else:
|
||||
sofar = (count*blockSize) / 1024
|
||||
if sofar >= 1000:
|
||||
sofar /= 1024
|
||||
sys.stdout.write("\r%dMB " % (sofar))
|
||||
else:
|
||||
sys.stdout.write("\r%dKB" % (sofar))
|
||||
sys.stdout.flush()
|
||||
|
||||
def unpack(filename, destination):
|
||||
dirname = ''
|
||||
print('Extracting {0} ...'.format(os.path.basename(filename)))
|
||||
sys.stdout.flush()
|
||||
if filename.endswith('tar.gz'):
|
||||
tfile = tarfile.open(filename, 'r:gz')
|
||||
tfile.extractall(destination)
|
||||
dirname = tfile.getnames()[0]
|
||||
elif filename.endswith('zip'):
|
||||
zfile = zipfile.ZipFile(filename)
|
||||
zfile.extractall(destination)
|
||||
dirname = zfile.namelist()[0]
|
||||
else:
|
||||
raise NotImplementedError('Unsupported archive type')
|
||||
|
||||
# a little trick to rename tool directories so they don't contain version number
|
||||
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-')
|
||||
if rename_to != dirname:
|
||||
print('Renaming {0} to {1} ...'.format(dirname, rename_to))
|
||||
if os.path.isdir(rename_to):
|
||||
shutil.rmtree(rename_to)
|
||||
shutil.move(dirname, rename_to)
|
||||
|
||||
def download_file_with_progress(url,filename):
|
||||
import ssl
|
||||
import contextlib
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
with contextlib.closing(urlopen(url,context=ctx)) as fp:
|
||||
total_size = int(fp.getheader("Content-Length",fp.getheader("Content-length","0")))
|
||||
block_count = 0
|
||||
block_size = 1024 * 8
|
||||
block = fp.read(block_size)
|
||||
if block:
|
||||
with open(filename,'wb') as out_file:
|
||||
out_file.write(block)
|
||||
block_count += 1
|
||||
report_progress(block_count, block_size, total_size)
|
||||
while True:
|
||||
block = fp.read(block_size)
|
||||
if not block:
|
||||
break
|
||||
out_file.write(block)
|
||||
block_count += 1
|
||||
report_progress(block_count, block_size, total_size)
|
||||
else:
|
||||
raise Exception ('nonexisting file or connection error')
|
||||
|
||||
def download_file(url,filename):
|
||||
import ssl
|
||||
import contextlib
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
with contextlib.closing(urlopen(url,context=ctx)) as fp:
|
||||
block_size = 1024 * 8
|
||||
block = fp.read(block_size)
|
||||
if block:
|
||||
with open(filename,'wb') as out_file:
|
||||
out_file.write(block)
|
||||
while True:
|
||||
block = fp.read(block_size)
|
||||
if not block:
|
||||
break
|
||||
out_file.write(block)
|
||||
else:
|
||||
raise Exception ('nonexisting file or connection error')
|
||||
|
||||
def get_tool(tool):
|
||||
sys_name = platform.system()
|
||||
archive_name = tool['archiveFileName']
|
||||
local_path = dist_dir + archive_name
|
||||
url = tool['url']
|
||||
if not os.path.isfile(local_path):
|
||||
print('Downloading ' + archive_name + ' ...')
|
||||
sys.stdout.flush()
|
||||
if 'CYGWIN_NT' in sys_name:
|
||||
import ssl
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
urlretrieve(url, local_path, report_progress, context=ctx)
|
||||
elif 'Windows' in sys_name:
|
||||
r = requests.get(url)
|
||||
f = open(local_path, 'wb')
|
||||
f.write(r.content)
|
||||
f.close()
|
||||
else:
|
||||
is_ci = os.environ.get('GITHUB_WORKSPACE');
|
||||
if is_ci:
|
||||
download_file(url, local_path)
|
||||
else:
|
||||
try:
|
||||
urlretrieve(url, local_path, report_progress)
|
||||
except:
|
||||
download_file_with_progress(url, local_path)
|
||||
sys.stdout.write("\rDone \n")
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
print('Tool {0} already downloaded'.format(archive_name))
|
||||
sys.stdout.flush()
|
||||
unpack(local_path, '.')
|
||||
|
||||
def load_tools_list(filename, platform):
|
||||
tools_info = json.load(open(filename))['packages'][0]['tools']
|
||||
tools_to_download = []
|
||||
for t in tools_info:
|
||||
tool_platform = [p for p in t['systems'] if p['host'] == platform]
|
||||
if len(tool_platform) == 0:
|
||||
continue
|
||||
tools_to_download.append(tool_platform[0])
|
||||
return tools_to_download
|
||||
|
||||
def identify_platform():
|
||||
arduino_platform_names = {'Darwin' : {32 : 'i386-apple-darwin', 64 : 'x86_64-apple-darwin'},
|
||||
'Linux' : {32 : 'i686-pc-linux-gnu', 64 : 'x86_64-pc-linux-gnu'},
|
||||
'LinuxARM': {32 : 'arm-linux-gnueabihf', 64 : 'aarch64-linux-gnu'},
|
||||
'Windows' : {32 : 'i686-mingw32', 64 : 'i686-mingw32'}}
|
||||
bits = 32
|
||||
if sys.maxsize > 2**32:
|
||||
bits = 64
|
||||
sys_name = platform.system()
|
||||
sys_platform = platform.platform()
|
||||
if 'Linux' in sys_name and (sys_platform.find('arm') > 0 or sys_platform.find('aarch64') > 0):
|
||||
sys_name = 'LinuxARM'
|
||||
if 'CYGWIN_NT' in sys_name:
|
||||
sys_name = 'Windows'
|
||||
print('System: %s, Bits: %d, Info: %s' % (sys_name, bits, sys_platform))
|
||||
return arduino_platform_names[sys_name][bits]
|
||||
|
||||
if __name__ == '__main__':
|
||||
identified_platform = identify_platform()
|
||||
print('Platform: {0}'.format(identified_platform))
|
||||
tools_to_download = load_tools_list(current_dir + '/../package/package_esp32_index.template.json', identified_platform)
|
||||
mkdir_p(dist_dir)
|
||||
for tool in tools_to_download:
|
||||
get_tool(tool)
|
||||
print('Platform Tools Installed')
|
7
tools/partitions/app3M_fat9M_16MB.csv
Normal file
7
tools/partitions/app3M_fat9M_16MB.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x300000,
|
||||
app1, app, ota_1, 0x310000,0x300000,
|
||||
ffat, data, fat, 0x610000,0x9F0000,
|
||||
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
|
|
3
tools/partitions/bare_minimum_2MB.csv
Normal file
3
tools/partitions/bare_minimum_2MB.csv
Normal file
@ -0,0 +1,3 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 36K, 20K,
|
||||
factory, app, factory, 64K, 1900K,
|
|
BIN
tools/partitions/boot_app0.bin
Normal file
BIN
tools/partitions/boot_app0.bin
Normal file
Binary file not shown.
BIN
tools/partitions/default.bin
Normal file
BIN
tools/partitions/default.bin
Normal file
Binary file not shown.
6
tools/partitions/default.csv
Normal file
6
tools/partitions/default.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x140000,
|
||||
app1, app, ota_1, 0x150000,0x140000,
|
||||
spiffs, data, spiffs, 0x290000,0x170000,
|
|
6
tools/partitions/default_16MB.csv
Normal file
6
tools/partitions/default_16MB.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x640000,
|
||||
app1, app, ota_1, 0x650000,0x640000,
|
||||
spiffs, data, spiffs, 0xc90000,0x370000,
|
|
6
tools/partitions/default_8MB.csv
Normal file
6
tools/partitions/default_8MB.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x330000,
|
||||
app1, app, ota_1, 0x340000,0x330000,
|
||||
spiffs, data, spiffs, 0x670000,0x190000,
|
|
6
tools/partitions/default_ffat.csv
Normal file
6
tools/partitions/default_ffat.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x140000,
|
||||
app1, app, ota_1, 0x150000,0x140000,
|
||||
ffat, data, fat, 0x290000,0x170000,
|
|
7
tools/partitions/ffat.csv
Normal file
7
tools/partitions/ffat.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x200000,
|
||||
app1, app, ota_1, 0x210000,0x200000,
|
||||
ffat, data, fat, 0x410000,0xBF0000,
|
||||
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
|
|
5
tools/partitions/huge_app.csv
Normal file
5
tools/partitions/huge_app.csv
Normal file
@ -0,0 +1,5 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x300000,
|
||||
spiffs, data, spiffs, 0x310000,0xF0000,
|
|
6
tools/partitions/large_spiffs_16MB.csv
Normal file
6
tools/partitions/large_spiffs_16MB.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x480000,
|
||||
app1, app, ota_1, 0x490000,0x480000,
|
||||
spiffs, data, spiffs, 0x910000,0x6F0000,
|
|
4
tools/partitions/max_app_8MB.csv
Normal file
4
tools/partitions/max_app_8MB.csv
Normal file
@ -0,0 +1,4 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, factory, 0x10000, 0x7F0000,
|
|
6
tools/partitions/min_spiffs.csv
Normal file
6
tools/partitions/min_spiffs.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x1E0000,
|
||||
app1, app, ota_1, 0x1F0000,0x1E0000,
|
||||
spiffs, data, spiffs, 0x3D0000,0x30000,
|
|
5
tools/partitions/minimal.csv
Normal file
5
tools/partitions/minimal.csv
Normal file
@ -0,0 +1,5 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x140000,
|
||||
spiffs, data, spiffs, 0x150000, 0xB0000,
|
|
5
tools/partitions/no_ota.csv
Normal file
5
tools/partitions/no_ota.csv
Normal file
@ -0,0 +1,5 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x200000,
|
||||
spiffs, data, spiffs, 0x210000,0x1F0000,
|
|
5
tools/partitions/noota_3g.csv
Normal file
5
tools/partitions/noota_3g.csv
Normal file
@ -0,0 +1,5 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x100000,
|
||||
spiffs, data, spiffs, 0x110000,0x2F0000,
|
|
6
tools/partitions/noota_3gffat.csv
Normal file
6
tools/partitions/noota_3gffat.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x100000,
|
||||
ffat, data, fat, 0x110000,0x2F0000,
|
||||
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
|
|
6
tools/partitions/noota_ffat.csv
Normal file
6
tools/partitions/noota_ffat.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x200000,
|
||||
ffat, data, fat, 0x210000,0x1F0000,
|
||||
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
|
|
6
tools/partitions/rainmaker.csv
Normal file
6
tools/partitions/rainmaker.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
ota_0, app, ota_0, 0x10000, 0x1E0000,
|
||||
ota_1, app, ota_1, 0x1F0000, 0x1E0000,
|
||||
fctry, data, nvs, 0x3D0000, 0x6000,
|
|
338
tools/platformio-build-esp32.py
Normal file
338
tools/platformio-build-esp32.py
Normal file
File diff suppressed because one or more lines are too long
271
tools/platformio-build.py
Normal file
271
tools/platformio-build.py
Normal file
@ -0,0 +1,271 @@
|
||||
# Copyright 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Arduino
|
||||
|
||||
Arduino Wiring-based Framework allows writing cross-platform software to
|
||||
control devices attached to a wide range of Arduino boards to create all
|
||||
kinds of creative coding, interactive objects, spaces or physical experiences.
|
||||
|
||||
http://arduino.cc/en/Reference/HomePage
|
||||
"""
|
||||
|
||||
# Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py
|
||||
|
||||
from os.path import abspath, basename, isdir, isfile, join
|
||||
|
||||
from SCons.Script import DefaultEnvironment, SConscript
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
board_config = env.BoardConfig()
|
||||
build_mcu = board_config.get("build.mcu", "").lower()
|
||||
partitions_name = board_config.get(
|
||||
"build.partitions", board_config.get("build.arduino.partitions", "")
|
||||
)
|
||||
|
||||
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
|
||||
assert isdir(FRAMEWORK_DIR)
|
||||
|
||||
|
||||
#
|
||||
# Helpers
|
||||
#
|
||||
|
||||
|
||||
def get_partition_table_csv(variants_dir):
|
||||
fwpartitions_dir = join(FRAMEWORK_DIR, "tools", "partitions")
|
||||
variant_partitions_dir = join(variants_dir, board_config.get("build.variant", ""))
|
||||
|
||||
if partitions_name:
|
||||
# A custom partitions file is selected
|
||||
if isfile(join(variant_partitions_dir, partitions_name)):
|
||||
return join(variant_partitions_dir, partitions_name)
|
||||
|
||||
return abspath(
|
||||
join(fwpartitions_dir, partitions_name)
|
||||
if isfile(join(fwpartitions_dir, partitions_name))
|
||||
else partitions_name
|
||||
)
|
||||
|
||||
variant_partitions = join(variant_partitions_dir, "partitions.csv")
|
||||
return (
|
||||
variant_partitions
|
||||
if isfile(variant_partitions)
|
||||
else join(fwpartitions_dir, "default.csv")
|
||||
)
|
||||
|
||||
|
||||
def get_bootloader_image(variants_dir):
|
||||
bootloader_image_file = "bootloader.bin"
|
||||
if partitions_name.endswith("tinyuf2.csv"):
|
||||
bootloader_image_file = "bootloader-tinyuf2.bin"
|
||||
|
||||
variant_bootloader = join(
|
||||
variants_dir,
|
||||
board_config.get("build.variant", ""),
|
||||
board_config.get("build.arduino.custom_bootloader", bootloader_image_file),
|
||||
)
|
||||
|
||||
return (
|
||||
variant_bootloader
|
||||
if isfile(variant_bootloader)
|
||||
else join(
|
||||
FRAMEWORK_DIR,
|
||||
"tools",
|
||||
"sdk",
|
||||
build_mcu,
|
||||
"bin",
|
||||
"bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.bin",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def get_patched_bootloader_image(original_bootloader_image, bootloader_offset):
|
||||
patched_bootloader_image = join(env.subst("$BUILD_DIR"), "patched_bootloader.bin")
|
||||
bootloader_cmd = env.Command(
|
||||
patched_bootloader_image,
|
||||
original_bootloader_image,
|
||||
env.VerboseAction(
|
||||
" ".join(
|
||||
[
|
||||
'"$PYTHONEXE"',
|
||||
join(
|
||||
platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"
|
||||
),
|
||||
"--chip",
|
||||
build_mcu,
|
||||
"merge_bin",
|
||||
"-o",
|
||||
"$TARGET",
|
||||
"--flash_mode",
|
||||
"${__get_board_flash_mode(__env__)}",
|
||||
"--flash_freq",
|
||||
"${__get_board_f_flash(__env__)}",
|
||||
"--flash_size",
|
||||
board_config.get("upload.flash_size", "4MB"),
|
||||
"--target-offset",
|
||||
bootloader_offset,
|
||||
bootloader_offset,
|
||||
"$SOURCE",
|
||||
]
|
||||
),
|
||||
"Updating bootloader headers",
|
||||
),
|
||||
)
|
||||
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", bootloader_cmd)
|
||||
|
||||
return patched_bootloader_image
|
||||
|
||||
|
||||
def add_tinyuf2_extra_image():
|
||||
tinuf2_image = board_config.get(
|
||||
"upload.arduino.tinyuf2_image",
|
||||
join(variants_dir, board_config.get("build.variant", ""), "tinyuf2.bin"),
|
||||
)
|
||||
|
||||
# Add the UF2 image only if it exists and it's not already added
|
||||
if not isfile(tinuf2_image):
|
||||
print("Warning! The `%s` UF2 bootloader image doesn't exist" % tinuf2_image)
|
||||
return
|
||||
|
||||
if any(
|
||||
"tinyuf2.bin" == basename(extra_image[1])
|
||||
for extra_image in env.get("FLASH_EXTRA_IMAGES", [])
|
||||
):
|
||||
print("Warning! An extra UF2 bootloader image is already added!")
|
||||
return
|
||||
|
||||
env.Append(
|
||||
FLASH_EXTRA_IMAGES=[
|
||||
(
|
||||
board_config.get(
|
||||
"upload.arduino.uf2_bootloader_offset",
|
||||
(
|
||||
"0x2d0000"
|
||||
if env.subst("$BOARD").startswith("adafruit")
|
||||
else "0x410000"
|
||||
),
|
||||
),
|
||||
tinuf2_image,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Run target-specific script to populate the environment with proper build flags
|
||||
#
|
||||
|
||||
SConscript(
|
||||
join(
|
||||
DefaultEnvironment()
|
||||
.PioPlatform()
|
||||
.get_package_dir("framework-arduinoespressif32"),
|
||||
"tools",
|
||||
"platformio-build-%s.py" % build_mcu,
|
||||
)
|
||||
)
|
||||
|
||||
#
|
||||
# Target: Build Core Library
|
||||
#
|
||||
|
||||
libs = []
|
||||
|
||||
variants_dir = join(FRAMEWORK_DIR, "variants")
|
||||
|
||||
if "build.variants_dir" in board_config:
|
||||
variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir"))
|
||||
|
||||
if "build.variant" in board_config:
|
||||
env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))])
|
||||
env.BuildSources(
|
||||
join("$BUILD_DIR", "FrameworkArduinoVariant"),
|
||||
join(variants_dir, board_config.get("build.variant")),
|
||||
)
|
||||
|
||||
libs.append(
|
||||
env.BuildLibrary(
|
||||
join("$BUILD_DIR", "FrameworkArduino"),
|
||||
join(FRAMEWORK_DIR, "cores", board_config.get("build.core")),
|
||||
)
|
||||
)
|
||||
|
||||
env.Prepend(LIBS=libs)
|
||||
|
||||
#
|
||||
# Process framework extra images
|
||||
#
|
||||
|
||||
# Starting with v2.0.4 the Arduino core contains updated bootloader images that have
|
||||
# innacurate default headers. This results in bootloops if firmware is flashed via
|
||||
# OpenOCD (e.g. debugging or uploading via debug tools). For this reason, before
|
||||
# uploading or debugging we need to adjust the bootloader binary according to
|
||||
# the values of the --flash-size and --flash-mode arguments.
|
||||
# Note: This behavior doesn't occur if uploading is done via esptoolpy, as esptoolpy
|
||||
# overrides the binary image headers before flashing.
|
||||
|
||||
bootloader_patch_required = bool(
|
||||
env.get("PIOFRAMEWORK", []) == ["arduino"]
|
||||
and (
|
||||
"debug" in env.GetBuildType()
|
||||
or env.subst("$UPLOAD_PROTOCOL") in board_config.get("debug.tools", {})
|
||||
or env.IsIntegrationDump()
|
||||
)
|
||||
)
|
||||
|
||||
bootloader_image_path = get_bootloader_image(variants_dir)
|
||||
bootloader_offset = "0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000"
|
||||
if bootloader_patch_required:
|
||||
bootloader_image_path = get_patched_bootloader_image(
|
||||
bootloader_image_path, bootloader_offset
|
||||
)
|
||||
|
||||
env.Append(
|
||||
LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")],
|
||||
FLASH_EXTRA_IMAGES=[
|
||||
(bootloader_offset, bootloader_image_path),
|
||||
("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")),
|
||||
("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")),
|
||||
]
|
||||
+ [
|
||||
(offset, join(FRAMEWORK_DIR, img))
|
||||
for offset, img in board_config.get("upload.arduino.flash_extra_images", [])
|
||||
],
|
||||
)
|
||||
|
||||
# Add an extra UF2 image if the 'TinyUF2' partition is selected
|
||||
if partitions_name.endswith("tinyuf2.csv") or board_config.get(
|
||||
"upload.arduino.tinyuf2_image", ""
|
||||
):
|
||||
add_tinyuf2_extra_image()
|
||||
|
||||
#
|
||||
# Generate partition table
|
||||
#
|
||||
|
||||
env.Replace(PARTITIONS_TABLE_CSV=get_partition_table_csv(variants_dir))
|
||||
|
||||
partition_table = env.Command(
|
||||
join("$BUILD_DIR", "partitions.bin"),
|
||||
"$PARTITIONS_TABLE_CSV",
|
||||
env.VerboseAction(
|
||||
'"$PYTHONEXE" "%s" -q $SOURCE $TARGET'
|
||||
% join(FRAMEWORK_DIR, "tools", "gen_esp32part.py"),
|
||||
"Generating partitions $TARGET",
|
||||
),
|
||||
)
|
||||
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table)
|
BIN
tools/sdk/esp32/bin/bootloader_dio_40m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_dio_40m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dio_40m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_dio_40m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dio_80m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_dio_80m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dio_80m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_dio_80m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dout_40m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_dout_40m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dout_40m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_dout_40m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dout_80m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_dout_80m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_dout_80m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_dout_80m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qio_40m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_qio_40m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qio_40m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_qio_40m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qio_80m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_qio_80m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qio_80m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_qio_80m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qout_40m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_qout_40m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qout_40m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_qout_40m.elf
Executable file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qout_80m.bin
Normal file
BIN
tools/sdk/esp32/bin/bootloader_qout_80m.bin
Normal file
Binary file not shown.
BIN
tools/sdk/esp32/bin/bootloader_qout_80m.elf
Executable file
BIN
tools/sdk/esp32/bin/bootloader_qout_80m.elf
Executable file
Binary file not shown.
782
tools/sdk/esp32/dio_qspi/include/sdkconfig.h
Normal file
782
tools/sdk/esp32/dio_qspi/include/sdkconfig.h
Normal file
@ -0,0 +1,782 @@
|
||||
/*
|
||||
* Automatically generated file. DO NOT EDIT.
|
||||
* Espressif IoT Development Framework (ESP-IDF) Configuration Header
|
||||
*/
|
||||
#pragma once
|
||||
#define CONFIG_IDF_CMAKE 1
|
||||
#define CONFIG_IDF_TARGET_ARCH_XTENSA 1
|
||||
#define CONFIG_IDF_TARGET "esp32"
|
||||
#define CONFIG_IDF_TARGET_ESP32 1
|
||||
#define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000
|
||||
#define CONFIG_SDK_TOOLPREFIX "xtensa-esp32-elf-"
|
||||
#define CONFIG_APP_BUILD_TYPE_APP_2NDBOOT 1
|
||||
#define CONFIG_APP_BUILD_GENERATE_BINARIES 1
|
||||
#define CONFIG_APP_BUILD_BOOTLOADER 1
|
||||
#define CONFIG_APP_BUILD_USE_FLASH_SECTIONS 1
|
||||
#define CONFIG_APP_COMPILE_TIME_DATE 1
|
||||
#define CONFIG_APP_RETRIEVE_LEN_ELF_SHA 16
|
||||
#define CONFIG_BOOTLOADER_OFFSET_IN_FLASH 0x1000
|
||||
#define CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE 1
|
||||
#define CONFIG_BOOTLOADER_LOG_LEVEL_INFO 1
|
||||
#define CONFIG_BOOTLOADER_LOG_LEVEL 3
|
||||
#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1
|
||||
#define CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE 1
|
||||
#define CONFIG_BOOTLOADER_WDT_ENABLE 1
|
||||
#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000
|
||||
#define CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE 1
|
||||
#define CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP 1
|
||||
#define CONFIG_BOOTLOADER_RESERVE_RTC_SIZE 0x10
|
||||
#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
|
||||
#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200
|
||||
#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1
|
||||
#define CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHMODE "dio"
|
||||
#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHFREQ "80m"
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE "4MB"
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1
|
||||
#define CONFIG_ESPTOOLPY_BEFORE_RESET 1
|
||||
#define CONFIG_ESPTOOLPY_BEFORE "default_reset"
|
||||
#define CONFIG_ESPTOOLPY_AFTER_RESET 1
|
||||
#define CONFIG_ESPTOOLPY_AFTER "hard_reset"
|
||||
#define CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B 1
|
||||
#define CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL 115200
|
||||
#define CONFIG_ESPTOOLPY_MONITOR_BAUD 115200
|
||||
#define CONFIG_PARTITION_TABLE_SINGLE_APP 1
|
||||
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
|
||||
#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv"
|
||||
#define CONFIG_PARTITION_TABLE_OFFSET 0x8000
|
||||
#define CONFIG_PARTITION_TABLE_MD5 1
|
||||
#define CONFIG_LIB_BUILDER_FLASHMODE "dio"
|
||||
#define CONFIG_LIB_BUILDER_FLASHFREQ "80m"
|
||||
#define CONFIG_ESP_RMAKER_ASSISTED_CLAIM 1
|
||||
#define CONFIG_ESP_RMAKER_CLAIM_TYPE 2
|
||||
#define CONFIG_ESP_RMAKER_MQTT_HOST "a1p72mufdu6064-ats.iot.us-east-1.amazonaws.com"
|
||||
#define CONFIG_ESP_RMAKER_MAX_PARAM_DATA_SIZE 1024
|
||||
#define CONFIG_ESP_RMAKER_CONSOLE_UART_NUM_0 1
|
||||
#define CONFIG_ESP_RMAKER_CONSOLE_UART_NUM 0
|
||||
#define CONFIG_ESP_RMAKER_USE_CERT_BUNDLE 1
|
||||
#define CONFIG_ESP_RMAKER_OTA_AUTOFETCH 1
|
||||
#define CONFIG_ESP_RMAKER_OTA_AUTOFETCH_PERIOD 0
|
||||
#define CONFIG_ESP_RMAKER_SKIP_VERSION_CHECK 1
|
||||
#define CONFIG_ESP_RMAKER_OTA_HTTP_RX_BUFFER_SIZE 1024
|
||||
#define CONFIG_ESP_RMAKER_OTA_ROLLBACK_WAIT_PERIOD 90
|
||||
#define CONFIG_ESP_RMAKER_SCHEDULING_MAX_SCHEDULES 10
|
||||
#define CONFIG_ESP_RMAKER_SCENES_MAX_SCENES 10
|
||||
#define CONFIG_ESP_RMAKER_CMD_RESP_ENABLE 1
|
||||
#define CONFIG_ARDUINO_VARIANT "esp32"
|
||||
#define CONFIG_ENABLE_ARDUINO_DEPENDS 1
|
||||
#define CONFIG_AUTOSTART_ARDUINO 1
|
||||
#define CONFIG_ARDUINO_RUN_CORE1 1
|
||||
#define CONFIG_ARDUINO_RUNNING_CORE 1
|
||||
#define CONFIG_ARDUINO_LOOP_STACK_SIZE 8192
|
||||
#define CONFIG_ARDUINO_EVENT_RUN_CORE1 1
|
||||
#define CONFIG_ARDUINO_EVENT_RUNNING_CORE 1
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY 1
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_TASK_PRIORITY 24
|
||||
#define CONFIG_ARDUINO_UDP_RUN_CORE0 1
|
||||
#define CONFIG_ARDUINO_UDP_RUNNING_CORE 0
|
||||
#define CONFIG_ARDUINO_UDP_TASK_PRIORITY 3
|
||||
#define CONFIG_DISABLE_HAL_LOCKS 1
|
||||
#define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR 1
|
||||
#define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 1
|
||||
#define CONFIG_ARDUHAL_ESP_LOG 1
|
||||
#define CONFIG_ARDUHAL_PARTITION_SCHEME_DEFAULT 1
|
||||
#define CONFIG_ARDUHAL_PARTITION_SCHEME "default"
|
||||
#define CONFIG_USE_AFE 1
|
||||
#define CONFIG_AFE_INTERFACE_V1 1
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_SIZE 1
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE 1
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL 2
|
||||
#define CONFIG_COMPILER_HIDE_PATHS_MACROS 1
|
||||
#define CONFIG_COMPILER_CXX_EXCEPTIONS 1
|
||||
#define CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE 0
|
||||
#define CONFIG_COMPILER_STACK_CHECK_MODE_NORM 1
|
||||
#define CONFIG_COMPILER_STACK_CHECK 1
|
||||
#define CONFIG_COMPILER_WARN_WRITE_STRINGS 1
|
||||
#define CONFIG_APPTRACE_DEST_NONE 1
|
||||
#define CONFIG_APPTRACE_LOCK_ENABLE 1
|
||||
#define CONFIG_BT_ENABLED 1
|
||||
#define CONFIG_BTDM_CTRL_MODE_BTDM 1
|
||||
#define CONFIG_BTDM_CTRL_BLE_MAX_CONN 3
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN 2
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN 0
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_PCM 1
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_ROLE_EDGE_CONFIG 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_ROLE_MASTER 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_POLAR_FALLING_EDGE 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_ROLE_EFF 0
|
||||
#define CONFIG_BTDM_CTRL_PCM_POLAR_EFF 0
|
||||
#define CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT 1
|
||||
#define CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF 1
|
||||
#define CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF 3
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF 2
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF 0
|
||||
#define CONFIG_BTDM_CTRL_PINNED_TO_CORE_0 1
|
||||
#define CONFIG_BTDM_CTRL_PINNED_TO_CORE 0
|
||||
#define CONFIG_BTDM_CTRL_HCI_MODE_VHCI 1
|
||||
#define CONFIG_BTDM_CTRL_MODEM_SLEEP 1
|
||||
#define CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_ORIG 1
|
||||
#define CONFIG_BTDM_CTRL_LPCLK_SEL_MAIN_XTAL 1
|
||||
#define CONFIG_BTDM_BLE_DEFAULT_SCA_250PPM 1
|
||||
#define CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF 1
|
||||
#define CONFIG_BTDM_BLE_SCAN_DUPL 1
|
||||
#define CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE 1
|
||||
#define CONFIG_BTDM_SCAN_DUPL_TYPE 0
|
||||
#define CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE 20
|
||||
#define CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN 1
|
||||
#define CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE 100
|
||||
#define CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED 1
|
||||
#define CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP 1
|
||||
#define CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM 100
|
||||
#define CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD 20
|
||||
#define CONFIG_BTDM_RESERVE_DRAM 0xdb5c
|
||||
#define CONFIG_BTDM_CTRL_HLI 1
|
||||
#define CONFIG_BT_BLUEDROID_ENABLED 1
|
||||
#define CONFIG_BT_BTC_TASK_STACK_SIZE 8192
|
||||
#define CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0 1
|
||||
#define CONFIG_BT_BLUEDROID_PINNED_TO_CORE 0
|
||||
#define CONFIG_BT_BTU_TASK_STACK_SIZE 8192
|
||||
#define CONFIG_BT_CLASSIC_ENABLED 1
|
||||
#define CONFIG_BT_A2DP_ENABLE 1
|
||||
#define CONFIG_BT_SPP_ENABLED 1
|
||||
#define CONFIG_BT_HFP_ENABLE 1
|
||||
#define CONFIG_BT_HFP_CLIENT_ENABLE 1
|
||||
#define CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM 1
|
||||
#define CONFIG_BT_SSP_ENABLED 1
|
||||
#define CONFIG_BT_BLE_ENABLED 1
|
||||
#define CONFIG_BT_GATTS_ENABLE 1
|
||||
#define CONFIG_BT_GATT_MAX_SR_PROFILES 8
|
||||
#define CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO 1
|
||||
#define CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE 0
|
||||
#define CONFIG_BT_GATTC_ENABLE 1
|
||||
#define CONFIG_BT_GATTC_CONNECT_RETRY_COUNT 3
|
||||
#define CONFIG_BT_BLE_SMP_ENABLE 1
|
||||
#define CONFIG_BT_STACK_NO_LOG 1
|
||||
#define CONFIG_BT_ACL_CONNECTIONS 4
|
||||
#define CONFIG_BT_MULTI_CONNECTION_ENBALE 1
|
||||
#define CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY 1
|
||||
#define CONFIG_BT_SMP_ENABLE 1
|
||||
#define CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT 30
|
||||
#define CONFIG_BT_MAX_DEVICE_NAME_LEN 32
|
||||
#define CONFIG_BLE_MESH 1
|
||||
#define CONFIG_BLE_MESH_HCI_5_0 1
|
||||
#define CONFIG_BLE_MESH_USE_DUPLICATE_SCAN 1
|
||||
#define CONFIG_BLE_MESH_MEM_ALLOC_MODE_INTERNAL 1
|
||||
#define CONFIG_BLE_MESH_DEINIT 1
|
||||
#define CONFIG_BLE_MESH_PROV 1
|
||||
#define CONFIG_BLE_MESH_PB_ADV 1
|
||||
#define CONFIG_BLE_MESH_PROXY 1
|
||||
#define CONFIG_BLE_MESH_NET_BUF_POOL_USAGE 1
|
||||
#define CONFIG_BLE_MESH_SUBNET_COUNT 3
|
||||
#define CONFIG_BLE_MESH_APP_KEY_COUNT 3
|
||||
#define CONFIG_BLE_MESH_MODEL_KEY_COUNT 3
|
||||
#define CONFIG_BLE_MESH_MODEL_GROUP_COUNT 3
|
||||
#define CONFIG_BLE_MESH_LABEL_COUNT 3
|
||||
#define CONFIG_BLE_MESH_CRPL 10
|
||||
#define CONFIG_BLE_MESH_MSG_CACHE_SIZE 10
|
||||
#define CONFIG_BLE_MESH_ADV_BUF_COUNT 60
|
||||
#define CONFIG_BLE_MESH_IVU_DIVIDER 4
|
||||
#define CONFIG_BLE_MESH_TX_SEG_MSG_COUNT 1
|
||||
#define CONFIG_BLE_MESH_RX_SEG_MSG_COUNT 1
|
||||
#define CONFIG_BLE_MESH_RX_SDU_MAX 384
|
||||
#define CONFIG_BLE_MESH_TX_SEG_MAX 32
|
||||
#define CONFIG_BLE_MESH_TRACE_LEVEL_WARNING 1
|
||||
#define CONFIG_BLE_MESH_STACK_TRACE_LEVEL 2
|
||||
#define CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL_WARNING 1
|
||||
#define CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL 2
|
||||
#define CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT 4000
|
||||
#define CONFIG_BLE_MESH_HEALTH_SRV 1
|
||||
#define CONFIG_BLE_MESH_GENERIC_SERVER 1
|
||||
#define CONFIG_BLE_MESH_SENSOR_SERVER 1
|
||||
#define CONFIG_BLE_MESH_TIME_SCENE_SERVER 1
|
||||
#define CONFIG_BLE_MESH_LIGHTING_SERVER 1
|
||||
#define CONFIG_BLE_MESH_DISCARD_OLD_SEQ_AUTH 1
|
||||
#define CONFIG_COAP_MBEDTLS_PSK 1
|
||||
#define CONFIG_COAP_LOG_DEFAULT_LEVEL 0
|
||||
#define CONFIG_ADC_DISABLE_DAC 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT 1
|
||||
#define CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4 1
|
||||
#define CONFIG_EFUSE_MAX_BLK_LEN 192
|
||||
#define CONFIG_ESP_TLS_USING_MBEDTLS 1
|
||||
#define CONFIG_ESP_TLS_SERVER 1
|
||||
#define CONFIG_ESP32_ECO3_CACHE_LOCK_FIX 1
|
||||
#define CONFIG_ESP32_REV_MIN_0 1
|
||||
#define CONFIG_ESP32_REV_MIN 0
|
||||
#define CONFIG_ESP32_DPORT_WORKAROUND 1
|
||||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1
|
||||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160
|
||||
#define CONFIG_ESP32_SPIRAM_SUPPORT 1
|
||||
#define CONFIG_SPIRAM_TYPE_AUTO 1
|
||||
#define CONFIG_SPIRAM_SIZE -1
|
||||
#define CONFIG_SPIRAM_SPEED_80M 1
|
||||
#define CONFIG_SPIRAM 1
|
||||
#define CONFIG_SPIRAM_USE_MALLOC 1
|
||||
#define CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL 4096
|
||||
#define CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL 0
|
||||
#define CONFIG_SPIRAM_CACHE_WORKAROUND 1
|
||||
#define CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBJMP_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBMATH_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBNUMPARSER_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBIO_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBTIME_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBCHAR_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBMEM_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBSTR_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBRAND_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBENV_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBFILE_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBMISC_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_BANKSWITCH_ENABLE 1
|
||||
#define CONFIG_SPIRAM_BANKSWITCH_RESERVE 8
|
||||
#define CONFIG_SPIRAM_OCCUPY_HSPI_HOST 1
|
||||
#define CONFIG_D0WD_PSRAM_CLK_IO 17
|
||||
#define CONFIG_D0WD_PSRAM_CS_IO 16
|
||||
#define CONFIG_D2WD_PSRAM_CLK_IO 9
|
||||
#define CONFIG_D2WD_PSRAM_CS_IO 10
|
||||
#define CONFIG_PICO_PSRAM_CS_IO 10
|
||||
#define CONFIG_SPIRAM_SPIWP_SD3_PIN 7
|
||||
#define CONFIG_ESP32_TRACEMEM_RESERVE_DRAM 0x0
|
||||
#define CONFIG_ESP32_ULP_COPROC_ENABLED 1
|
||||
#define CONFIG_ESP32_ULP_COPROC_RESERVE_MEM 512
|
||||
#define CONFIG_ESP32_DEBUG_OCDAWARE 1
|
||||
#define CONFIG_ESP32_BROWNOUT_DET 1
|
||||
#define CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0 1
|
||||
#define CONFIG_ESP32_BROWNOUT_DET_LVL 0
|
||||
#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1
|
||||
#define CONFIG_ESP32_RTC_CLK_SRC_INT_RC 1
|
||||
#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024
|
||||
#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000
|
||||
#define CONFIG_ESP32_XTAL_FREQ_AUTO 1
|
||||
#define CONFIG_ESP32_XTAL_FREQ 0
|
||||
#define CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL 5
|
||||
#define CONFIG_ADC_CAL_EFUSE_TP_ENABLE 1
|
||||
#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1
|
||||
#define CONFIG_ADC_CAL_LUT_ENABLE 1
|
||||
#define CONFIG_ESP_ERR_TO_NAME_LOOKUP 1
|
||||
#define CONFIG_ETH_ENABLED 1
|
||||
#define CONFIG_ETH_USE_ESP32_EMAC 1
|
||||
#define CONFIG_ETH_PHY_INTERFACE_RMII 1
|
||||
#define CONFIG_ETH_RMII_CLK_INPUT 1
|
||||
#define CONFIG_ETH_RMII_CLK_IN_GPIO 0
|
||||
#define CONFIG_ETH_DMA_BUFFER_SIZE 512
|
||||
#define CONFIG_ETH_DMA_RX_BUFFER_NUM 10
|
||||
#define CONFIG_ETH_DMA_TX_BUFFER_NUM 10
|
||||
#define CONFIG_ETH_USE_SPI_ETHERNET 1
|
||||
#define CONFIG_ETH_SPI_ETHERNET_DM9051 1
|
||||
#define CONFIG_ETH_SPI_ETHERNET_W5500 1
|
||||
#define CONFIG_ESP_EVENT_POST_FROM_ISR 1
|
||||
#define CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR 1
|
||||
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1
|
||||
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH 1
|
||||
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH 1
|
||||
#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 1024
|
||||
#define CONFIG_HTTPD_MAX_URI_LEN 512
|
||||
#define CONFIG_HTTPD_ERR_RESP_NO_DELAY 1
|
||||
#define CONFIG_HTTPD_PURGE_BUF_LEN 32
|
||||
#define CONFIG_HTTPD_WS_SUPPORT 1
|
||||
#define CONFIG_ESP_HTTPS_SERVER_ENABLE 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_BT 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH 1
|
||||
#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR 1
|
||||
#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES 4
|
||||
#define CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND 1
|
||||
#define CONFIG_ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND 1
|
||||
#define CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND 1
|
||||
#define CONFIG_ESP_IPC_TASK_STACK_SIZE 1024
|
||||
#define CONFIG_ESP_IPC_USES_CALLERS_PRIORITY 1
|
||||
#define CONFIG_ESP_IPC_ISR_ENABLE 1
|
||||
#define CONFIG_LCD_PANEL_IO_FORMAT_BUF_SIZE 32
|
||||
#define CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL 120
|
||||
#define CONFIG_ESP_NETIF_TCPIP_LWIP 1
|
||||
#define CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER 1
|
||||
#define CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE 1
|
||||
#define CONFIG_ESP_PHY_MAX_WIFI_TX_POWER 20
|
||||
#define CONFIG_ESP_PHY_MAX_TX_POWER 20
|
||||
#define CONFIG_ESP_PHY_REDUCE_TX_POWER 1
|
||||
#define CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT 1
|
||||
#define CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE 32
|
||||
#define CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_ESP_MAIN_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_ESP_MAIN_TASK_AFFINITY 0x0
|
||||
#define CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE 2048
|
||||
#define CONFIG_ESP_CONSOLE_UART_DEFAULT 1
|
||||
#define CONFIG_ESP_CONSOLE_UART 1
|
||||
#define CONFIG_ESP_CONSOLE_MULTIPLE_UART 1
|
||||
#define CONFIG_ESP_CONSOLE_UART_NUM 0
|
||||
#define CONFIG_ESP_CONSOLE_UART_BAUDRATE 115200
|
||||
#define CONFIG_ESP_INT_WDT 1
|
||||
#define CONFIG_ESP_INT_WDT_TIMEOUT_MS 300
|
||||
#define CONFIG_ESP_INT_WDT_CHECK_CPU1 1
|
||||
#define CONFIG_ESP_TASK_WDT 1
|
||||
#define CONFIG_ESP_TASK_WDT_PANIC 1
|
||||
#define CONFIG_ESP_TASK_WDT_TIMEOUT_S 5
|
||||
#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 1
|
||||
#define CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5 1
|
||||
#define CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER 1
|
||||
#define CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER 1
|
||||
#define CONFIG_ESP_TIMER_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_ESP_TIMER_INTERRUPT_LEVEL 1
|
||||
#define CONFIG_ESP_TIMER_IMPL_TG0_LAC 1
|
||||
#define CONFIG_ESP32_WIFI_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE 1
|
||||
#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 8
|
||||
#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 32
|
||||
#define CONFIG_ESP32_WIFI_STATIC_TX_BUFFER 1
|
||||
#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 0
|
||||
#define CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM 8
|
||||
#define CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM 16
|
||||
#define CONFIG_ESP32_WIFI_CSI_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_TX_BA_WIN 6
|
||||
#define CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_RX_BA_WIN 6
|
||||
#define CONFIG_ESP32_WIFI_NVS_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1
|
||||
#define CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN 752
|
||||
#define CONFIG_ESP32_WIFI_MGMT_SBUF_NUM 32
|
||||
#define CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE 1
|
||||
#define CONFIG_ESP_WIFI_SOFTAP_SUPPORT 1
|
||||
#define CONFIG_ESP_COREDUMP_ENABLE_TO_NONE 1
|
||||
#define CONFIG_FATFS_CODEPAGE_850 1
|
||||
#define CONFIG_FATFS_CODEPAGE 850
|
||||
#define CONFIG_FATFS_LFN_STACK 1
|
||||
#define CONFIG_FATFS_MAX_LFN 255
|
||||
#define CONFIG_FATFS_API_ENCODING_ANSI_OEM 1
|
||||
#define CONFIG_FATFS_FS_LOCK 0
|
||||
#define CONFIG_FATFS_TIMEOUT_MS 10000
|
||||
#define CONFIG_FATFS_PER_FILE_CACHE 1
|
||||
#define CONFIG_FATFS_ALLOC_PREFER_EXTRAM 1
|
||||
#define CONFIG_FMB_COMM_MODE_TCP_EN 1
|
||||
#define CONFIG_FMB_TCP_PORT_DEFAULT 502
|
||||
#define CONFIG_FMB_TCP_PORT_MAX_CONN 5
|
||||
#define CONFIG_FMB_TCP_CONNECTION_TOUT_SEC 20
|
||||
#define CONFIG_FMB_COMM_MODE_RTU_EN 1
|
||||
#define CONFIG_FMB_COMM_MODE_ASCII_EN 1
|
||||
#define CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND 150
|
||||
#define CONFIG_FMB_MASTER_DELAY_MS_CONVERT 200
|
||||
#define CONFIG_FMB_QUEUE_LENGTH 20
|
||||
#define CONFIG_FMB_PORT_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_FMB_SERIAL_BUF_SIZE 256
|
||||
#define CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB 8
|
||||
#define CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS 1000
|
||||
#define CONFIG_FMB_PORT_TASK_PRIO 10
|
||||
#define CONFIG_FMB_PORT_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_FMB_PORT_TASK_AFFINITY 0x0
|
||||
#define CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT 20
|
||||
#define CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE 20
|
||||
#define CONFIG_FMB_CONTROLLER_STACK_SIZE 4096
|
||||
#define CONFIG_FMB_EVENT_QUEUE_TIMEOUT 20
|
||||
#define CONFIG_FMB_TIMER_PORT_ENABLED 1
|
||||
#define CONFIG_FMB_TIMER_GROUP 0
|
||||
#define CONFIG_FMB_TIMER_INDEX 0
|
||||
#define CONFIG_FMB_MASTER_TIMER_GROUP 0
|
||||
#define CONFIG_FMB_MASTER_TIMER_INDEX 0
|
||||
#define CONFIG_FREERTOS_NO_AFFINITY 0x7FFFFFFF
|
||||
#define CONFIG_FREERTOS_TICK_SUPPORT_CORETIMER 1
|
||||
#define CONFIG_FREERTOS_CORETIMER_0 1
|
||||
#define CONFIG_FREERTOS_SYSTICK_USES_CCOUNT 1
|
||||
#define CONFIG_FREERTOS_HZ 1000
|
||||
#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1
|
||||
#define CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK 1
|
||||
#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1
|
||||
#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1
|
||||
#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1
|
||||
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024
|
||||
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
|
||||
#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16
|
||||
#define CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION 1
|
||||
#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1
|
||||
#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 2048
|
||||
#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10
|
||||
#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0
|
||||
#define CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER 1
|
||||
#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1
|
||||
#define CONFIG_FREERTOS_FPU_IN_ISR 1
|
||||
#define CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT 1
|
||||
#define CONFIG_HAL_ASSERTION_EQUALS_SYSTEM 1
|
||||
#define CONFIG_HAL_DEFAULT_ASSERTION_LEVEL 2
|
||||
#define CONFIG_HEAP_POISONING_LIGHT 1
|
||||
#define CONFIG_HEAP_TRACING_OFF 1
|
||||
#define CONFIG_LOG_DEFAULT_LEVEL_ERROR 1
|
||||
#define CONFIG_LOG_DEFAULT_LEVEL 1
|
||||
#define CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT 1
|
||||
#define CONFIG_LOG_MAXIMUM_LEVEL 1
|
||||
#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1
|
||||
#define CONFIG_LWIP_LOCAL_HOSTNAME "espressif"
|
||||
#define CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES 1
|
||||
#define CONFIG_LWIP_TIMERS_ONDEMAND 1
|
||||
#define CONFIG_LWIP_MAX_SOCKETS 16
|
||||
#define CONFIG_LWIP_SO_REUSE 1
|
||||
#define CONFIG_LWIP_SO_REUSE_RXTOALL 1
|
||||
#define CONFIG_LWIP_SO_RCVBUF 1
|
||||
#define CONFIG_LWIP_IP4_FRAG 1
|
||||
#define CONFIG_LWIP_IP6_FRAG 1
|
||||
#define CONFIG_LWIP_ETHARP_TRUST_IP_MAC 1
|
||||
#define CONFIG_LWIP_ESP_GRATUITOUS_ARP 1
|
||||
#define CONFIG_LWIP_GARP_TMR_INTERVAL 60
|
||||
#define CONFIG_LWIP_TCPIP_RECVMBOX_SIZE 32
|
||||
#define CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID 1
|
||||
#define CONFIG_LWIP_DHCP_RESTORE_LAST_IP 1
|
||||
#define CONFIG_LWIP_DHCP_OPTIONS_LEN 128
|
||||
#define CONFIG_LWIP_DHCPS 1
|
||||
#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60
|
||||
#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8
|
||||
#define CONFIG_LWIP_IPV6 1
|
||||
#define CONFIG_LWIP_IPV6_AUTOCONFIG 1
|
||||
#define CONFIG_LWIP_IPV6_NUM_ADDRESSES 3
|
||||
#define CONFIG_LWIP_IPV6_RDNSS_MAX_DNS_SERVERS 0
|
||||
#define CONFIG_LWIP_NETIF_LOOPBACK 1
|
||||
#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8
|
||||
#define CONFIG_LWIP_MAX_ACTIVE_TCP 16
|
||||
#define CONFIG_LWIP_MAX_LISTENING_TCP 16
|
||||
#define CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION 1
|
||||
#define CONFIG_LWIP_TCP_MAXRTX 12
|
||||
#define CONFIG_LWIP_TCP_SYNMAXRTX 6
|
||||
#define CONFIG_LWIP_TCP_MSS 1436
|
||||
#define CONFIG_LWIP_TCP_TMR_INTERVAL 250
|
||||
#define CONFIG_LWIP_TCP_MSL 60000
|
||||
#define CONFIG_LWIP_TCP_SND_BUF_DEFAULT 5744
|
||||
#define CONFIG_LWIP_TCP_WND_DEFAULT 5744
|
||||
#define CONFIG_LWIP_TCP_RECVMBOX_SIZE 6
|
||||
#define CONFIG_LWIP_TCP_QUEUE_OOSEQ 1
|
||||
#define CONFIG_LWIP_TCP_OVERSIZE_MSS 1
|
||||
#define CONFIG_LWIP_TCP_RTO_TIME 3000
|
||||
#define CONFIG_LWIP_MAX_UDP_PCBS 16
|
||||
#define CONFIG_LWIP_UDP_RECVMBOX_SIZE 6
|
||||
#define CONFIG_LWIP_CHECKSUM_CHECK_ICMP 1
|
||||
#define CONFIG_LWIP_TCPIP_TASK_STACK_SIZE 2560
|
||||
#define CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_LWIP_TCPIP_TASK_AFFINITY 0x0
|
||||
#define CONFIG_LWIP_PPP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_ENABLE_IPV6 1
|
||||
#define CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE 3
|
||||
#define CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS 5
|
||||
#define CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_PAP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_CHAP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_MSCHAP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_MPPE_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_DEBUG_ON 1
|
||||
#define CONFIG_LWIP_ICMP 1
|
||||
#define CONFIG_LWIP_MAX_RAW_PCBS 16
|
||||
#define CONFIG_LWIP_SNTP_MAX_SERVERS 3
|
||||
#define CONFIG_LWIP_DHCP_GET_NTP_SRV 1
|
||||
#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1
|
||||
#define CONFIG_LWIP_SNTP_UPDATE_DELAY 10800000
|
||||
#define CONFIG_LWIP_ESP_LWIP_ASSERT 1
|
||||
#define CONFIG_LWIP_HOOK_TCP_ISN_DEFAULT 1
|
||||
#define CONFIG_LWIP_HOOK_IP6_ROUTE_NONE 1
|
||||
#define CONFIG_LWIP_HOOK_ND6_GET_GW_NONE 1
|
||||
#define CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE 1
|
||||
#define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1
|
||||
#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384
|
||||
#define CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE 1
|
||||
#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE 1
|
||||
#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL 1
|
||||
#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS 200
|
||||
#define CONFIG_MBEDTLS_HARDWARE_AES 1
|
||||
#define CONFIG_MBEDTLS_HARDWARE_MPI 1
|
||||
#define CONFIG_MBEDTLS_HARDWARE_SHA 1
|
||||
#define CONFIG_MBEDTLS_ROM_MD5 1
|
||||
#define CONFIG_MBEDTLS_HAVE_TIME 1
|
||||
#define CONFIG_MBEDTLS_ECDSA_DETERMINISTIC 1
|
||||
#define CONFIG_MBEDTLS_SHA512_C 1
|
||||
#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
|
||||
#define CONFIG_MBEDTLS_TLS_SERVER 1
|
||||
#define CONFIG_MBEDTLS_TLS_CLIENT 1
|
||||
#define CONFIG_MBEDTLS_TLS_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_PSK_MODES 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1
|
||||
#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_DTLS 1
|
||||
#define CONFIG_MBEDTLS_SSL_ALPN 1
|
||||
#define CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS 1
|
||||
#define CONFIG_MBEDTLS_X509_CHECK_KEY_USAGE 1
|
||||
#define CONFIG_MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 1
|
||||
#define CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS 1
|
||||
#define CONFIG_MBEDTLS_AES_C 1
|
||||
#define CONFIG_MBEDTLS_CAMELLIA_C 1
|
||||
#define CONFIG_MBEDTLS_RC4_DISABLED 1
|
||||
#define CONFIG_MBEDTLS_CCM_C 1
|
||||
#define CONFIG_MBEDTLS_GCM_C 1
|
||||
#define CONFIG_MBEDTLS_PEM_PARSE_C 1
|
||||
#define CONFIG_MBEDTLS_PEM_WRITE_C 1
|
||||
#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1
|
||||
#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1
|
||||
#define CONFIG_MBEDTLS_ECP_C 1
|
||||
#define CONFIG_MBEDTLS_ECDH_C 1
|
||||
#define CONFIG_MBEDTLS_ECDSA_C 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1
|
||||
#define CONFIG_MDNS_MAX_SERVICES 10
|
||||
#define CONFIG_MDNS_TASK_PRIORITY 1
|
||||
#define CONFIG_MDNS_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_MDNS_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_MDNS_TASK_AFFINITY 0x0
|
||||
#define CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS 2000
|
||||
#define CONFIG_MDNS_TIMER_PERIOD_MS 100
|
||||
#define CONFIG_MDNS_MULTIPLE_INSTANCE 1
|
||||
#define CONFIG_MQTT_PROTOCOL_311 1
|
||||
#define CONFIG_MQTT_TRANSPORT_SSL 1
|
||||
#define CONFIG_MQTT_TRANSPORT_WEBSOCKET 1
|
||||
#define CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE 1
|
||||
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
|
||||
#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1
|
||||
#define CONFIG_OPENSSL_ERROR_STACK 1
|
||||
#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1
|
||||
#define CONFIG_PTHREAD_TASK_PRIO_DEFAULT 5
|
||||
#define CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT 2048
|
||||
#define CONFIG_PTHREAD_STACK_MIN 768
|
||||
#define CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY 1
|
||||
#define CONFIG_PTHREAD_TASK_CORE_DEFAULT -1
|
||||
#define CONFIG_PTHREAD_TASK_NAME_DEFAULT "pthread"
|
||||
#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
|
||||
#define CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS 1
|
||||
#define CONFIG_SPI_FLASH_YIELD_DURING_ERASE 1
|
||||
#define CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS 10
|
||||
#define CONFIG_SPI_FLASH_ERASE_YIELD_TICKS 2
|
||||
#define CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE 4096
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_GD_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE 1
|
||||
#define CONFIG_SPIFFS_MAX_PARTITIONS 3
|
||||
#define CONFIG_SPIFFS_CACHE 1
|
||||
#define CONFIG_SPIFFS_CACHE_WR 1
|
||||
#define CONFIG_SPIFFS_PAGE_CHECK 1
|
||||
#define CONFIG_SPIFFS_GC_MAX_RUNS 10
|
||||
#define CONFIG_SPIFFS_PAGE_SIZE 256
|
||||
#define CONFIG_SPIFFS_OBJ_NAME_LEN 32
|
||||
#define CONFIG_SPIFFS_USE_MAGIC 1
|
||||
#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1
|
||||
#define CONFIG_SPIFFS_META_LENGTH 4
|
||||
#define CONFIG_SPIFFS_USE_MTIME 1
|
||||
#define CONFIG_WS_TRANSPORT 1
|
||||
#define CONFIG_WS_BUFFER_SIZE 1024
|
||||
#define CONFIG_UNITY_ENABLE_FLOAT 1
|
||||
#define CONFIG_UNITY_ENABLE_DOUBLE 1
|
||||
#define CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER 1
|
||||
#define CONFIG_VFS_SUPPORT_IO 1
|
||||
#define CONFIG_VFS_SUPPORT_DIR 1
|
||||
#define CONFIG_VFS_SUPPORT_SELECT 1
|
||||
#define CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT 1
|
||||
#define CONFIG_VFS_SUPPORT_TERMIOS 1
|
||||
#define CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS 1
|
||||
#define CONFIG_WL_SECTOR_SIZE_4096 1
|
||||
#define CONFIG_WL_SECTOR_SIZE 4096
|
||||
#define CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES 16
|
||||
#define CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT 30
|
||||
#define CONFIG_WIFI_PROV_BLE_BONDING 1
|
||||
#define CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION 1
|
||||
#define CONFIG_WPA_MBEDTLS_CRYPTO 1
|
||||
#define CONFIG_IO_GLITCH_FILTER_TIME_MS 50
|
||||
#define CONFIG_ESP_RMAKER_LIB_ESP_MQTT 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_GLUE_LIB 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PORT_443 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PORT 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_SEND_USERNAME 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PRODUCT_NAME "RMDev"
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PRODUCT_VERSION "1x0"
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PRODUCT_SKU "EX00"
|
||||
#define CONFIG_ESP_RMAKER_MQTT_USE_CERT_BUNDLE 1
|
||||
#define CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK 4096
|
||||
#define CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_PRIORITY 5
|
||||
#define CONFIG_ESP_RMAKER_FACTORY_PARTITION_NAME "fctry"
|
||||
#define CONFIG_ESP_RMAKER_FACTORY_NAMESPACE "rmaker_creds"
|
||||
#define CONFIG_ESP_RMAKER_DEF_TIMEZONE "Asia/Shanghai"
|
||||
#define CONFIG_ESP_RMAKER_SNTP_SERVER_NAME "pool.ntp.org"
|
||||
#define CONFIG_ESP_RMAKER_MAX_COMMANDS 10
|
||||
#define CONFIG_DSP_OPTIMIZATIONS_SUPPORTED 1
|
||||
#define CONFIG_DSP_OPTIMIZED 1
|
||||
#define CONFIG_DSP_OPTIMIZATION 1
|
||||
#define CONFIG_DSP_MAX_FFT_SIZE_4096 1
|
||||
#define CONFIG_DSP_MAX_FFT_SIZE 4096
|
||||
#define CONFIG_OV7670_SUPPORT 1
|
||||
#define CONFIG_OV7725_SUPPORT 1
|
||||
#define CONFIG_NT99141_SUPPORT 1
|
||||
#define CONFIG_OV2640_SUPPORT 1
|
||||
#define CONFIG_OV3660_SUPPORT 1
|
||||
#define CONFIG_OV5640_SUPPORT 1
|
||||
#define CONFIG_GC2145_SUPPORT 1
|
||||
#define CONFIG_GC032A_SUPPORT 1
|
||||
#define CONFIG_GC0308_SUPPORT 1
|
||||
#define CONFIG_BF3005_SUPPORT 1
|
||||
#define CONFIG_BF20A6_SUPPORT 1
|
||||
#define CONFIG_SC030IOT_SUPPORT 1
|
||||
#define CONFIG_SCCB_HARDWARE_I2C_PORT1 1
|
||||
#define CONFIG_SCCB_CLK_FREQ 100000
|
||||
#define CONFIG_GC_SENSOR_SUBSAMPLE_MODE 1
|
||||
#define CONFIG_CAMERA_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_CAMERA_CORE0 1
|
||||
#define CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX 32768
|
||||
#define CONFIG_LITTLEFS_MAX_PARTITIONS 3
|
||||
#define CONFIG_LITTLEFS_PAGE_SIZE 256
|
||||
#define CONFIG_LITTLEFS_OBJ_NAME_LEN 64
|
||||
#define CONFIG_LITTLEFS_READ_SIZE 128
|
||||
#define CONFIG_LITTLEFS_WRITE_SIZE 128
|
||||
#define CONFIG_LITTLEFS_LOOKAHEAD_SIZE 128
|
||||
#define CONFIG_LITTLEFS_CACHE_SIZE 512
|
||||
#define CONFIG_LITTLEFS_BLOCK_CYCLES 512
|
||||
#define CONFIG_LITTLEFS_USE_MTIME 1
|
||||
#define CONFIG_LITTLEFS_MTIME_USE_SECONDS 1
|
||||
|
||||
/* List of deprecated options */
|
||||
#define CONFIG_A2DP_ENABLE CONFIG_BT_A2DP_ENABLE
|
||||
#define CONFIG_ADC2_DISABLE_DAC CONFIG_ADC_DISABLE_DAC
|
||||
#define CONFIG_APP_ROLLBACK_ENABLE CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
#define CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD
|
||||
#define CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM
|
||||
#define CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
|
||||
#define CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT
|
||||
#define CONFIG_BLE_MESH_SCAN_DUPLICATE_EN CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN
|
||||
#define CONFIG_BLE_SCAN_DUPLICATE CONFIG_BTDM_BLE_SCAN_DUPL
|
||||
#define CONFIG_BLE_SMP_ENABLE CONFIG_BT_BLE_SMP_ENABLE
|
||||
#define CONFIG_BLUEDROID_ENABLED CONFIG_BT_BLUEDROID_ENABLED
|
||||
#define CONFIG_BLUEDROID_PINNED_TO_CORE_0 CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0
|
||||
#define CONFIG_BROWNOUT_DET CONFIG_ESP32_BROWNOUT_DET
|
||||
#define CONFIG_BROWNOUT_DET_LVL_SEL_0 CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0
|
||||
#define CONFIG_BTC_TASK_STACK_SIZE CONFIG_BT_BTC_TASK_STACK_SIZE
|
||||
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN CONFIG_BTDM_CTRL_BLE_MAX_CONN
|
||||
#define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN
|
||||
#define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN
|
||||
#define CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED
|
||||
#define CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI CONFIG_BTDM_CTRL_HCI_MODE_VHCI
|
||||
#define CONFIG_BTDM_CONTROLLER_MODEM_SLEEP CONFIG_BTDM_CTRL_MODEM_SLEEP
|
||||
#define CONFIG_BTDM_CONTROLLER_MODE_BTDM CONFIG_BTDM_CTRL_MODE_BTDM
|
||||
#define CONFIG_BTU_TASK_STACK_SIZE CONFIG_BT_BTU_TASK_STACK_SIZE
|
||||
#define CONFIG_CLASSIC_BT_ENABLED CONFIG_BT_CLASSIC_ENABLED
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE
|
||||
#define CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT
|
||||
#define CONFIG_CXX_EXCEPTIONS CONFIG_COMPILER_CXX_EXCEPTIONS
|
||||
#define CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE
|
||||
#define CONFIG_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE
|
||||
#define CONFIG_ESP32S2_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT
|
||||
#define CONFIG_ESP32_APPTRACE_DEST_NONE CONFIG_APPTRACE_DEST_NONE
|
||||
#define CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY
|
||||
#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE CONFIG_ESP_COREDUMP_ENABLE_TO_NONE
|
||||
#define CONFIG_ESP32_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT
|
||||
#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE
|
||||
#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER CONFIG_ESP_PHY_MAX_WIFI_TX_POWER
|
||||
#define CONFIG_ESP32_PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
|
||||
#define CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT CONFIG_PTHREAD_TASK_NAME_DEFAULT
|
||||
#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT CONFIG_PTHREAD_TASK_PRIO_DEFAULT
|
||||
#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT
|
||||
#define CONFIG_ESP32_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER
|
||||
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC CONFIG_ESP32_RTC_CLK_SRC_INT_RC
|
||||
#define CONFIG_ESP_GRATUITOUS_ARP CONFIG_LWIP_ESP_GRATUITOUS_ARP
|
||||
#define CONFIG_FLASHMODE_DIO CONFIG_ESPTOOLPY_FLASHMODE_DIO
|
||||
#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
|
||||
#define CONFIG_GARP_TMR_INTERVAL CONFIG_LWIP_GARP_TMR_INTERVAL
|
||||
#define CONFIG_GATTC_ENABLE CONFIG_BT_GATTC_ENABLE
|
||||
#define CONFIG_GATTS_ENABLE CONFIG_BT_GATTS_ENABLE
|
||||
#define CONFIG_GATTS_SEND_SERVICE_CHANGE_AUTO CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO
|
||||
#define CONFIG_HFP_AUDIO_DATA_PATH_PCM CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM
|
||||
#define CONFIG_HFP_CLIENT_ENABLE CONFIG_BT_HFP_CLIENT_ENABLE
|
||||
#define CONFIG_HFP_ENABLE CONFIG_BT_HFP_ENABLE
|
||||
#define CONFIG_INT_WDT CONFIG_ESP_INT_WDT
|
||||
#define CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1
|
||||
#define CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS
|
||||
#define CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_TASK_STACK_SIZE
|
||||
#define CONFIG_LOG_BOOTLOADER_LEVEL_INFO CONFIG_BOOTLOADER_LOG_LEVEL_INFO
|
||||
#define CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE
|
||||
#define CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE
|
||||
#define CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT
|
||||
#define CONFIG_MB_CONTROLLER_STACK_SIZE CONFIG_FMB_CONTROLLER_STACK_SIZE
|
||||
#define CONFIG_MB_EVENT_QUEUE_TIMEOUT CONFIG_FMB_EVENT_QUEUE_TIMEOUT
|
||||
#define CONFIG_MB_MASTER_DELAY_MS_CONVERT CONFIG_FMB_MASTER_DELAY_MS_CONVERT
|
||||
#define CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND
|
||||
#define CONFIG_MB_QUEUE_LENGTH CONFIG_FMB_QUEUE_LENGTH
|
||||
#define CONFIG_MB_SERIAL_BUF_SIZE CONFIG_FMB_SERIAL_BUF_SIZE
|
||||
#define CONFIG_MB_SERIAL_TASK_PRIO CONFIG_FMB_PORT_TASK_PRIO
|
||||
#define CONFIG_MB_SERIAL_TASK_STACK_SIZE CONFIG_FMB_PORT_TASK_STACK_SIZE
|
||||
#define CONFIG_MB_TIMER_GROUP CONFIG_FMB_TIMER_GROUP
|
||||
#define CONFIG_MB_TIMER_INDEX CONFIG_FMB_TIMER_INDEX
|
||||
#define CONFIG_MB_TIMER_PORT_ENABLED CONFIG_FMB_TIMER_PORT_ENABLED
|
||||
#define CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE
|
||||
#define CONFIG_MONITOR_BAUD_115200B CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B
|
||||
#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE
|
||||
#define CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE
|
||||
#define CONFIG_POST_EVENTS_FROM_IRAM_ISR CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR
|
||||
#define CONFIG_POST_EVENTS_FROM_ISR CONFIG_ESP_EVENT_POST_FROM_ISR
|
||||
#define CONFIG_PPP_CHAP_SUPPORT CONFIG_LWIP_PPP_CHAP_SUPPORT
|
||||
#define CONFIG_PPP_DEBUG_ON CONFIG_LWIP_PPP_DEBUG_ON
|
||||
#define CONFIG_PPP_MPPE_SUPPORT CONFIG_LWIP_PPP_MPPE_SUPPORT
|
||||
#define CONFIG_PPP_MSCHAP_SUPPORT CONFIG_LWIP_PPP_MSCHAP_SUPPORT
|
||||
#define CONFIG_PPP_NOTIFY_PHASE_SUPPORT CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT
|
||||
#define CONFIG_PPP_PAP_SUPPORT CONFIG_LWIP_PPP_PAP_SUPPORT
|
||||
#define CONFIG_PPP_SUPPORT CONFIG_LWIP_PPP_SUPPORT
|
||||
#define CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER
|
||||
#define CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE
|
||||
#define CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS
|
||||
#define CONFIG_SPIRAM_SUPPORT CONFIG_ESP32_SPIRAM_SUPPORT
|
||||
#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS
|
||||
#define CONFIG_STACK_CHECK_NORM CONFIG_COMPILER_STACK_CHECK_MODE_NORM
|
||||
#define CONFIG_SUPPORT_TERMIOS CONFIG_VFS_SUPPORT_TERMIOS
|
||||
#define CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT
|
||||
#define CONFIG_SW_COEXIST_ENABLE CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE
|
||||
#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE
|
||||
#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE
|
||||
#define CONFIG_TASK_WDT CONFIG_ESP_TASK_WDT
|
||||
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
|
||||
#define CONFIG_TASK_WDT_PANIC CONFIG_ESP_TASK_WDT_PANIC
|
||||
#define CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIMEOUT_S
|
||||
#define CONFIG_TCPIP_RECVMBOX_SIZE CONFIG_LWIP_TCPIP_RECVMBOX_SIZE
|
||||
#define CONFIG_TCPIP_TASK_AFFINITY_CPU0 CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0
|
||||
#define CONFIG_TCPIP_TASK_STACK_SIZE CONFIG_LWIP_TCPIP_TASK_STACK_SIZE
|
||||
#define CONFIG_TCP_MAXRTX CONFIG_LWIP_TCP_MAXRTX
|
||||
#define CONFIG_TCP_MSL CONFIG_LWIP_TCP_MSL
|
||||
#define CONFIG_TCP_MSS CONFIG_LWIP_TCP_MSS
|
||||
#define CONFIG_TCP_OVERSIZE_MSS CONFIG_LWIP_TCP_OVERSIZE_MSS
|
||||
#define CONFIG_TCP_QUEUE_OOSEQ CONFIG_LWIP_TCP_QUEUE_OOSEQ
|
||||
#define CONFIG_TCP_RECVMBOX_SIZE CONFIG_LWIP_TCP_RECVMBOX_SIZE
|
||||
#define CONFIG_TCP_SND_BUF_DEFAULT CONFIG_LWIP_TCP_SND_BUF_DEFAULT
|
||||
#define CONFIG_TCP_SYNMAXRTX CONFIG_LWIP_TCP_SYNMAXRTX
|
||||
#define CONFIG_TCP_WND_DEFAULT CONFIG_LWIP_TCP_WND_DEFAULT
|
||||
#define CONFIG_TIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH
|
||||
#define CONFIG_TIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY
|
||||
#define CONFIG_TIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH
|
||||
#define CONFIG_TIMER_TASK_STACK_SIZE CONFIG_ESP_TIMER_TASK_STACK_SIZE
|
||||
#define CONFIG_TOOLPREFIX CONFIG_SDK_TOOLPREFIX
|
||||
#define CONFIG_UDP_RECVMBOX_SIZE CONFIG_LWIP_UDP_RECVMBOX_SIZE
|
||||
#define CONFIG_ULP_COPROC_ENABLED CONFIG_ESP32_ULP_COPROC_ENABLED
|
||||
#define CONFIG_ULP_COPROC_RESERVE_MEM CONFIG_ESP32_ULP_COPROC_RESERVE_MEM
|
||||
#define CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS
|
||||
#define CONFIG_ARDUINO_IDF_COMMIT ""
|
||||
#define CONFIG_ARDUINO_IDF_BRANCH "release/v4.4"
|
BIN
tools/sdk/esp32/dio_qspi/libspi_flash.a
Normal file
BIN
tools/sdk/esp32/dio_qspi/libspi_flash.a
Normal file
Binary file not shown.
782
tools/sdk/esp32/dout_qspi/include/sdkconfig.h
Normal file
782
tools/sdk/esp32/dout_qspi/include/sdkconfig.h
Normal file
@ -0,0 +1,782 @@
|
||||
/*
|
||||
* Automatically generated file. DO NOT EDIT.
|
||||
* Espressif IoT Development Framework (ESP-IDF) Configuration Header
|
||||
*/
|
||||
#pragma once
|
||||
#define CONFIG_IDF_CMAKE 1
|
||||
#define CONFIG_IDF_TARGET_ARCH_XTENSA 1
|
||||
#define CONFIG_IDF_TARGET "esp32"
|
||||
#define CONFIG_IDF_TARGET_ESP32 1
|
||||
#define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000
|
||||
#define CONFIG_SDK_TOOLPREFIX "xtensa-esp32-elf-"
|
||||
#define CONFIG_APP_BUILD_TYPE_APP_2NDBOOT 1
|
||||
#define CONFIG_APP_BUILD_GENERATE_BINARIES 1
|
||||
#define CONFIG_APP_BUILD_BOOTLOADER 1
|
||||
#define CONFIG_APP_BUILD_USE_FLASH_SECTIONS 1
|
||||
#define CONFIG_APP_COMPILE_TIME_DATE 1
|
||||
#define CONFIG_APP_RETRIEVE_LEN_ELF_SHA 16
|
||||
#define CONFIG_BOOTLOADER_OFFSET_IN_FLASH 0x1000
|
||||
#define CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE 1
|
||||
#define CONFIG_BOOTLOADER_LOG_LEVEL_INFO 1
|
||||
#define CONFIG_BOOTLOADER_LOG_LEVEL 3
|
||||
#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1
|
||||
#define CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE 1
|
||||
#define CONFIG_BOOTLOADER_WDT_ENABLE 1
|
||||
#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000
|
||||
#define CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE 1
|
||||
#define CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP 1
|
||||
#define CONFIG_BOOTLOADER_RESERVE_RTC_SIZE 0x10
|
||||
#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
|
||||
#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200
|
||||
#define CONFIG_ESPTOOLPY_FLASHMODE_DOUT 1
|
||||
#define CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHMODE "dout"
|
||||
#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHFREQ "80m"
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE "4MB"
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1
|
||||
#define CONFIG_ESPTOOLPY_BEFORE_RESET 1
|
||||
#define CONFIG_ESPTOOLPY_BEFORE "default_reset"
|
||||
#define CONFIG_ESPTOOLPY_AFTER_RESET 1
|
||||
#define CONFIG_ESPTOOLPY_AFTER "hard_reset"
|
||||
#define CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B 1
|
||||
#define CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL 115200
|
||||
#define CONFIG_ESPTOOLPY_MONITOR_BAUD 115200
|
||||
#define CONFIG_PARTITION_TABLE_SINGLE_APP 1
|
||||
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
|
||||
#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv"
|
||||
#define CONFIG_PARTITION_TABLE_OFFSET 0x8000
|
||||
#define CONFIG_PARTITION_TABLE_MD5 1
|
||||
#define CONFIG_LIB_BUILDER_FLASHMODE "dout"
|
||||
#define CONFIG_LIB_BUILDER_FLASHFREQ "80m"
|
||||
#define CONFIG_ESP_RMAKER_ASSISTED_CLAIM 1
|
||||
#define CONFIG_ESP_RMAKER_CLAIM_TYPE 2
|
||||
#define CONFIG_ESP_RMAKER_MQTT_HOST "a1p72mufdu6064-ats.iot.us-east-1.amazonaws.com"
|
||||
#define CONFIG_ESP_RMAKER_MAX_PARAM_DATA_SIZE 1024
|
||||
#define CONFIG_ESP_RMAKER_CONSOLE_UART_NUM_0 1
|
||||
#define CONFIG_ESP_RMAKER_CONSOLE_UART_NUM 0
|
||||
#define CONFIG_ESP_RMAKER_USE_CERT_BUNDLE 1
|
||||
#define CONFIG_ESP_RMAKER_OTA_AUTOFETCH 1
|
||||
#define CONFIG_ESP_RMAKER_OTA_AUTOFETCH_PERIOD 0
|
||||
#define CONFIG_ESP_RMAKER_SKIP_VERSION_CHECK 1
|
||||
#define CONFIG_ESP_RMAKER_OTA_HTTP_RX_BUFFER_SIZE 1024
|
||||
#define CONFIG_ESP_RMAKER_OTA_ROLLBACK_WAIT_PERIOD 90
|
||||
#define CONFIG_ESP_RMAKER_SCHEDULING_MAX_SCHEDULES 10
|
||||
#define CONFIG_ESP_RMAKER_SCENES_MAX_SCENES 10
|
||||
#define CONFIG_ESP_RMAKER_CMD_RESP_ENABLE 1
|
||||
#define CONFIG_ARDUINO_VARIANT "esp32"
|
||||
#define CONFIG_ENABLE_ARDUINO_DEPENDS 1
|
||||
#define CONFIG_AUTOSTART_ARDUINO 1
|
||||
#define CONFIG_ARDUINO_RUN_CORE1 1
|
||||
#define CONFIG_ARDUINO_RUNNING_CORE 1
|
||||
#define CONFIG_ARDUINO_LOOP_STACK_SIZE 8192
|
||||
#define CONFIG_ARDUINO_EVENT_RUN_CORE1 1
|
||||
#define CONFIG_ARDUINO_EVENT_RUNNING_CORE 1
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY 1
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_ARDUINO_SERIAL_EVENT_TASK_PRIORITY 24
|
||||
#define CONFIG_ARDUINO_UDP_RUN_CORE0 1
|
||||
#define CONFIG_ARDUINO_UDP_RUNNING_CORE 0
|
||||
#define CONFIG_ARDUINO_UDP_TASK_PRIORITY 3
|
||||
#define CONFIG_DISABLE_HAL_LOCKS 1
|
||||
#define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR 1
|
||||
#define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 1
|
||||
#define CONFIG_ARDUHAL_ESP_LOG 1
|
||||
#define CONFIG_ARDUHAL_PARTITION_SCHEME_DEFAULT 1
|
||||
#define CONFIG_ARDUHAL_PARTITION_SCHEME "default"
|
||||
#define CONFIG_USE_AFE 1
|
||||
#define CONFIG_AFE_INTERFACE_V1 1
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_SIZE 1
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE 1
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL 2
|
||||
#define CONFIG_COMPILER_HIDE_PATHS_MACROS 1
|
||||
#define CONFIG_COMPILER_CXX_EXCEPTIONS 1
|
||||
#define CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE 0
|
||||
#define CONFIG_COMPILER_STACK_CHECK_MODE_NORM 1
|
||||
#define CONFIG_COMPILER_STACK_CHECK 1
|
||||
#define CONFIG_COMPILER_WARN_WRITE_STRINGS 1
|
||||
#define CONFIG_APPTRACE_DEST_NONE 1
|
||||
#define CONFIG_APPTRACE_LOCK_ENABLE 1
|
||||
#define CONFIG_BT_ENABLED 1
|
||||
#define CONFIG_BTDM_CTRL_MODE_BTDM 1
|
||||
#define CONFIG_BTDM_CTRL_BLE_MAX_CONN 3
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN 2
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN 0
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_PCM 1
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_ROLE_EDGE_CONFIG 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_ROLE_MASTER 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_POLAR_FALLING_EDGE 1
|
||||
#define CONFIG_BTDM_CTRL_PCM_ROLE_EFF 0
|
||||
#define CONFIG_BTDM_CTRL_PCM_POLAR_EFF 0
|
||||
#define CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT 1
|
||||
#define CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF 1
|
||||
#define CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF 3
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF 2
|
||||
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF 0
|
||||
#define CONFIG_BTDM_CTRL_PINNED_TO_CORE_0 1
|
||||
#define CONFIG_BTDM_CTRL_PINNED_TO_CORE 0
|
||||
#define CONFIG_BTDM_CTRL_HCI_MODE_VHCI 1
|
||||
#define CONFIG_BTDM_CTRL_MODEM_SLEEP 1
|
||||
#define CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_ORIG 1
|
||||
#define CONFIG_BTDM_CTRL_LPCLK_SEL_MAIN_XTAL 1
|
||||
#define CONFIG_BTDM_BLE_DEFAULT_SCA_250PPM 1
|
||||
#define CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF 1
|
||||
#define CONFIG_BTDM_BLE_SCAN_DUPL 1
|
||||
#define CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE 1
|
||||
#define CONFIG_BTDM_SCAN_DUPL_TYPE 0
|
||||
#define CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE 20
|
||||
#define CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN 1
|
||||
#define CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE 100
|
||||
#define CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED 1
|
||||
#define CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP 1
|
||||
#define CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM 100
|
||||
#define CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD 20
|
||||
#define CONFIG_BTDM_RESERVE_DRAM 0xdb5c
|
||||
#define CONFIG_BTDM_CTRL_HLI 1
|
||||
#define CONFIG_BT_BLUEDROID_ENABLED 1
|
||||
#define CONFIG_BT_BTC_TASK_STACK_SIZE 8192
|
||||
#define CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0 1
|
||||
#define CONFIG_BT_BLUEDROID_PINNED_TO_CORE 0
|
||||
#define CONFIG_BT_BTU_TASK_STACK_SIZE 8192
|
||||
#define CONFIG_BT_CLASSIC_ENABLED 1
|
||||
#define CONFIG_BT_A2DP_ENABLE 1
|
||||
#define CONFIG_BT_SPP_ENABLED 1
|
||||
#define CONFIG_BT_HFP_ENABLE 1
|
||||
#define CONFIG_BT_HFP_CLIENT_ENABLE 1
|
||||
#define CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM 1
|
||||
#define CONFIG_BT_SSP_ENABLED 1
|
||||
#define CONFIG_BT_BLE_ENABLED 1
|
||||
#define CONFIG_BT_GATTS_ENABLE 1
|
||||
#define CONFIG_BT_GATT_MAX_SR_PROFILES 8
|
||||
#define CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO 1
|
||||
#define CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE 0
|
||||
#define CONFIG_BT_GATTC_ENABLE 1
|
||||
#define CONFIG_BT_GATTC_CONNECT_RETRY_COUNT 3
|
||||
#define CONFIG_BT_BLE_SMP_ENABLE 1
|
||||
#define CONFIG_BT_STACK_NO_LOG 1
|
||||
#define CONFIG_BT_ACL_CONNECTIONS 4
|
||||
#define CONFIG_BT_MULTI_CONNECTION_ENBALE 1
|
||||
#define CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY 1
|
||||
#define CONFIG_BT_SMP_ENABLE 1
|
||||
#define CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT 30
|
||||
#define CONFIG_BT_MAX_DEVICE_NAME_LEN 32
|
||||
#define CONFIG_BLE_MESH 1
|
||||
#define CONFIG_BLE_MESH_HCI_5_0 1
|
||||
#define CONFIG_BLE_MESH_USE_DUPLICATE_SCAN 1
|
||||
#define CONFIG_BLE_MESH_MEM_ALLOC_MODE_INTERNAL 1
|
||||
#define CONFIG_BLE_MESH_DEINIT 1
|
||||
#define CONFIG_BLE_MESH_PROV 1
|
||||
#define CONFIG_BLE_MESH_PB_ADV 1
|
||||
#define CONFIG_BLE_MESH_PROXY 1
|
||||
#define CONFIG_BLE_MESH_NET_BUF_POOL_USAGE 1
|
||||
#define CONFIG_BLE_MESH_SUBNET_COUNT 3
|
||||
#define CONFIG_BLE_MESH_APP_KEY_COUNT 3
|
||||
#define CONFIG_BLE_MESH_MODEL_KEY_COUNT 3
|
||||
#define CONFIG_BLE_MESH_MODEL_GROUP_COUNT 3
|
||||
#define CONFIG_BLE_MESH_LABEL_COUNT 3
|
||||
#define CONFIG_BLE_MESH_CRPL 10
|
||||
#define CONFIG_BLE_MESH_MSG_CACHE_SIZE 10
|
||||
#define CONFIG_BLE_MESH_ADV_BUF_COUNT 60
|
||||
#define CONFIG_BLE_MESH_IVU_DIVIDER 4
|
||||
#define CONFIG_BLE_MESH_TX_SEG_MSG_COUNT 1
|
||||
#define CONFIG_BLE_MESH_RX_SEG_MSG_COUNT 1
|
||||
#define CONFIG_BLE_MESH_RX_SDU_MAX 384
|
||||
#define CONFIG_BLE_MESH_TX_SEG_MAX 32
|
||||
#define CONFIG_BLE_MESH_TRACE_LEVEL_WARNING 1
|
||||
#define CONFIG_BLE_MESH_STACK_TRACE_LEVEL 2
|
||||
#define CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL_WARNING 1
|
||||
#define CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL 2
|
||||
#define CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT 4000
|
||||
#define CONFIG_BLE_MESH_HEALTH_SRV 1
|
||||
#define CONFIG_BLE_MESH_GENERIC_SERVER 1
|
||||
#define CONFIG_BLE_MESH_SENSOR_SERVER 1
|
||||
#define CONFIG_BLE_MESH_TIME_SCENE_SERVER 1
|
||||
#define CONFIG_BLE_MESH_LIGHTING_SERVER 1
|
||||
#define CONFIG_BLE_MESH_DISCARD_OLD_SEQ_AUTH 1
|
||||
#define CONFIG_COAP_MBEDTLS_PSK 1
|
||||
#define CONFIG_COAP_LOG_DEFAULT_LEVEL 0
|
||||
#define CONFIG_ADC_DISABLE_DAC 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID 1
|
||||
#define CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT 1
|
||||
#define CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4 1
|
||||
#define CONFIG_EFUSE_MAX_BLK_LEN 192
|
||||
#define CONFIG_ESP_TLS_USING_MBEDTLS 1
|
||||
#define CONFIG_ESP_TLS_SERVER 1
|
||||
#define CONFIG_ESP32_ECO3_CACHE_LOCK_FIX 1
|
||||
#define CONFIG_ESP32_REV_MIN_0 1
|
||||
#define CONFIG_ESP32_REV_MIN 0
|
||||
#define CONFIG_ESP32_DPORT_WORKAROUND 1
|
||||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1
|
||||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160
|
||||
#define CONFIG_ESP32_SPIRAM_SUPPORT 1
|
||||
#define CONFIG_SPIRAM_TYPE_AUTO 1
|
||||
#define CONFIG_SPIRAM_SIZE -1
|
||||
#define CONFIG_SPIRAM_SPEED_80M 1
|
||||
#define CONFIG_SPIRAM 1
|
||||
#define CONFIG_SPIRAM_USE_MALLOC 1
|
||||
#define CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL 4096
|
||||
#define CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL 0
|
||||
#define CONFIG_SPIRAM_CACHE_WORKAROUND 1
|
||||
#define CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBJMP_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBMATH_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBNUMPARSER_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBIO_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBTIME_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBCHAR_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBMEM_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBSTR_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBRAND_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBENV_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBFILE_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_CACHE_LIBMISC_IN_IRAM 1
|
||||
#define CONFIG_SPIRAM_BANKSWITCH_ENABLE 1
|
||||
#define CONFIG_SPIRAM_BANKSWITCH_RESERVE 8
|
||||
#define CONFIG_SPIRAM_OCCUPY_HSPI_HOST 1
|
||||
#define CONFIG_D0WD_PSRAM_CLK_IO 17
|
||||
#define CONFIG_D0WD_PSRAM_CS_IO 16
|
||||
#define CONFIG_D2WD_PSRAM_CLK_IO 9
|
||||
#define CONFIG_D2WD_PSRAM_CS_IO 10
|
||||
#define CONFIG_PICO_PSRAM_CS_IO 10
|
||||
#define CONFIG_SPIRAM_SPIWP_SD3_PIN 7
|
||||
#define CONFIG_ESP32_TRACEMEM_RESERVE_DRAM 0x0
|
||||
#define CONFIG_ESP32_ULP_COPROC_ENABLED 1
|
||||
#define CONFIG_ESP32_ULP_COPROC_RESERVE_MEM 512
|
||||
#define CONFIG_ESP32_DEBUG_OCDAWARE 1
|
||||
#define CONFIG_ESP32_BROWNOUT_DET 1
|
||||
#define CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0 1
|
||||
#define CONFIG_ESP32_BROWNOUT_DET_LVL 0
|
||||
#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1
|
||||
#define CONFIG_ESP32_RTC_CLK_SRC_INT_RC 1
|
||||
#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024
|
||||
#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000
|
||||
#define CONFIG_ESP32_XTAL_FREQ_AUTO 1
|
||||
#define CONFIG_ESP32_XTAL_FREQ 0
|
||||
#define CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL 5
|
||||
#define CONFIG_ADC_CAL_EFUSE_TP_ENABLE 1
|
||||
#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1
|
||||
#define CONFIG_ADC_CAL_LUT_ENABLE 1
|
||||
#define CONFIG_ESP_ERR_TO_NAME_LOOKUP 1
|
||||
#define CONFIG_ETH_ENABLED 1
|
||||
#define CONFIG_ETH_USE_ESP32_EMAC 1
|
||||
#define CONFIG_ETH_PHY_INTERFACE_RMII 1
|
||||
#define CONFIG_ETH_RMII_CLK_INPUT 1
|
||||
#define CONFIG_ETH_RMII_CLK_IN_GPIO 0
|
||||
#define CONFIG_ETH_DMA_BUFFER_SIZE 512
|
||||
#define CONFIG_ETH_DMA_RX_BUFFER_NUM 10
|
||||
#define CONFIG_ETH_DMA_TX_BUFFER_NUM 10
|
||||
#define CONFIG_ETH_USE_SPI_ETHERNET 1
|
||||
#define CONFIG_ETH_SPI_ETHERNET_DM9051 1
|
||||
#define CONFIG_ETH_SPI_ETHERNET_W5500 1
|
||||
#define CONFIG_ESP_EVENT_POST_FROM_ISR 1
|
||||
#define CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR 1
|
||||
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1
|
||||
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH 1
|
||||
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH 1
|
||||
#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 1024
|
||||
#define CONFIG_HTTPD_MAX_URI_LEN 512
|
||||
#define CONFIG_HTTPD_ERR_RESP_NO_DELAY 1
|
||||
#define CONFIG_HTTPD_PURGE_BUF_LEN 32
|
||||
#define CONFIG_HTTPD_WS_SUPPORT 1
|
||||
#define CONFIG_ESP_HTTPS_SERVER_ENABLE 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_BT 1
|
||||
#define CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH 1
|
||||
#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR 1
|
||||
#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES 4
|
||||
#define CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND 1
|
||||
#define CONFIG_ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND 1
|
||||
#define CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND 1
|
||||
#define CONFIG_ESP_IPC_TASK_STACK_SIZE 1024
|
||||
#define CONFIG_ESP_IPC_USES_CALLERS_PRIORITY 1
|
||||
#define CONFIG_ESP_IPC_ISR_ENABLE 1
|
||||
#define CONFIG_LCD_PANEL_IO_FORMAT_BUF_SIZE 32
|
||||
#define CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL 120
|
||||
#define CONFIG_ESP_NETIF_TCPIP_LWIP 1
|
||||
#define CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER 1
|
||||
#define CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE 1
|
||||
#define CONFIG_ESP_PHY_MAX_WIFI_TX_POWER 20
|
||||
#define CONFIG_ESP_PHY_MAX_TX_POWER 20
|
||||
#define CONFIG_ESP_PHY_REDUCE_TX_POWER 1
|
||||
#define CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT 1
|
||||
#define CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE 32
|
||||
#define CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_ESP_MAIN_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_ESP_MAIN_TASK_AFFINITY 0x0
|
||||
#define CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE 2048
|
||||
#define CONFIG_ESP_CONSOLE_UART_DEFAULT 1
|
||||
#define CONFIG_ESP_CONSOLE_UART 1
|
||||
#define CONFIG_ESP_CONSOLE_MULTIPLE_UART 1
|
||||
#define CONFIG_ESP_CONSOLE_UART_NUM 0
|
||||
#define CONFIG_ESP_CONSOLE_UART_BAUDRATE 115200
|
||||
#define CONFIG_ESP_INT_WDT 1
|
||||
#define CONFIG_ESP_INT_WDT_TIMEOUT_MS 300
|
||||
#define CONFIG_ESP_INT_WDT_CHECK_CPU1 1
|
||||
#define CONFIG_ESP_TASK_WDT 1
|
||||
#define CONFIG_ESP_TASK_WDT_PANIC 1
|
||||
#define CONFIG_ESP_TASK_WDT_TIMEOUT_S 5
|
||||
#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 1
|
||||
#define CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5 1
|
||||
#define CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER 1
|
||||
#define CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER 1
|
||||
#define CONFIG_ESP_TIMER_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_ESP_TIMER_INTERRUPT_LEVEL 1
|
||||
#define CONFIG_ESP_TIMER_IMPL_TG0_LAC 1
|
||||
#define CONFIG_ESP32_WIFI_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE 1
|
||||
#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 8
|
||||
#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 32
|
||||
#define CONFIG_ESP32_WIFI_STATIC_TX_BUFFER 1
|
||||
#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 0
|
||||
#define CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM 8
|
||||
#define CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM 16
|
||||
#define CONFIG_ESP32_WIFI_CSI_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_TX_BA_WIN 6
|
||||
#define CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_RX_BA_WIN 6
|
||||
#define CONFIG_ESP32_WIFI_NVS_ENABLED 1
|
||||
#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1
|
||||
#define CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN 752
|
||||
#define CONFIG_ESP32_WIFI_MGMT_SBUF_NUM 32
|
||||
#define CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE 1
|
||||
#define CONFIG_ESP_WIFI_SOFTAP_SUPPORT 1
|
||||
#define CONFIG_ESP_COREDUMP_ENABLE_TO_NONE 1
|
||||
#define CONFIG_FATFS_CODEPAGE_850 1
|
||||
#define CONFIG_FATFS_CODEPAGE 850
|
||||
#define CONFIG_FATFS_LFN_STACK 1
|
||||
#define CONFIG_FATFS_MAX_LFN 255
|
||||
#define CONFIG_FATFS_API_ENCODING_ANSI_OEM 1
|
||||
#define CONFIG_FATFS_FS_LOCK 0
|
||||
#define CONFIG_FATFS_TIMEOUT_MS 10000
|
||||
#define CONFIG_FATFS_PER_FILE_CACHE 1
|
||||
#define CONFIG_FATFS_ALLOC_PREFER_EXTRAM 1
|
||||
#define CONFIG_FMB_COMM_MODE_TCP_EN 1
|
||||
#define CONFIG_FMB_TCP_PORT_DEFAULT 502
|
||||
#define CONFIG_FMB_TCP_PORT_MAX_CONN 5
|
||||
#define CONFIG_FMB_TCP_CONNECTION_TOUT_SEC 20
|
||||
#define CONFIG_FMB_COMM_MODE_RTU_EN 1
|
||||
#define CONFIG_FMB_COMM_MODE_ASCII_EN 1
|
||||
#define CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND 150
|
||||
#define CONFIG_FMB_MASTER_DELAY_MS_CONVERT 200
|
||||
#define CONFIG_FMB_QUEUE_LENGTH 20
|
||||
#define CONFIG_FMB_PORT_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_FMB_SERIAL_BUF_SIZE 256
|
||||
#define CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB 8
|
||||
#define CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS 1000
|
||||
#define CONFIG_FMB_PORT_TASK_PRIO 10
|
||||
#define CONFIG_FMB_PORT_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_FMB_PORT_TASK_AFFINITY 0x0
|
||||
#define CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT 20
|
||||
#define CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE 20
|
||||
#define CONFIG_FMB_CONTROLLER_STACK_SIZE 4096
|
||||
#define CONFIG_FMB_EVENT_QUEUE_TIMEOUT 20
|
||||
#define CONFIG_FMB_TIMER_PORT_ENABLED 1
|
||||
#define CONFIG_FMB_TIMER_GROUP 0
|
||||
#define CONFIG_FMB_TIMER_INDEX 0
|
||||
#define CONFIG_FMB_MASTER_TIMER_GROUP 0
|
||||
#define CONFIG_FMB_MASTER_TIMER_INDEX 0
|
||||
#define CONFIG_FREERTOS_NO_AFFINITY 0x7FFFFFFF
|
||||
#define CONFIG_FREERTOS_TICK_SUPPORT_CORETIMER 1
|
||||
#define CONFIG_FREERTOS_CORETIMER_0 1
|
||||
#define CONFIG_FREERTOS_SYSTICK_USES_CCOUNT 1
|
||||
#define CONFIG_FREERTOS_HZ 1000
|
||||
#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1
|
||||
#define CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK 1
|
||||
#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1
|
||||
#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1
|
||||
#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1
|
||||
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024
|
||||
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
|
||||
#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16
|
||||
#define CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION 1
|
||||
#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1
|
||||
#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 2048
|
||||
#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10
|
||||
#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0
|
||||
#define CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER 1
|
||||
#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1
|
||||
#define CONFIG_FREERTOS_FPU_IN_ISR 1
|
||||
#define CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT 1
|
||||
#define CONFIG_HAL_ASSERTION_EQUALS_SYSTEM 1
|
||||
#define CONFIG_HAL_DEFAULT_ASSERTION_LEVEL 2
|
||||
#define CONFIG_HEAP_POISONING_LIGHT 1
|
||||
#define CONFIG_HEAP_TRACING_OFF 1
|
||||
#define CONFIG_LOG_DEFAULT_LEVEL_ERROR 1
|
||||
#define CONFIG_LOG_DEFAULT_LEVEL 1
|
||||
#define CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT 1
|
||||
#define CONFIG_LOG_MAXIMUM_LEVEL 1
|
||||
#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1
|
||||
#define CONFIG_LWIP_LOCAL_HOSTNAME "espressif"
|
||||
#define CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES 1
|
||||
#define CONFIG_LWIP_TIMERS_ONDEMAND 1
|
||||
#define CONFIG_LWIP_MAX_SOCKETS 16
|
||||
#define CONFIG_LWIP_SO_REUSE 1
|
||||
#define CONFIG_LWIP_SO_REUSE_RXTOALL 1
|
||||
#define CONFIG_LWIP_SO_RCVBUF 1
|
||||
#define CONFIG_LWIP_IP4_FRAG 1
|
||||
#define CONFIG_LWIP_IP6_FRAG 1
|
||||
#define CONFIG_LWIP_ETHARP_TRUST_IP_MAC 1
|
||||
#define CONFIG_LWIP_ESP_GRATUITOUS_ARP 1
|
||||
#define CONFIG_LWIP_GARP_TMR_INTERVAL 60
|
||||
#define CONFIG_LWIP_TCPIP_RECVMBOX_SIZE 32
|
||||
#define CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID 1
|
||||
#define CONFIG_LWIP_DHCP_RESTORE_LAST_IP 1
|
||||
#define CONFIG_LWIP_DHCP_OPTIONS_LEN 128
|
||||
#define CONFIG_LWIP_DHCPS 1
|
||||
#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60
|
||||
#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8
|
||||
#define CONFIG_LWIP_IPV6 1
|
||||
#define CONFIG_LWIP_IPV6_AUTOCONFIG 1
|
||||
#define CONFIG_LWIP_IPV6_NUM_ADDRESSES 3
|
||||
#define CONFIG_LWIP_IPV6_RDNSS_MAX_DNS_SERVERS 0
|
||||
#define CONFIG_LWIP_NETIF_LOOPBACK 1
|
||||
#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8
|
||||
#define CONFIG_LWIP_MAX_ACTIVE_TCP 16
|
||||
#define CONFIG_LWIP_MAX_LISTENING_TCP 16
|
||||
#define CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION 1
|
||||
#define CONFIG_LWIP_TCP_MAXRTX 12
|
||||
#define CONFIG_LWIP_TCP_SYNMAXRTX 6
|
||||
#define CONFIG_LWIP_TCP_MSS 1436
|
||||
#define CONFIG_LWIP_TCP_TMR_INTERVAL 250
|
||||
#define CONFIG_LWIP_TCP_MSL 60000
|
||||
#define CONFIG_LWIP_TCP_SND_BUF_DEFAULT 5744
|
||||
#define CONFIG_LWIP_TCP_WND_DEFAULT 5744
|
||||
#define CONFIG_LWIP_TCP_RECVMBOX_SIZE 6
|
||||
#define CONFIG_LWIP_TCP_QUEUE_OOSEQ 1
|
||||
#define CONFIG_LWIP_TCP_OVERSIZE_MSS 1
|
||||
#define CONFIG_LWIP_TCP_RTO_TIME 3000
|
||||
#define CONFIG_LWIP_MAX_UDP_PCBS 16
|
||||
#define CONFIG_LWIP_UDP_RECVMBOX_SIZE 6
|
||||
#define CONFIG_LWIP_CHECKSUM_CHECK_ICMP 1
|
||||
#define CONFIG_LWIP_TCPIP_TASK_STACK_SIZE 2560
|
||||
#define CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_LWIP_TCPIP_TASK_AFFINITY 0x0
|
||||
#define CONFIG_LWIP_PPP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_ENABLE_IPV6 1
|
||||
#define CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE 3
|
||||
#define CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS 5
|
||||
#define CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_PAP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_CHAP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_MSCHAP_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_MPPE_SUPPORT 1
|
||||
#define CONFIG_LWIP_PPP_DEBUG_ON 1
|
||||
#define CONFIG_LWIP_ICMP 1
|
||||
#define CONFIG_LWIP_MAX_RAW_PCBS 16
|
||||
#define CONFIG_LWIP_SNTP_MAX_SERVERS 3
|
||||
#define CONFIG_LWIP_DHCP_GET_NTP_SRV 1
|
||||
#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1
|
||||
#define CONFIG_LWIP_SNTP_UPDATE_DELAY 10800000
|
||||
#define CONFIG_LWIP_ESP_LWIP_ASSERT 1
|
||||
#define CONFIG_LWIP_HOOK_TCP_ISN_DEFAULT 1
|
||||
#define CONFIG_LWIP_HOOK_IP6_ROUTE_NONE 1
|
||||
#define CONFIG_LWIP_HOOK_ND6_GET_GW_NONE 1
|
||||
#define CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE 1
|
||||
#define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1
|
||||
#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384
|
||||
#define CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE 1
|
||||
#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE 1
|
||||
#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL 1
|
||||
#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS 200
|
||||
#define CONFIG_MBEDTLS_HARDWARE_AES 1
|
||||
#define CONFIG_MBEDTLS_HARDWARE_MPI 1
|
||||
#define CONFIG_MBEDTLS_HARDWARE_SHA 1
|
||||
#define CONFIG_MBEDTLS_ROM_MD5 1
|
||||
#define CONFIG_MBEDTLS_HAVE_TIME 1
|
||||
#define CONFIG_MBEDTLS_ECDSA_DETERMINISTIC 1
|
||||
#define CONFIG_MBEDTLS_SHA512_C 1
|
||||
#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
|
||||
#define CONFIG_MBEDTLS_TLS_SERVER 1
|
||||
#define CONFIG_MBEDTLS_TLS_CLIENT 1
|
||||
#define CONFIG_MBEDTLS_TLS_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_PSK_MODES 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1
|
||||
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1
|
||||
#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1
|
||||
#define CONFIG_MBEDTLS_SSL_PROTO_DTLS 1
|
||||
#define CONFIG_MBEDTLS_SSL_ALPN 1
|
||||
#define CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS 1
|
||||
#define CONFIG_MBEDTLS_X509_CHECK_KEY_USAGE 1
|
||||
#define CONFIG_MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 1
|
||||
#define CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS 1
|
||||
#define CONFIG_MBEDTLS_AES_C 1
|
||||
#define CONFIG_MBEDTLS_CAMELLIA_C 1
|
||||
#define CONFIG_MBEDTLS_RC4_DISABLED 1
|
||||
#define CONFIG_MBEDTLS_CCM_C 1
|
||||
#define CONFIG_MBEDTLS_GCM_C 1
|
||||
#define CONFIG_MBEDTLS_PEM_PARSE_C 1
|
||||
#define CONFIG_MBEDTLS_PEM_WRITE_C 1
|
||||
#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1
|
||||
#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1
|
||||
#define CONFIG_MBEDTLS_ECP_C 1
|
||||
#define CONFIG_MBEDTLS_ECDH_C 1
|
||||
#define CONFIG_MBEDTLS_ECDSA_C 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1
|
||||
#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1
|
||||
#define CONFIG_MDNS_MAX_SERVICES 10
|
||||
#define CONFIG_MDNS_TASK_PRIORITY 1
|
||||
#define CONFIG_MDNS_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_MDNS_TASK_AFFINITY_CPU0 1
|
||||
#define CONFIG_MDNS_TASK_AFFINITY 0x0
|
||||
#define CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS 2000
|
||||
#define CONFIG_MDNS_TIMER_PERIOD_MS 100
|
||||
#define CONFIG_MDNS_MULTIPLE_INSTANCE 1
|
||||
#define CONFIG_MQTT_PROTOCOL_311 1
|
||||
#define CONFIG_MQTT_TRANSPORT_SSL 1
|
||||
#define CONFIG_MQTT_TRANSPORT_WEBSOCKET 1
|
||||
#define CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE 1
|
||||
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
|
||||
#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1
|
||||
#define CONFIG_OPENSSL_ERROR_STACK 1
|
||||
#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1
|
||||
#define CONFIG_PTHREAD_TASK_PRIO_DEFAULT 5
|
||||
#define CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT 2048
|
||||
#define CONFIG_PTHREAD_STACK_MIN 768
|
||||
#define CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY 1
|
||||
#define CONFIG_PTHREAD_TASK_CORE_DEFAULT -1
|
||||
#define CONFIG_PTHREAD_TASK_NAME_DEFAULT "pthread"
|
||||
#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
|
||||
#define CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS 1
|
||||
#define CONFIG_SPI_FLASH_YIELD_DURING_ERASE 1
|
||||
#define CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS 10
|
||||
#define CONFIG_SPI_FLASH_ERASE_YIELD_TICKS 2
|
||||
#define CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE 4096
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_GD_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP 1
|
||||
#define CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE 1
|
||||
#define CONFIG_SPIFFS_MAX_PARTITIONS 3
|
||||
#define CONFIG_SPIFFS_CACHE 1
|
||||
#define CONFIG_SPIFFS_CACHE_WR 1
|
||||
#define CONFIG_SPIFFS_PAGE_CHECK 1
|
||||
#define CONFIG_SPIFFS_GC_MAX_RUNS 10
|
||||
#define CONFIG_SPIFFS_PAGE_SIZE 256
|
||||
#define CONFIG_SPIFFS_OBJ_NAME_LEN 32
|
||||
#define CONFIG_SPIFFS_USE_MAGIC 1
|
||||
#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1
|
||||
#define CONFIG_SPIFFS_META_LENGTH 4
|
||||
#define CONFIG_SPIFFS_USE_MTIME 1
|
||||
#define CONFIG_WS_TRANSPORT 1
|
||||
#define CONFIG_WS_BUFFER_SIZE 1024
|
||||
#define CONFIG_UNITY_ENABLE_FLOAT 1
|
||||
#define CONFIG_UNITY_ENABLE_DOUBLE 1
|
||||
#define CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER 1
|
||||
#define CONFIG_VFS_SUPPORT_IO 1
|
||||
#define CONFIG_VFS_SUPPORT_DIR 1
|
||||
#define CONFIG_VFS_SUPPORT_SELECT 1
|
||||
#define CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT 1
|
||||
#define CONFIG_VFS_SUPPORT_TERMIOS 1
|
||||
#define CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS 1
|
||||
#define CONFIG_WL_SECTOR_SIZE_4096 1
|
||||
#define CONFIG_WL_SECTOR_SIZE 4096
|
||||
#define CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES 16
|
||||
#define CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT 30
|
||||
#define CONFIG_WIFI_PROV_BLE_BONDING 1
|
||||
#define CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION 1
|
||||
#define CONFIG_WPA_MBEDTLS_CRYPTO 1
|
||||
#define CONFIG_IO_GLITCH_FILTER_TIME_MS 50
|
||||
#define CONFIG_ESP_RMAKER_LIB_ESP_MQTT 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_GLUE_LIB 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PORT_443 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PORT 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_SEND_USERNAME 1
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PRODUCT_NAME "RMDev"
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PRODUCT_VERSION "1x0"
|
||||
#define CONFIG_ESP_RMAKER_MQTT_PRODUCT_SKU "EX00"
|
||||
#define CONFIG_ESP_RMAKER_MQTT_USE_CERT_BUNDLE 1
|
||||
#define CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK 4096
|
||||
#define CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_PRIORITY 5
|
||||
#define CONFIG_ESP_RMAKER_FACTORY_PARTITION_NAME "fctry"
|
||||
#define CONFIG_ESP_RMAKER_FACTORY_NAMESPACE "rmaker_creds"
|
||||
#define CONFIG_ESP_RMAKER_DEF_TIMEZONE "Asia/Shanghai"
|
||||
#define CONFIG_ESP_RMAKER_SNTP_SERVER_NAME "pool.ntp.org"
|
||||
#define CONFIG_ESP_RMAKER_MAX_COMMANDS 10
|
||||
#define CONFIG_DSP_OPTIMIZATIONS_SUPPORTED 1
|
||||
#define CONFIG_DSP_OPTIMIZED 1
|
||||
#define CONFIG_DSP_OPTIMIZATION 1
|
||||
#define CONFIG_DSP_MAX_FFT_SIZE_4096 1
|
||||
#define CONFIG_DSP_MAX_FFT_SIZE 4096
|
||||
#define CONFIG_OV7670_SUPPORT 1
|
||||
#define CONFIG_OV7725_SUPPORT 1
|
||||
#define CONFIG_NT99141_SUPPORT 1
|
||||
#define CONFIG_OV2640_SUPPORT 1
|
||||
#define CONFIG_OV3660_SUPPORT 1
|
||||
#define CONFIG_OV5640_SUPPORT 1
|
||||
#define CONFIG_GC2145_SUPPORT 1
|
||||
#define CONFIG_GC032A_SUPPORT 1
|
||||
#define CONFIG_GC0308_SUPPORT 1
|
||||
#define CONFIG_BF3005_SUPPORT 1
|
||||
#define CONFIG_BF20A6_SUPPORT 1
|
||||
#define CONFIG_SC030IOT_SUPPORT 1
|
||||
#define CONFIG_SCCB_HARDWARE_I2C_PORT1 1
|
||||
#define CONFIG_SCCB_CLK_FREQ 100000
|
||||
#define CONFIG_GC_SENSOR_SUBSAMPLE_MODE 1
|
||||
#define CONFIG_CAMERA_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_CAMERA_CORE0 1
|
||||
#define CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX 32768
|
||||
#define CONFIG_LITTLEFS_MAX_PARTITIONS 3
|
||||
#define CONFIG_LITTLEFS_PAGE_SIZE 256
|
||||
#define CONFIG_LITTLEFS_OBJ_NAME_LEN 64
|
||||
#define CONFIG_LITTLEFS_READ_SIZE 128
|
||||
#define CONFIG_LITTLEFS_WRITE_SIZE 128
|
||||
#define CONFIG_LITTLEFS_LOOKAHEAD_SIZE 128
|
||||
#define CONFIG_LITTLEFS_CACHE_SIZE 512
|
||||
#define CONFIG_LITTLEFS_BLOCK_CYCLES 512
|
||||
#define CONFIG_LITTLEFS_USE_MTIME 1
|
||||
#define CONFIG_LITTLEFS_MTIME_USE_SECONDS 1
|
||||
|
||||
/* List of deprecated options */
|
||||
#define CONFIG_A2DP_ENABLE CONFIG_BT_A2DP_ENABLE
|
||||
#define CONFIG_ADC2_DISABLE_DAC CONFIG_ADC_DISABLE_DAC
|
||||
#define CONFIG_APP_ROLLBACK_ENABLE CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
#define CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD
|
||||
#define CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM
|
||||
#define CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
|
||||
#define CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT
|
||||
#define CONFIG_BLE_MESH_SCAN_DUPLICATE_EN CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN
|
||||
#define CONFIG_BLE_SCAN_DUPLICATE CONFIG_BTDM_BLE_SCAN_DUPL
|
||||
#define CONFIG_BLE_SMP_ENABLE CONFIG_BT_BLE_SMP_ENABLE
|
||||
#define CONFIG_BLUEDROID_ENABLED CONFIG_BT_BLUEDROID_ENABLED
|
||||
#define CONFIG_BLUEDROID_PINNED_TO_CORE_0 CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0
|
||||
#define CONFIG_BROWNOUT_DET CONFIG_ESP32_BROWNOUT_DET
|
||||
#define CONFIG_BROWNOUT_DET_LVL_SEL_0 CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0
|
||||
#define CONFIG_BTC_TASK_STACK_SIZE CONFIG_BT_BTC_TASK_STACK_SIZE
|
||||
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN CONFIG_BTDM_CTRL_BLE_MAX_CONN
|
||||
#define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN
|
||||
#define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN
|
||||
#define CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED
|
||||
#define CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI CONFIG_BTDM_CTRL_HCI_MODE_VHCI
|
||||
#define CONFIG_BTDM_CONTROLLER_MODEM_SLEEP CONFIG_BTDM_CTRL_MODEM_SLEEP
|
||||
#define CONFIG_BTDM_CONTROLLER_MODE_BTDM CONFIG_BTDM_CTRL_MODE_BTDM
|
||||
#define CONFIG_BTU_TASK_STACK_SIZE CONFIG_BT_BTU_TASK_STACK_SIZE
|
||||
#define CONFIG_CLASSIC_BT_ENABLED CONFIG_BT_CLASSIC_ENABLED
|
||||
#define CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE
|
||||
#define CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT
|
||||
#define CONFIG_CXX_EXCEPTIONS CONFIG_COMPILER_CXX_EXCEPTIONS
|
||||
#define CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE
|
||||
#define CONFIG_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE
|
||||
#define CONFIG_ESP32S2_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT
|
||||
#define CONFIG_ESP32_APPTRACE_DEST_NONE CONFIG_APPTRACE_DEST_NONE
|
||||
#define CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY
|
||||
#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE CONFIG_ESP_COREDUMP_ENABLE_TO_NONE
|
||||
#define CONFIG_ESP32_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT
|
||||
#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE
|
||||
#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER CONFIG_ESP_PHY_MAX_WIFI_TX_POWER
|
||||
#define CONFIG_ESP32_PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
|
||||
#define CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT CONFIG_PTHREAD_TASK_NAME_DEFAULT
|
||||
#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT CONFIG_PTHREAD_TASK_PRIO_DEFAULT
|
||||
#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT
|
||||
#define CONFIG_ESP32_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER
|
||||
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC CONFIG_ESP32_RTC_CLK_SRC_INT_RC
|
||||
#define CONFIG_ESP_GRATUITOUS_ARP CONFIG_LWIP_ESP_GRATUITOUS_ARP
|
||||
#define CONFIG_FLASHMODE_DOUT CONFIG_ESPTOOLPY_FLASHMODE_DOUT
|
||||
#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
|
||||
#define CONFIG_GARP_TMR_INTERVAL CONFIG_LWIP_GARP_TMR_INTERVAL
|
||||
#define CONFIG_GATTC_ENABLE CONFIG_BT_GATTC_ENABLE
|
||||
#define CONFIG_GATTS_ENABLE CONFIG_BT_GATTS_ENABLE
|
||||
#define CONFIG_GATTS_SEND_SERVICE_CHANGE_AUTO CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO
|
||||
#define CONFIG_HFP_AUDIO_DATA_PATH_PCM CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM
|
||||
#define CONFIG_HFP_CLIENT_ENABLE CONFIG_BT_HFP_CLIENT_ENABLE
|
||||
#define CONFIG_HFP_ENABLE CONFIG_BT_HFP_ENABLE
|
||||
#define CONFIG_INT_WDT CONFIG_ESP_INT_WDT
|
||||
#define CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1
|
||||
#define CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS
|
||||
#define CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_TASK_STACK_SIZE
|
||||
#define CONFIG_LOG_BOOTLOADER_LEVEL_INFO CONFIG_BOOTLOADER_LOG_LEVEL_INFO
|
||||
#define CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE
|
||||
#define CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE
|
||||
#define CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT
|
||||
#define CONFIG_MB_CONTROLLER_STACK_SIZE CONFIG_FMB_CONTROLLER_STACK_SIZE
|
||||
#define CONFIG_MB_EVENT_QUEUE_TIMEOUT CONFIG_FMB_EVENT_QUEUE_TIMEOUT
|
||||
#define CONFIG_MB_MASTER_DELAY_MS_CONVERT CONFIG_FMB_MASTER_DELAY_MS_CONVERT
|
||||
#define CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND
|
||||
#define CONFIG_MB_QUEUE_LENGTH CONFIG_FMB_QUEUE_LENGTH
|
||||
#define CONFIG_MB_SERIAL_BUF_SIZE CONFIG_FMB_SERIAL_BUF_SIZE
|
||||
#define CONFIG_MB_SERIAL_TASK_PRIO CONFIG_FMB_PORT_TASK_PRIO
|
||||
#define CONFIG_MB_SERIAL_TASK_STACK_SIZE CONFIG_FMB_PORT_TASK_STACK_SIZE
|
||||
#define CONFIG_MB_TIMER_GROUP CONFIG_FMB_TIMER_GROUP
|
||||
#define CONFIG_MB_TIMER_INDEX CONFIG_FMB_TIMER_INDEX
|
||||
#define CONFIG_MB_TIMER_PORT_ENABLED CONFIG_FMB_TIMER_PORT_ENABLED
|
||||
#define CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE
|
||||
#define CONFIG_MONITOR_BAUD_115200B CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B
|
||||
#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE
|
||||
#define CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE
|
||||
#define CONFIG_POST_EVENTS_FROM_IRAM_ISR CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR
|
||||
#define CONFIG_POST_EVENTS_FROM_ISR CONFIG_ESP_EVENT_POST_FROM_ISR
|
||||
#define CONFIG_PPP_CHAP_SUPPORT CONFIG_LWIP_PPP_CHAP_SUPPORT
|
||||
#define CONFIG_PPP_DEBUG_ON CONFIG_LWIP_PPP_DEBUG_ON
|
||||
#define CONFIG_PPP_MPPE_SUPPORT CONFIG_LWIP_PPP_MPPE_SUPPORT
|
||||
#define CONFIG_PPP_MSCHAP_SUPPORT CONFIG_LWIP_PPP_MSCHAP_SUPPORT
|
||||
#define CONFIG_PPP_NOTIFY_PHASE_SUPPORT CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT
|
||||
#define CONFIG_PPP_PAP_SUPPORT CONFIG_LWIP_PPP_PAP_SUPPORT
|
||||
#define CONFIG_PPP_SUPPORT CONFIG_LWIP_PPP_SUPPORT
|
||||
#define CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER
|
||||
#define CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE
|
||||
#define CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS
|
||||
#define CONFIG_SPIRAM_SUPPORT CONFIG_ESP32_SPIRAM_SUPPORT
|
||||
#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS
|
||||
#define CONFIG_STACK_CHECK_NORM CONFIG_COMPILER_STACK_CHECK_MODE_NORM
|
||||
#define CONFIG_SUPPORT_TERMIOS CONFIG_VFS_SUPPORT_TERMIOS
|
||||
#define CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT
|
||||
#define CONFIG_SW_COEXIST_ENABLE CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE
|
||||
#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE
|
||||
#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE
|
||||
#define CONFIG_TASK_WDT CONFIG_ESP_TASK_WDT
|
||||
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
|
||||
#define CONFIG_TASK_WDT_PANIC CONFIG_ESP_TASK_WDT_PANIC
|
||||
#define CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIMEOUT_S
|
||||
#define CONFIG_TCPIP_RECVMBOX_SIZE CONFIG_LWIP_TCPIP_RECVMBOX_SIZE
|
||||
#define CONFIG_TCPIP_TASK_AFFINITY_CPU0 CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0
|
||||
#define CONFIG_TCPIP_TASK_STACK_SIZE CONFIG_LWIP_TCPIP_TASK_STACK_SIZE
|
||||
#define CONFIG_TCP_MAXRTX CONFIG_LWIP_TCP_MAXRTX
|
||||
#define CONFIG_TCP_MSL CONFIG_LWIP_TCP_MSL
|
||||
#define CONFIG_TCP_MSS CONFIG_LWIP_TCP_MSS
|
||||
#define CONFIG_TCP_OVERSIZE_MSS CONFIG_LWIP_TCP_OVERSIZE_MSS
|
||||
#define CONFIG_TCP_QUEUE_OOSEQ CONFIG_LWIP_TCP_QUEUE_OOSEQ
|
||||
#define CONFIG_TCP_RECVMBOX_SIZE CONFIG_LWIP_TCP_RECVMBOX_SIZE
|
||||
#define CONFIG_TCP_SND_BUF_DEFAULT CONFIG_LWIP_TCP_SND_BUF_DEFAULT
|
||||
#define CONFIG_TCP_SYNMAXRTX CONFIG_LWIP_TCP_SYNMAXRTX
|
||||
#define CONFIG_TCP_WND_DEFAULT CONFIG_LWIP_TCP_WND_DEFAULT
|
||||
#define CONFIG_TIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH
|
||||
#define CONFIG_TIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY
|
||||
#define CONFIG_TIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH
|
||||
#define CONFIG_TIMER_TASK_STACK_SIZE CONFIG_ESP_TIMER_TASK_STACK_SIZE
|
||||
#define CONFIG_TOOLPREFIX CONFIG_SDK_TOOLPREFIX
|
||||
#define CONFIG_UDP_RECVMBOX_SIZE CONFIG_LWIP_UDP_RECVMBOX_SIZE
|
||||
#define CONFIG_ULP_COPROC_ENABLED CONFIG_ESP32_ULP_COPROC_ENABLED
|
||||
#define CONFIG_ULP_COPROC_RESERVE_MEM CONFIG_ESP32_ULP_COPROC_RESERVE_MEM
|
||||
#define CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS
|
||||
#define CONFIG_ARDUINO_IDF_COMMIT ""
|
||||
#define CONFIG_ARDUINO_IDF_BRANCH "release/v4.4"
|
BIN
tools/sdk/esp32/dout_qspi/libspi_flash.a
Normal file
BIN
tools/sdk/esp32/dout_qspi/libspi_flash.a
Normal file
Binary file not shown.
268
tools/sdk/esp32/include/app_trace/include/esp_app_trace.h
Normal file
268
tools/sdk/esp32/include/app_trace/include/esp_app_trace.h
Normal file
@ -0,0 +1,268 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ESP_APP_TRACE_H_
|
||||
#define ESP_APP_TRACE_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_app_trace_util.h" // ESP_APPTRACE_TMO_INFINITE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Application trace data destinations bits.
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_APPTRACE_DEST_JTAG = 1, ///< JTAG destination
|
||||
ESP_APPTRACE_DEST_TRAX = ESP_APPTRACE_DEST_JTAG, ///< xxx_TRAX name is obsolete, use more common xxx_JTAG
|
||||
ESP_APPTRACE_DEST_UART0, ///< UART0 destination
|
||||
ESP_APPTRACE_DEST_MAX = ESP_APPTRACE_DEST_UART0,
|
||||
ESP_APPTRACE_DEST_NUM
|
||||
} esp_apptrace_dest_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes application tracing module.
|
||||
*
|
||||
* @note Should be called before any esp_apptrace_xxx call.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_init(void);
|
||||
|
||||
/**
|
||||
* @brief Configures down buffer.
|
||||
* @note Needs to be called before initiating any data transfer using esp_apptrace_buffer_get and esp_apptrace_write.
|
||||
* This function does not protect internal data by lock.
|
||||
*
|
||||
* @param buf Address of buffer to use for down channel (host to target) data.
|
||||
* @param size Size of the buffer.
|
||||
*/
|
||||
void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Allocates buffer for trace data.
|
||||
* After data in buffer are ready to be sent off esp_apptrace_buffer_put must be called to indicate it.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data.
|
||||
* @param size Size of data to write to trace buffer.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return non-NULL on success, otherwise NULL.
|
||||
*/
|
||||
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Indicates that the data in buffer are ready to be sent off.
|
||||
* This function is a counterpart of and must be preceeded by esp_apptrace_buffer_get.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data. Should be identical to the same parameter in call to esp_apptrace_buffer_get.
|
||||
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_buffer_get.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Writes data to trace buffer.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data.
|
||||
* @param data Address of data to write to trace buffer.
|
||||
* @param size Size of data to write to trace buffer.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_t size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief vprintf-like function to sent log messages to host via specified HW interface.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
* @param fmt Address of format string.
|
||||
* @param ap List of arguments.
|
||||
*
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t tmo, const char *fmt, va_list ap);
|
||||
|
||||
/**
|
||||
* @brief vprintf-like function to sent log messages to host.
|
||||
*
|
||||
* @param fmt Address of format string.
|
||||
* @param ap List of arguments.
|
||||
*
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int esp_apptrace_vprintf(const char *fmt, va_list ap);
|
||||
|
||||
/**
|
||||
* @brief Flushes remaining data in trace buffer to host.
|
||||
*
|
||||
* @param dest Indicates HW interface to flush data on.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Flushes remaining data in trace buffer to host without locking internal data.
|
||||
* This is special version of esp_apptrace_flush which should be called from panic handler.
|
||||
*
|
||||
* @param dest Indicates HW interface to flush data on.
|
||||
* @param min_sz Threshold for flushing data. If current filling level is above this value, data will be flushed. TRAX destinations only.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Reads host data from trace buffer.
|
||||
*
|
||||
* @param dest Indicates HW interface to read the data on.
|
||||
* @param data Address of buffer to put data from trace buffer.
|
||||
* @param size Pointer to store size of read data. Before call to this function pointed memory must hold requested size of data
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *data, uint32_t *size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Retrieves incoming data buffer if any.
|
||||
* After data in buffer are processed esp_apptrace_down_buffer_put must be called to indicate it.
|
||||
*
|
||||
* @param dest Indicates HW interface to receive data.
|
||||
* @param size Address to store size of available data in down buffer. Must be initialized with requested value.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return non-NULL on success, otherwise NULL.
|
||||
*/
|
||||
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Indicates that the data in down buffer are processed.
|
||||
* This function is a counterpart of and must be preceeded by esp_apptrace_down_buffer_get.
|
||||
*
|
||||
* @param dest Indicates HW interface to receive data. Should be identical to the same parameter in call to esp_apptrace_down_buffer_get.
|
||||
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_down_buffer_get.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Checks whether host is connected.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
*
|
||||
* @return true if host is connected, otherwise false
|
||||
*/
|
||||
bool esp_apptrace_host_is_connected(esp_apptrace_dest_t dest);
|
||||
|
||||
/**
|
||||
* @brief Opens file on host.
|
||||
* This function has the same semantic as 'fopen' except for the first argument.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
* @param path Path to file.
|
||||
* @param mode Mode string. See fopen for details.
|
||||
*
|
||||
* @return non zero file handle on success, otherwise 0
|
||||
*/
|
||||
void *esp_apptrace_fopen(esp_apptrace_dest_t dest, const char *path, const char *mode);
|
||||
|
||||
/**
|
||||
* @brief Closes file on host.
|
||||
* This function has the same semantic as 'fclose' except for the first argument.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
* @param stream File handle returned by esp_apptrace_fopen.
|
||||
*
|
||||
* @return Zero on success, otherwise non-zero. See fclose for details.
|
||||
*/
|
||||
int esp_apptrace_fclose(esp_apptrace_dest_t dest, void *stream);
|
||||
|
||||
/**
|
||||
* @brief Writes to file on host.
|
||||
* This function has the same semantic as 'fwrite' except for the first argument.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
* @param ptr Address of data to write.
|
||||
* @param size Size of an item.
|
||||
* @param nmemb Number of items to write.
|
||||
* @param stream File handle returned by esp_apptrace_fopen.
|
||||
*
|
||||
* @return Number of written items. See fwrite for details.
|
||||
*/
|
||||
size_t esp_apptrace_fwrite(esp_apptrace_dest_t dest, const void *ptr, size_t size, size_t nmemb, void *stream);
|
||||
|
||||
/**
|
||||
* @brief Read file on host.
|
||||
* This function has the same semantic as 'fread' except for the first argument.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
* @param ptr Address to store read data.
|
||||
* @param size Size of an item.
|
||||
* @param nmemb Number of items to read.
|
||||
* @param stream File handle returned by esp_apptrace_fopen.
|
||||
*
|
||||
* @return Number of read items. See fread for details.
|
||||
*/
|
||||
size_t esp_apptrace_fread(esp_apptrace_dest_t dest, void *ptr, size_t size, size_t nmemb, void *stream);
|
||||
|
||||
/**
|
||||
* @brief Set position indicator in file on host.
|
||||
* This function has the same semantic as 'fseek' except for the first argument.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
* @param stream File handle returned by esp_apptrace_fopen.
|
||||
* @param offset Offset. See fseek for details.
|
||||
* @param whence Position in file. See fseek for details.
|
||||
*
|
||||
* @return Zero on success, otherwise non-zero. See fseek for details.
|
||||
*/
|
||||
int esp_apptrace_fseek(esp_apptrace_dest_t dest, void *stream, long offset, int whence);
|
||||
|
||||
/**
|
||||
* @brief Get current position indicator for file on host.
|
||||
* This function has the same semantic as 'ftell' except for the first argument.
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
* @param stream File handle returned by esp_apptrace_fopen.
|
||||
*
|
||||
* @return Current position in file. See ftell for details.
|
||||
*/
|
||||
int esp_apptrace_ftell(esp_apptrace_dest_t dest, void *stream);
|
||||
|
||||
/**
|
||||
* @brief Indicates to the host that all file operations are completed.
|
||||
* This function should be called after all file operations are finished and
|
||||
* indicate to the host that it can perform cleanup operations (close open files etc.).
|
||||
*
|
||||
* @param dest Indicates HW interface to use.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
int esp_apptrace_fstop(esp_apptrace_dest_t dest);
|
||||
|
||||
/**
|
||||
* @brief Triggers gcov info dump.
|
||||
* This function waits for the host to connect to target before dumping data.
|
||||
*/
|
||||
void esp_gcov_dump(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
192
tools/sdk/esp32/include/app_trace/include/esp_app_trace_util.h
Normal file
192
tools/sdk/esp32/include/app_trace/include/esp_app_trace_util.h
Normal file
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ESP_APP_TRACE_UTIL_H_
|
||||
#define ESP_APP_TRACE_UTIL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
/** Infinite waiting timeout */
|
||||
#define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
|
||||
|
||||
/** Structure which holds data necessary for measuring time intervals.
|
||||
*
|
||||
* After initialization via esp_apptrace_tmo_init() user needs to call esp_apptrace_tmo_check()
|
||||
* periodically to check timeout for expiration.
|
||||
*/
|
||||
typedef struct {
|
||||
int64_t start; ///< time interval start (in us)
|
||||
int64_t tmo; ///< timeout value (in us)
|
||||
int64_t elapsed; ///< elapsed time (in us)
|
||||
} esp_apptrace_tmo_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes timeout structure.
|
||||
*
|
||||
* @param tmo Pointer to timeout structure to be initialized.
|
||||
* @param user_tmo Timeout value (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*/
|
||||
static inline void esp_apptrace_tmo_init(esp_apptrace_tmo_t *tmo, uint32_t user_tmo)
|
||||
{
|
||||
tmo->start = esp_timer_get_time();
|
||||
tmo->tmo = user_tmo == ESP_APPTRACE_TMO_INFINITE ? (int64_t)-1 : (int64_t)user_tmo;
|
||||
tmo->elapsed = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks timeout for expiration.
|
||||
*
|
||||
* @param tmo Pointer to timeout structure.
|
||||
*
|
||||
* @return number of remaining us till tmo.
|
||||
*/
|
||||
esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo);
|
||||
|
||||
static inline uint32_t esp_apptrace_tmo_remaining_us(esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
return tmo->tmo != (int64_t)-1 ? (tmo->elapsed - tmo->tmo) : ESP_APPTRACE_TMO_INFINITE;
|
||||
}
|
||||
|
||||
/** Tracing module synchronization lock */
|
||||
typedef struct {
|
||||
portMUX_TYPE mux;
|
||||
unsigned int_state;
|
||||
} esp_apptrace_lock_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes lock structure.
|
||||
*
|
||||
* @param lock Pointer to lock structure to be initialized.
|
||||
*/
|
||||
static inline void esp_apptrace_lock_init(esp_apptrace_lock_t *lock)
|
||||
{
|
||||
portMUX_INITIALIZE(&lock->mux);
|
||||
lock->int_state = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tries to acquire lock in specified time period.
|
||||
*
|
||||
* @param lock Pointer to lock structure.
|
||||
* @param tmo Pointer to timeout struct.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, esp_apptrace_tmo_t *tmo);
|
||||
|
||||
/**
|
||||
* @brief Releases lock.
|
||||
*
|
||||
* @param lock Pointer to lock structure.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_lock_give(esp_apptrace_lock_t *lock);
|
||||
|
||||
/** Ring buffer control structure.
|
||||
*
|
||||
* @note For purposes of application tracing module if there is no enough space for user data and write pointer can be wrapped
|
||||
* current ring buffer size can be temporarily shrinked in order to provide buffer with requested size.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t *data; ///< pointer to data storage
|
||||
volatile uint32_t size; ///< size of data storage
|
||||
volatile uint32_t cur_size; ///< current size of data storage
|
||||
volatile uint32_t rd; ///< read pointer
|
||||
volatile uint32_t wr; ///< write pointer
|
||||
} esp_apptrace_rb_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes ring buffer control structure.
|
||||
*
|
||||
* @param rb Pointer to ring buffer structure to be initialized.
|
||||
* @param data Pointer to buffer to be used as ring buffer's data storage.
|
||||
* @param size Size of buffer to be used as ring buffer's data storage.
|
||||
*/
|
||||
static inline void esp_apptrace_rb_init(esp_apptrace_rb_t *rb, uint8_t *data, uint32_t size)
|
||||
{
|
||||
rb->data = data;
|
||||
rb->size = rb->cur_size = size;
|
||||
rb->rd = 0;
|
||||
rb->wr = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocates memory chunk in ring buffer.
|
||||
*
|
||||
* @param rb Pointer to ring buffer structure.
|
||||
* @param size Size of the memory to allocate.
|
||||
*
|
||||
* @return Pointer to the allocated memory or NULL in case of failure.
|
||||
*/
|
||||
uint8_t *esp_apptrace_rb_produce(esp_apptrace_rb_t *rb, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Consumes memory chunk in ring buffer.
|
||||
*
|
||||
* @param rb Pointer to ring buffer structure.
|
||||
* @param size Size of the memory to consume.
|
||||
*
|
||||
* @return Pointer to consumed memory chunk or NULL in case of failure.
|
||||
*/
|
||||
uint8_t *esp_apptrace_rb_consume(esp_apptrace_rb_t *rb, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Gets size of memory which can consumed with single call to esp_apptrace_rb_consume().
|
||||
*
|
||||
* @param rb Pointer to ring buffer structure.
|
||||
*
|
||||
* @return Size of memory which can consumed.
|
||||
*
|
||||
* @note Due to read pointer wrapping returned size can be less then the total size of available data.
|
||||
*/
|
||||
uint32_t esp_apptrace_rb_read_size_get(esp_apptrace_rb_t *rb);
|
||||
|
||||
/**
|
||||
* @brief Gets size of memory which can produced with single call to esp_apptrace_rb_produce().
|
||||
*
|
||||
* @param rb Pointer to ring buffer structure.
|
||||
*
|
||||
* @return Size of memory which can produced.
|
||||
*
|
||||
* @note Due to write pointer wrapping returned size can be less then the total size of available data.
|
||||
*/
|
||||
uint32_t esp_apptrace_rb_write_size_get(esp_apptrace_rb_t *rb);
|
||||
|
||||
int esp_apptrace_log_lock(void);
|
||||
void esp_apptrace_log_unlock(void);
|
||||
|
||||
#define ESP_APPTRACE_LOG( format, ... ) \
|
||||
do { \
|
||||
esp_apptrace_log_lock(); \
|
||||
esp_rom_printf(format, ##__VA_ARGS__); \
|
||||
esp_apptrace_log_unlock(); \
|
||||
} while(0)
|
||||
|
||||
#define ESP_APPTRACE_LOG_LEV( _L_, level, format, ... ) \
|
||||
do { \
|
||||
if (LOG_LOCAL_LEVEL >= level) { \
|
||||
ESP_APPTRACE_LOG(LOG_FORMAT(_L_, format), esp_log_early_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ESP_APPTRACE_LOGE( format, ... ) ESP_APPTRACE_LOG_LEV(E, ESP_LOG_ERROR, format, ##__VA_ARGS__)
|
||||
#define ESP_APPTRACE_LOGW( format, ... ) ESP_APPTRACE_LOG_LEV(W, ESP_LOG_WARN, format, ##__VA_ARGS__)
|
||||
#define ESP_APPTRACE_LOGI( format, ... ) ESP_APPTRACE_LOG_LEV(I, ESP_LOG_INFO, format, ##__VA_ARGS__)
|
||||
#define ESP_APPTRACE_LOGD( format, ... ) ESP_APPTRACE_LOG_LEV(D, ESP_LOG_DEBUG, format, ##__VA_ARGS__)
|
||||
#define ESP_APPTRACE_LOGV( format, ... ) ESP_APPTRACE_LOG_LEV(V, ESP_LOG_VERBOSE, format, ##__VA_ARGS__)
|
||||
#define ESP_APPTRACE_LOGO( format, ... ) ESP_APPTRACE_LOG_LEV(E, ESP_LOG_NONE, format, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ESP_APP_TRACE_UTIL_H_
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ESP_SYSVIEW_TRACE_H_
|
||||
#define ESP_SYSVIEW_TRACE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "esp_err.h"
|
||||
#include "SEGGER_RTT.h" // SEGGER_RTT_ESP_Flush
|
||||
#include "esp_app_trace_util.h" // ESP_APPTRACE_TMO_INFINITE
|
||||
|
||||
/**
|
||||
* @brief Flushes remaining data in SystemView trace buffer to host.
|
||||
*
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return ESP_OK.
|
||||
*/
|
||||
static inline esp_err_t esp_sysview_flush(uint32_t tmo)
|
||||
{
|
||||
SEGGER_RTT_ESP_Flush(0, tmo);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief vprintf-like function to sent log messages to the host.
|
||||
*
|
||||
* @param format Address of format string.
|
||||
* @param args List of arguments.
|
||||
*
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int esp_sysview_vprintf(const char * format, va_list args);
|
||||
|
||||
/**
|
||||
* @brief Starts SystemView heap tracing.
|
||||
*
|
||||
* @param tmo Timeout (in us) to wait for the host to be connected. Use -1 to wait forever.
|
||||
*
|
||||
* @return ESP_OK on success, ESP_ERR_TIMEOUT if operation has been timed out.
|
||||
*/
|
||||
esp_err_t esp_sysview_heap_trace_start(uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Stops SystemView heap tracing.
|
||||
*
|
||||
* @return ESP_OK.
|
||||
*/
|
||||
esp_err_t esp_sysview_heap_trace_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Sends heap allocation event to the host.
|
||||
*
|
||||
* @param addr Address of allocated block.
|
||||
* @param size Size of allocated block.
|
||||
* @param callers Pointer to array with callstack addresses.
|
||||
* Array size must be CONFIG_HEAP_TRACING_STACK_DEPTH.
|
||||
*/
|
||||
void esp_sysview_heap_trace_alloc(void *addr, uint32_t size, const void *callers);
|
||||
|
||||
/**
|
||||
* @brief Sends heap de-allocation event to the host.
|
||||
*
|
||||
* @param addr Address of de-allocated block.
|
||||
* @param callers Pointer to array with callstack addresses.
|
||||
* Array size must be CONFIG_HEAP_TRACING_STACK_DEPTH.
|
||||
*/
|
||||
void esp_sysview_heap_trace_free(void *addr, const void *callers);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ESP_SYSVIEW_TRACE_H_
|
348
tools/sdk/esp32/include/app_update/include/esp_ota_ops.h
Normal file
348
tools/sdk/esp32/include/app_update/include/esp_ota_ops.h
Normal file
@ -0,0 +1,348 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _OTA_OPS_H
|
||||
#define _OTA_OPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define OTA_SIZE_UNKNOWN 0xffffffff /*!< Used for esp_ota_begin() if new image size is unknown */
|
||||
#define OTA_WITH_SEQUENTIAL_WRITES 0xfffffffe /*!< Used for esp_ota_begin() if new image size is unknown and erase can be done in incremental manner (assuming write operation is in continuous sequence) */
|
||||
|
||||
#define ESP_ERR_OTA_BASE 0x1500 /*!< Base error code for ota_ops api */
|
||||
#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< Error if request was to write or erase the current running partition */
|
||||
#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< Error if OTA data partition contains invalid content */
|
||||
#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< Error if OTA app image is invalid */
|
||||
#define ESP_ERR_OTA_SMALL_SEC_VER (ESP_ERR_OTA_BASE + 0x04) /*!< Error if the firmware has a secure version less than the running firmware. */
|
||||
#define ESP_ERR_OTA_ROLLBACK_FAILED (ESP_ERR_OTA_BASE + 0x05) /*!< Error if flash does not have valid firmware in passive partition and hence rollback is not possible */
|
||||
#define ESP_ERR_OTA_ROLLBACK_INVALID_STATE (ESP_ERR_OTA_BASE + 0x06) /*!< Error if current active firmware is still marked in pending validation state (ESP_OTA_IMG_PENDING_VERIFY), essentially first boot of firmware image post upgrade and hence firmware upgrade is not possible */
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opaque handle for an application OTA update
|
||||
*
|
||||
* esp_ota_begin() returns a handle which is then used for subsequent
|
||||
* calls to esp_ota_write() and esp_ota_end().
|
||||
*/
|
||||
typedef uint32_t esp_ota_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Return esp_app_desc structure. This structure includes app version.
|
||||
*
|
||||
* Return description for running app.
|
||||
* @return Pointer to esp_app_desc structure.
|
||||
*/
|
||||
const esp_app_desc_t *esp_ota_get_app_description(void);
|
||||
|
||||
/**
|
||||
* @brief Fill the provided buffer with SHA256 of the ELF file, formatted as hexadecimal, null-terminated.
|
||||
* If the buffer size is not sufficient to fit the entire SHA256 in hex plus a null terminator,
|
||||
* the largest possible number of bytes will be written followed by a null.
|
||||
* @param dst Destination buffer
|
||||
* @param size Size of the buffer
|
||||
* @return Number of bytes written to dst (including null terminator)
|
||||
*/
|
||||
int esp_ota_get_app_elf_sha256(char* dst, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Commence an OTA update writing to the specified partition.
|
||||
|
||||
* The specified partition is erased to the specified image size.
|
||||
*
|
||||
* If image size is not yet known, pass OTA_SIZE_UNKNOWN which will
|
||||
* cause the entire partition to be erased.
|
||||
*
|
||||
* On success, this function allocates memory that remains in use
|
||||
* until esp_ota_end() is called with the returned handle.
|
||||
*
|
||||
* Note: If the rollback option is enabled and the running application has the ESP_OTA_IMG_PENDING_VERIFY state then
|
||||
* it will lead to the ESP_ERR_OTA_ROLLBACK_INVALID_STATE error. Confirm the running app before to run download a new app,
|
||||
* use esp_ota_mark_app_valid_cancel_rollback() function for it (this should be done as early as possible when you first download a new application).
|
||||
*
|
||||
* @param partition Pointer to info for partition which will receive the OTA update. Required.
|
||||
* @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased.
|
||||
* @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls.
|
||||
|
||||
* @return
|
||||
* - ESP_OK: OTA operation commenced successfully.
|
||||
* - ESP_ERR_INVALID_ARG: partition or out_handle arguments were NULL, or partition doesn't point to an OTA app partition.
|
||||
* - ESP_ERR_NO_MEM: Cannot allocate memory for OTA operation.
|
||||
* - ESP_ERR_OTA_PARTITION_CONFLICT: Partition holds the currently running firmware, cannot update in place.
|
||||
* - ESP_ERR_NOT_FOUND: Partition argument not found in partition table.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: The OTA data partition contains invalid data.
|
||||
* - ESP_ERR_INVALID_SIZE: Partition doesn't fit in configured flash size.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_ROLLBACK_INVALID_STATE: If the running app has not confirmed state. Before performing an update, the application must be valid.
|
||||
*/
|
||||
esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
|
||||
|
||||
/**
|
||||
* @brief Write OTA update data to partition
|
||||
*
|
||||
* This function can be called multiple times as
|
||||
* data is received during the OTA operation. Data is written
|
||||
* sequentially to the partition.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin
|
||||
* @param data Data buffer to write
|
||||
* @param size Size of data buffer in bytes.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Data was written to flash successfully.
|
||||
* - ESP_ERR_INVALID_ARG: handle is invalid.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
|
||||
*/
|
||||
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Write OTA update data to partition
|
||||
*
|
||||
* This function can write data in non contiguous manner.
|
||||
* If flash encryption is enabled, data should be 16 byte aligned.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin
|
||||
* @param data Data buffer to write
|
||||
* @param size Size of data buffer in bytes
|
||||
* @param offset Offset in flash partition
|
||||
*
|
||||
* @note While performing OTA, if the packets arrive out of order, esp_ota_write_with_offset() can be used to write data in non contiguous manner.
|
||||
* Use of esp_ota_write_with_offset() in combination with esp_ota_write() is not recommended.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Data was written to flash successfully.
|
||||
* - ESP_ERR_INVALID_ARG: handle is invalid.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
|
||||
*/
|
||||
esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, size_t size, uint32_t offset);
|
||||
|
||||
/**
|
||||
* @brief Finish OTA update and validate newly written app image.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin().
|
||||
*
|
||||
* @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result).
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Newly written OTA app image is valid.
|
||||
* - ESP_ERR_NOT_FOUND: OTA handle was not found.
|
||||
* - ESP_ERR_INVALID_ARG: Handle was never written to.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: OTA image is invalid (either not a valid app image, or - if secure boot is enabled - signature failed to verify.)
|
||||
* - ESP_ERR_INVALID_STATE: If flash encryption is enabled, this result indicates an internal error writing the final encrypted bytes to flash.
|
||||
*/
|
||||
esp_err_t esp_ota_end(esp_ota_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Abort OTA update, free the handle and memory associated with it.
|
||||
*
|
||||
* @param handle obtained from esp_ota_begin().
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Handle and its associated memory is freed successfully.
|
||||
* - ESP_ERR_NOT_FOUND: OTA handle was not found.
|
||||
*/
|
||||
esp_err_t esp_ota_abort(esp_ota_handle_t handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure OTA data for a new boot partition
|
||||
*
|
||||
* @note If this function returns ESP_OK, calling esp_restart() will boot the newly configured app partition.
|
||||
*
|
||||
* @param partition Pointer to info for partition containing app image to boot.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: OTA data updated, next reboot will use specified partition.
|
||||
* - ESP_ERR_INVALID_ARG: partition argument was NULL or didn't point to a valid OTA partition of type "app".
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: Partition contained invalid app image. Also returned if secure boot is enabled and signature validation failed.
|
||||
* - ESP_ERR_NOT_FOUND: OTA data partition not found.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash erase or write failed.
|
||||
*/
|
||||
esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
|
||||
|
||||
/**
|
||||
* @brief Get partition info of currently configured boot app
|
||||
*
|
||||
* If esp_ota_set_boot_partition() has been called, the partition which was set by that function will be returned.
|
||||
*
|
||||
* If esp_ota_set_boot_partition() has not been called, the result is usually the same as esp_ota_get_running_partition().
|
||||
* The two results are not equal if the configured boot partition does not contain a valid app (meaning that the running partition
|
||||
* will be an app that the bootloader chose via fallback).
|
||||
*
|
||||
* If the OTA data partition is not present or not valid then the result is the first app partition found in the
|
||||
* partition table. In priority order, this means: the factory app, the first OTA app slot, or the test app partition.
|
||||
*
|
||||
* Note that there is no guarantee the returned partition is a valid app. Use esp_image_verify(ESP_IMAGE_VERIFY, ...) to verify if the
|
||||
* returned partition contains a bootable image.
|
||||
*
|
||||
* @return Pointer to info for partition structure, or NULL if partition table is invalid or a flash read operation failed. Any returned pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_boot_partition(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get partition info of currently running app
|
||||
*
|
||||
* This function is different to esp_ota_get_boot_partition() in that
|
||||
* it ignores any change of selected boot partition caused by
|
||||
* esp_ota_set_boot_partition(). Only the app whose code is currently
|
||||
* running will have its partition information returned.
|
||||
*
|
||||
* The partition returned by this function may also differ from esp_ota_get_boot_partition() if the configured boot
|
||||
* partition is somehow invalid, and the bootloader fell back to a different app partition at boot.
|
||||
*
|
||||
* @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_running_partition(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the next OTA app partition which should be written with a new firmware.
|
||||
*
|
||||
* Call this function to find an OTA app partition which can be passed to esp_ota_begin().
|
||||
*
|
||||
* Finds next partition round-robin, starting from the current running partition.
|
||||
*
|
||||
* @param start_from If set, treat this partition info as describing the current running partition. Can be NULL, in which case esp_ota_get_running_partition() is used to find the currently running partition. The result of this function is never the same as this argument.
|
||||
*
|
||||
* @return Pointer to info for partition which should be updated next. NULL result indicates invalid OTA data partition, or that no eligible OTA app slot partition was found.
|
||||
*
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_next_update_partition(const esp_partition_t *start_from);
|
||||
|
||||
/**
|
||||
* @brief Returns esp_app_desc structure for app partition. This structure includes app version.
|
||||
*
|
||||
* Returns a description for the requested app partition.
|
||||
* @param[in] partition Pointer to app partition. (only app partition)
|
||||
* @param[out] app_desc Structure of info about app.
|
||||
* @return
|
||||
* - ESP_OK Successful.
|
||||
* - ESP_ERR_NOT_FOUND app_desc structure is not found. Magic word is incorrect.
|
||||
* - ESP_ERR_NOT_SUPPORTED Partition is not application.
|
||||
* - ESP_ERR_INVALID_ARG Arguments is NULL or if partition's offset exceeds partition size.
|
||||
* - ESP_ERR_INVALID_SIZE Read would go out of bounds of the partition.
|
||||
* - or one of error codes from lower-level flash driver.
|
||||
*/
|
||||
esp_err_t esp_ota_get_partition_description(const esp_partition_t *partition, esp_app_desc_t *app_desc);
|
||||
|
||||
/**
|
||||
* @brief Returns number of ota partitions provided in partition table.
|
||||
*
|
||||
* @return
|
||||
* - Number of OTA partitions
|
||||
*/
|
||||
uint8_t esp_ota_get_app_partition_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to indicate that the running app is working well.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: if successful.
|
||||
*/
|
||||
esp_err_t esp_ota_mark_app_valid_cancel_rollback(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to roll back to the previously workable app with reboot.
|
||||
*
|
||||
* If rollback is successful then device will reset else API will return with error code.
|
||||
* Checks applications on a flash drive that can be booted in case of rollback.
|
||||
* If the flash does not have at least one app (except the running app) then rollback is not possible.
|
||||
* @return
|
||||
* - ESP_FAIL: if not successful.
|
||||
* - ESP_ERR_OTA_ROLLBACK_FAILED: The rollback is not possible due to flash does not have any apps.
|
||||
*/
|
||||
esp_err_t esp_ota_mark_app_invalid_rollback_and_reboot(void);
|
||||
|
||||
/**
|
||||
* @brief Returns last partition with invalid state (ESP_OTA_IMG_INVALID or ESP_OTA_IMG_ABORTED).
|
||||
*
|
||||
* @return partition.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_last_invalid_partition(void);
|
||||
|
||||
/**
|
||||
* @brief Returns state for given partition.
|
||||
*
|
||||
* @param[in] partition Pointer to partition.
|
||||
* @param[out] ota_state state of partition (if this partition has a record in otadata).
|
||||
* @return
|
||||
* - ESP_OK: Successful.
|
||||
* - ESP_ERR_INVALID_ARG: partition or ota_state arguments were NULL.
|
||||
* - ESP_ERR_NOT_SUPPORTED: partition is not ota.
|
||||
* - ESP_ERR_NOT_FOUND: Partition table does not have otadata or state was not found for given partition.
|
||||
*/
|
||||
esp_err_t esp_ota_get_state_partition(const esp_partition_t *partition, esp_ota_img_states_t *ota_state);
|
||||
|
||||
/**
|
||||
* @brief Erase previous boot app partition and corresponding otadata select for this partition.
|
||||
*
|
||||
* When current app is marked to as valid then you can erase previous app partition.
|
||||
* @return
|
||||
* - ESP_OK: Successful, otherwise ESP_ERR.
|
||||
*/
|
||||
esp_err_t esp_ota_erase_last_boot_app_partition(void);
|
||||
|
||||
/**
|
||||
* @brief Checks applications on the slots which can be booted in case of rollback.
|
||||
*
|
||||
* These applications should be valid (marked in otadata as not UNDEFINED, INVALID or ABORTED and crc is good) and be able booted,
|
||||
* and secure_version of app >= secure_version of efuse (if anti-rollback is enabled).
|
||||
*
|
||||
* @return
|
||||
* - True: Returns true if the slots have at least one app (except the running app).
|
||||
* - False: The rollback is not possible.
|
||||
*/
|
||||
bool esp_ota_check_rollback_is_possible(void);
|
||||
|
||||
#if SOC_EFUSE_SECURE_BOOT_KEY_DIGESTS > 1 && (CONFIG_SECURE_BOOT_V2_ENABLED || __DOXYGEN__)
|
||||
|
||||
/**
|
||||
* Secure Boot V2 public key indexes.
|
||||
*/
|
||||
typedef enum {
|
||||
SECURE_BOOT_PUBLIC_KEY_INDEX_0, /*!< Points to the 0th index of the Secure Boot v2 public key */
|
||||
SECURE_BOOT_PUBLIC_KEY_INDEX_1, /*!< Points to the 1st index of the Secure Boot v2 public key */
|
||||
SECURE_BOOT_PUBLIC_KEY_INDEX_2 /*!< Points to the 2nd index of the Secure Boot v2 public key */
|
||||
} esp_ota_secure_boot_public_key_index_t;
|
||||
|
||||
/**
|
||||
* @brief Revokes the old signature digest. To be called in the application after the rollback logic.
|
||||
*
|
||||
* Relevant for Secure boot v2 on ESP32-S2, ESP32-S3, ESP32-C3 where upto 3 key digests can be stored (Key \#N-1, Key \#N, Key \#N+1).
|
||||
* When key \#N-1 used to sign an app is invalidated, an OTA update is to be sent with an app signed with key \#N-1 & Key \#N.
|
||||
* After successfully booting the OTA app should call this function to revoke Key \#N-1.
|
||||
*
|
||||
* @param index - The index of the signature block to be revoked
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: If revocation is successful.
|
||||
* - ESP_ERR_INVALID_ARG: If the index of the public key to be revoked is incorrect.
|
||||
* - ESP_FAIL: If secure boot v2 has not been enabled.
|
||||
*/
|
||||
esp_err_t esp_ota_revoke_secure_boot_public_key(esp_ota_secure_boot_public_key_index_t index);
|
||||
#endif /* SOC_EFUSE_SECURE_BOOT_KEY_DIGESTS > 1 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OTA_OPS_H */
|
151
tools/sdk/esp32/include/asio/asio/asio/include/asio.hpp
Normal file
151
tools/sdk/esp32/include/asio/asio/asio/include/asio.hpp
Normal file
@ -0,0 +1,151 @@
|
||||
//
|
||||
// asio.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_HPP
|
||||
#define ASIO_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#if defined(ESP_PLATFORM)
|
||||
# include "esp_asio_config.h"
|
||||
#endif // defined(ESP_PLATFORM)
|
||||
|
||||
#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"
|
||||
#include "asio/basic_raw_socket.hpp"
|
||||
#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"
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
#include "asio/basic_streambuf.hpp"
|
||||
#include "asio/basic_waitable_timer.hpp"
|
||||
#include "asio/bind_executor.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/buffered_read_stream_fwd.hpp"
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
#include "asio/buffered_stream_fwd.hpp"
|
||||
#include "asio/buffered_stream.hpp"
|
||||
#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/deadline_timer.hpp"
|
||||
#include "asio/defer.hpp"
|
||||
#include "asio/detached.hpp"
|
||||
#include "asio/dispatch.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/error_code.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
#include "asio/executor_work_guard.hpp"
|
||||
#include "asio/generic/basic_endpoint.hpp"
|
||||
#include "asio/generic/datagram_protocol.hpp"
|
||||
#include "asio/generic/raw_protocol.hpp"
|
||||
#include "asio/generic/seq_packet_protocol.hpp"
|
||||
#include "asio/generic/stream_protocol.hpp"
|
||||
#include "asio/handler_alloc_hook.hpp"
|
||||
#include "asio/handler_continuation_hook.hpp"
|
||||
#include "asio/handler_invoke_hook.hpp"
|
||||
#include "asio/high_resolution_timer.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/io_context_strand.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/io_service_strand.hpp"
|
||||
#include "asio/ip/address.hpp"
|
||||
#include "asio/ip/address_v4.hpp"
|
||||
#include "asio/ip/address_v4_iterator.hpp"
|
||||
#include "asio/ip/address_v4_range.hpp"
|
||||
#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"
|
||||
#include "asio/ip/basic_resolver_entry.hpp"
|
||||
#include "asio/ip/basic_resolver_iterator.hpp"
|
||||
#include "asio/ip/basic_resolver_query.hpp"
|
||||
#include "asio/ip/host_name.hpp"
|
||||
#include "asio/ip/icmp.hpp"
|
||||
#include "asio/ip/multicast.hpp"
|
||||
#include "asio/ip/resolver_base.hpp"
|
||||
#include "asio/ip/resolver_query_base.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "asio/ip/unicast.hpp"
|
||||
#include "asio/ip/v6_only.hpp"
|
||||
#include "asio/is_executor.hpp"
|
||||
#include "asio/is_read_buffered.hpp"
|
||||
#include "asio/is_write_buffered.hpp"
|
||||
#include "asio/local/basic_endpoint.hpp"
|
||||
#include "asio/local/connect_pair.hpp"
|
||||
#include "asio/local/datagram_protocol.hpp"
|
||||
#include "asio/local/stream_protocol.hpp"
|
||||
#include "asio/packaged_task.hpp"
|
||||
#include "asio/placeholders.hpp"
|
||||
#include "asio/posix/basic_descriptor.hpp"
|
||||
#include "asio/posix/basic_stream_descriptor.hpp"
|
||||
#include "asio/posix/descriptor.hpp"
|
||||
#include "asio/posix/descriptor_base.hpp"
|
||||
#include "asio/posix/stream_descriptor.hpp"
|
||||
#include "asio/post.hpp"
|
||||
#include "asio/read.hpp"
|
||||
#include "asio/read_at.hpp"
|
||||
#include "asio/read_until.hpp"
|
||||
#include "asio/redirect_error.hpp"
|
||||
#include "asio/serial_port.hpp"
|
||||
#include "asio/serial_port_base.hpp"
|
||||
#include "asio/signal_set.hpp"
|
||||
#include "asio/socket_base.hpp"
|
||||
#include "asio/steady_timer.hpp"
|
||||
#include "asio/strand.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/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/overlapped_handle.hpp"
|
||||
#include "asio/windows/overlapped_ptr.hpp"
|
||||
#include "asio/windows/random_access_handle.hpp"
|
||||
#include "asio/windows/stream_handle.hpp"
|
||||
#include "asio/write.hpp"
|
||||
#include "asio/write_at.hpp"
|
||||
|
||||
#endif // ASIO_HPP
|
@ -0,0 +1,131 @@
|
||||
//
|
||||
// associated_allocator.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_ASSOCIATED_ALLOCATOR_HPP
|
||||
#define ASIO_ASSOCIATED_ALLOCATOR_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/type_traits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename>
|
||||
struct associated_allocator_check
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <typename T, typename E, typename = void>
|
||||
struct associated_allocator_impl
|
||||
{
|
||||
typedef E type;
|
||||
|
||||
static type get(const T&, const E& e) ASIO_NOEXCEPT
|
||||
{
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename E>
|
||||
struct associated_allocator_impl<T, E,
|
||||
typename associated_allocator_check<typename T::allocator_type>::type>
|
||||
{
|
||||
typedef typename T::allocator_type type;
|
||||
|
||||
static type get(const T& t, const E&) ASIO_NOEXCEPT
|
||||
{
|
||||
return t.get_allocator();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Traits type used to obtain the allocator associated with an object.
|
||||
/**
|
||||
* A program may specialise this traits type if the @c T template parameter in
|
||||
* the specialisation is a user-defined type. The template parameter @c
|
||||
* Allocator shall be a type meeting the Allocator requirements.
|
||||
*
|
||||
* Specialisations shall meet the following requirements, where @c t is a const
|
||||
* reference to an object of type @c T, and @c a is an object of type @c
|
||||
* Allocator.
|
||||
*
|
||||
* @li Provide a nested typedef @c type that identifies a type meeting the
|
||||
* Allocator requirements.
|
||||
*
|
||||
* @li Provide a noexcept static member function named @c get, callable as @c
|
||||
* get(t) and with return type @c type.
|
||||
*
|
||||
* @li Provide a noexcept static member function named @c get, callable as @c
|
||||
* get(t,a) and with return type @c type.
|
||||
*/
|
||||
template <typename T, typename Allocator = std::allocator<void> >
|
||||
struct associated_allocator
|
||||
{
|
||||
/// If @c T has a nested type @c allocator_type, <tt>T::allocator_type</tt>.
|
||||
/// Otherwise @c Allocator.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef see_below type;
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
typedef typename detail::associated_allocator_impl<T, Allocator>::type type;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// If @c T has a nested type @c allocator_type, returns
|
||||
/// <tt>t.get_allocator()</tt>. Otherwise returns @c a.
|
||||
static type get(const T& t,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return detail::associated_allocator_impl<T, Allocator>::get(t, a);
|
||||
}
|
||||
};
|
||||
|
||||
/// Helper function to obtain an object's associated allocator.
|
||||
/**
|
||||
* @returns <tt>associated_allocator<T>::get(t)</tt>
|
||||
*/
|
||||
template <typename T>
|
||||
inline typename associated_allocator<T>::type
|
||||
get_associated_allocator(const T& t) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<T>::get(t);
|
||||
}
|
||||
|
||||
/// Helper function to obtain an object's associated allocator.
|
||||
/**
|
||||
* @returns <tt>associated_allocator<T, Allocator>::get(t, a)</tt>
|
||||
*/
|
||||
template <typename T, typename Allocator>
|
||||
inline typename associated_allocator<T, Allocator>::type
|
||||
get_associated_allocator(const T& t, const Allocator& a) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<T, Allocator>::get(t, a);
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
|
||||
|
||||
template <typename T, typename Allocator = std::allocator<void> >
|
||||
using associated_allocator_t
|
||||
= typename associated_allocator<T, Allocator>::type;
|
||||
|
||||
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_ASSOCIATED_ALLOCATOR_HPP
|
@ -0,0 +1,149 @@
|
||||
//
|
||||
// associated_executor.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_ASSOCIATED_EXECUTOR_HPP
|
||||
#define ASIO_ASSOCIATED_EXECUTOR_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/is_executor.hpp"
|
||||
#include "asio/system_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename>
|
||||
struct associated_executor_check
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <typename T, typename E, typename = void>
|
||||
struct associated_executor_impl
|
||||
{
|
||||
typedef E type;
|
||||
|
||||
static type get(const T&, const E& e) ASIO_NOEXCEPT
|
||||
{
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename E>
|
||||
struct associated_executor_impl<T, E,
|
||||
typename associated_executor_check<typename T::executor_type>::type>
|
||||
{
|
||||
typedef typename T::executor_type type;
|
||||
|
||||
static type get(const T& t, const E&) ASIO_NOEXCEPT
|
||||
{
|
||||
return t.get_executor();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Traits type used to obtain the executor associated with an object.
|
||||
/**
|
||||
* A program may specialise this traits type if the @c T template parameter in
|
||||
* the specialisation is a user-defined type. The template parameter @c
|
||||
* Executor shall be a type meeting the Executor requirements.
|
||||
*
|
||||
* Specialisations shall meet the following requirements, where @c t is a const
|
||||
* reference to an object of type @c T, and @c e is an object of type @c
|
||||
* Executor.
|
||||
*
|
||||
* @li Provide a nested typedef @c type that identifies a type meeting the
|
||||
* Executor requirements.
|
||||
*
|
||||
* @li Provide a noexcept static member function named @c get, callable as @c
|
||||
* get(t) and with return type @c type.
|
||||
*
|
||||
* @li Provide a noexcept static member function named @c get, callable as @c
|
||||
* get(t,e) and with return type @c type.
|
||||
*/
|
||||
template <typename T, typename Executor = system_executor>
|
||||
struct associated_executor
|
||||
{
|
||||
/// If @c T has a nested type @c executor_type, <tt>T::executor_type</tt>.
|
||||
/// Otherwise @c Executor.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef see_below type;
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
typedef typename detail::associated_executor_impl<T, Executor>::type type;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// If @c T has a nested type @c executor_type, returns
|
||||
/// <tt>t.get_executor()</tt>. Otherwise returns @c ex.
|
||||
static type get(const T& t,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return detail::associated_executor_impl<T, Executor>::get(t, ex);
|
||||
}
|
||||
};
|
||||
|
||||
/// Helper function to obtain an object's associated executor.
|
||||
/**
|
||||
* @returns <tt>associated_executor<T>::get(t)</tt>
|
||||
*/
|
||||
template <typename T>
|
||||
inline typename associated_executor<T>::type
|
||||
get_associated_executor(const T& t) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<T>::get(t);
|
||||
}
|
||||
|
||||
/// Helper function to obtain an object's associated executor.
|
||||
/**
|
||||
* @returns <tt>associated_executor<T, Executor>::get(t, ex)</tt>
|
||||
*/
|
||||
template <typename T, typename Executor>
|
||||
inline typename associated_executor<T, Executor>::type
|
||||
get_associated_executor(const T& t, const Executor& ex,
|
||||
typename enable_if<is_executor<
|
||||
Executor>::value>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<T, Executor>::get(t, ex);
|
||||
}
|
||||
|
||||
/// Helper function to obtain an object's associated executor.
|
||||
/**
|
||||
* @returns <tt>associated_executor<T, typename
|
||||
* ExecutionContext::executor_type>::get(t, ctx.get_executor())</tt>
|
||||
*/
|
||||
template <typename T, typename ExecutionContext>
|
||||
inline typename associated_executor<T,
|
||||
typename ExecutionContext::executor_type>::type
|
||||
get_associated_executor(const T& t, ExecutionContext& ctx,
|
||||
typename enable_if<is_convertible<ExecutionContext&,
|
||||
execution_context&>::value>::type* = 0) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<T,
|
||||
typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
|
||||
|
||||
template <typename T, typename Executor = system_executor>
|
||||
using associated_executor_t = typename associated_executor<T, Executor>::type;
|
||||
|
||||
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_ASSOCIATED_EXECUTOR_HPP
|
@ -0,0 +1,585 @@
|
||||
//
|
||||
// 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 {
|
||||
|
||||
#if defined(ASIO_HAS_CONCEPTS) \
|
||||
&& defined(ASIO_HAS_VARIADIC_TEMPLATES) \
|
||||
&& defined(ASIO_HAS_DECLTYPE)
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
struct is_completion_signature : false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename R, typename... Args>
|
||||
struct is_completion_signature<R(Args...)> : true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
ASIO_CONCEPT callable_with = requires(T t, Args&&... args)
|
||||
{
|
||||
t(static_cast<Args&&>(args)...);
|
||||
};
|
||||
|
||||
template <typename T, typename Signature>
|
||||
struct is_completion_handler_for : false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename R, typename... Args>
|
||||
struct is_completion_handler_for<T, R(Args...)>
|
||||
: integral_constant<bool, (callable_with<T, Args...>)>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
ASIO_CONCEPT completion_signature =
|
||||
detail::is_completion_signature<T>::value;
|
||||
|
||||
#define ASIO_COMPLETION_SIGNATURE \
|
||||
::asio::completion_signature
|
||||
|
||||
template <typename T, completion_signature Signature>
|
||||
ASIO_CONCEPT completion_handler_for =
|
||||
detail::is_completion_handler_for<T, Signature>::value;
|
||||
|
||||
#define ASIO_COMPLETION_HANDLER_FOR(s) \
|
||||
::asio::completion_handler_for<s>
|
||||
|
||||
#else // defined(ASIO_HAS_CONCEPTS)
|
||||
// && defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// && defined(ASIO_HAS_DECLTYPE)
|
||||
|
||||
#define ASIO_COMPLETION_SIGNATURE typename
|
||||
#define ASIO_COMPLETION_HANDLER_FOR(s) typename
|
||||
|
||||
#endif // defined(ASIO_HAS_CONCEPTS)
|
||||
// && defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// && defined(ASIO_HAS_DECLTYPE)
|
||||
|
||||
/// 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, ASIO_COMPLETION_SIGNATURE 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(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);
|
||||
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Initiation,
|
||||
ASIO_COMPLETION_HANDLER_FOR(Signature) 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)
|
||||
|
||||
template <typename Initiation,
|
||||
ASIO_COMPLETION_HANDLER_FOR(Signature) 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, \
|
||||
ASIO_COMPLETION_HANDLER_FOR(Signature) 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)
|
||||
|
||||
private:
|
||||
async_result(const async_result&) ASIO_DELETED;
|
||||
async_result& operator=(const async_result&) ASIO_DELETED;
|
||||
};
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <ASIO_COMPLETION_SIGNATURE Signature>
|
||||
class async_result<void, Signature>
|
||||
{
|
||||
// Empty.
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// 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, ASIO_COMPLETION_SIGNATURE 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(GENERATION_DOCUMENTATION)
|
||||
# define ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
|
||||
auto
|
||||
#elif defined(ASIO_HAS_RETURN_TYPE_DEDUCTION)
|
||||
# define ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
|
||||
auto
|
||||
#else
|
||||
# define ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
|
||||
ASIO_INITFN_RESULT_TYPE(ct, sig)
|
||||
#endif
|
||||
|
||||
#if defined(GENERATION_DOCUMENTATION)
|
||||
# define ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
|
||||
void_or_deduced
|
||||
#elif defined(ASIO_HAS_DECLTYPE)
|
||||
# define ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
|
||||
decltype expr
|
||||
#else
|
||||
# define ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
|
||||
ASIO_INITFN_RESULT_TYPE(ct, sig)
|
||||
#endif
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename CompletionToken,
|
||||
completion_signature Signature,
|
||||
typename Initiation, typename... Args>
|
||||
void_or_deduced 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,
|
||||
ASIO_COMPLETION_SIGNATURE Signature,
|
||||
typename Initiation, typename... Args>
|
||||
inline typename enable_if<
|
||||
detail::async_result_has_initiate_memfn<CompletionToken, Signature>::value,
|
||||
ASIO_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, Signature,
|
||||
(async_result<typename decay<CompletionToken>::type,
|
||||
Signature>::initiate(declval<ASIO_MOVE_ARG(Initiation)>(),
|
||||
declval<ASIO_MOVE_ARG(CompletionToken)>(),
|
||||
declval<ASIO_MOVE_ARG(Args)>()...)))>::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,
|
||||
ASIO_COMPLETION_SIGNATURE 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,
|
||||
ASIO_COMPLETION_SIGNATURE Signature,
|
||||
typename Initiation>
|
||||
inline typename enable_if<
|
||||
detail::async_result_has_initiate_memfn<CompletionToken, Signature>::value,
|
||||
ASIO_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, Signature,
|
||||
(async_result<typename decay<CompletionToken>::type,
|
||||
Signature>::initiate(declval<ASIO_MOVE_ARG(Initiation)>(),
|
||||
declval<ASIO_MOVE_ARG(CompletionToken)>())))>::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,
|
||||
ASIO_COMPLETION_SIGNATURE 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, \
|
||||
ASIO_COMPLETION_SIGNATURE Signature, \
|
||||
typename Initiation, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
inline typename enable_if< \
|
||||
detail::async_result_has_initiate_memfn< \
|
||||
CompletionToken, Signature>::value, \
|
||||
ASIO_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, Signature, \
|
||||
(async_result<typename decay<CompletionToken>::type, \
|
||||
Signature>::initiate(declval<ASIO_MOVE_ARG(Initiation)>(), \
|
||||
declval<ASIO_MOVE_ARG(CompletionToken)>(), \
|
||||
ASIO_VARIADIC_MOVE_DECLVAL(n))))>::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, \
|
||||
ASIO_COMPLETION_SIGNATURE 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)
|
||||
|
||||
#if defined(ASIO_HAS_CONCEPTS) \
|
||||
&& defined(ASIO_HAS_VARIADIC_TEMPLATES) \
|
||||
&& defined(ASIO_HAS_DECLTYPE)
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Signature>
|
||||
struct initiation_archetype
|
||||
{
|
||||
template <completion_handler_for<Signature> CompletionHandler>
|
||||
void operator()(CompletionHandler&&) const
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, completion_signature Signature>
|
||||
ASIO_CONCEPT completion_token_for = requires(T&& t)
|
||||
{
|
||||
async_initiate<T, Signature>(detail::initiation_archetype<Signature>{}, t);
|
||||
};
|
||||
|
||||
#define ASIO_COMPLETION_TOKEN_FOR(s) \
|
||||
::asio::completion_token_for<s>
|
||||
|
||||
#else // defined(ASIO_HAS_CONCEPTS)
|
||||
// && defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// && defined(ASIO_HAS_DECLTYPE)
|
||||
|
||||
#define ASIO_COMPLETION_TOKEN_FOR(s) typename
|
||||
|
||||
#endif // defined(ASIO_HAS_CONCEPTS)
|
||||
// && defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
// && defined(ASIO_HAS_DECLTYPE)
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename>
|
||||
struct default_completion_token_check
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct default_completion_token_impl
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct default_completion_token_impl<T,
|
||||
typename default_completion_token_check<
|
||||
typename T::default_completion_token_type>::type>
|
||||
{
|
||||
typedef typename T::default_completion_token_type type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Traits type used to determine the default completion token type associated
|
||||
/// with a type (such as an executor).
|
||||
/**
|
||||
* A program may specialise this traits type if the @c T template parameter in
|
||||
* the specialisation is a user-defined type.
|
||||
*
|
||||
* Specialisations of this trait may provide a nested typedef @c type, which is
|
||||
* a default-constructible completion token type.
|
||||
*/
|
||||
template <typename T>
|
||||
struct default_completion_token
|
||||
{
|
||||
/// If @c T has a nested type @c default_completion_token_type,
|
||||
/// <tt>T::default_completion_token_type</tt>. Otherwise the typedef @c type
|
||||
/// is not defined.
|
||||
typedef see_below type;
|
||||
};
|
||||
#else
|
||||
template <typename T>
|
||||
struct default_completion_token
|
||||
: detail::default_completion_token_impl<T>
|
||||
{
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
|
||||
|
||||
template <typename T>
|
||||
using default_completion_token_t = typename default_completion_token<T>::type;
|
||||
|
||||
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
|
||||
|
||||
#if defined(ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS)
|
||||
|
||||
#define ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
|
||||
= typename ::asio::default_completion_token<e>::type
|
||||
#define ASIO_DEFAULT_COMPLETION_TOKEN(e) \
|
||||
= typename ::asio::default_completion_token<e>::type()
|
||||
|
||||
#else // defined(ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS)
|
||||
|
||||
#define ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
|
||||
#define ASIO_DEFAULT_COMPLETION_TOKEN(e)
|
||||
|
||||
#endif // defined(ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_ASYNC_RESULT_HPP
|
@ -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
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,693 @@
|
||||
//
|
||||
// basic_deadline_timer.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_BASIC_DEADLINE_TIMER_HPP
|
||||
#define ASIO_BASIC_DEADLINE_TIMER_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_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <cstddef>
|
||||
#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"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides waitable timer functionality.
|
||||
/**
|
||||
* The basic_deadline_timer class template provides the ability to perform a
|
||||
* blocking or asynchronous wait for a timer to expire.
|
||||
*
|
||||
* A deadline timer is always in one of two states: "expired" or "not expired".
|
||||
* If the wait() or async_wait() function is called on an expired timer, the
|
||||
* wait operation will complete immediately.
|
||||
*
|
||||
* Most applications will use the asio::deadline_timer typedef.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Examples
|
||||
* Performing a blocking wait:
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* asio::deadline_timer timer(my_context);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_from_now(boost::posix_time::seconds(5));
|
||||
*
|
||||
* // Wait for the timer to expire.
|
||||
* timer.wait();
|
||||
* @endcode
|
||||
*
|
||||
* @par
|
||||
* Performing an asynchronous wait:
|
||||
* @code
|
||||
* void handler(const asio::error_code& error)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // Timer expired.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* asio::deadline_timer timer(my_context,
|
||||
* boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
* timer.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Changing an active deadline_timer's expiry time
|
||||
*
|
||||
* Changing the expiry time of a timer while there are pending asynchronous
|
||||
* waits causes those wait operations to be cancelled. To ensure that the action
|
||||
* associated with the timer is performed only once, use something like this:
|
||||
* used:
|
||||
*
|
||||
* @code
|
||||
* void on_some_event()
|
||||
* {
|
||||
* if (my_timer.expires_from_now(seconds(5)) > 0)
|
||||
* {
|
||||
* // We managed to cancel the timer. Start new asynchronous wait.
|
||||
* my_timer.async_wait(on_timeout);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Too late, timer has already expired!
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void on_timeout(const asio::error_code& e)
|
||||
* {
|
||||
* if (e != asio::error::operation_aborted)
|
||||
* {
|
||||
* // Timer was not cancelled, take necessary action.
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @li The asio::basic_deadline_timer::expires_from_now() function
|
||||
* cancels any pending asynchronous waits, and returns the number of
|
||||
* asynchronous waits that were cancelled. If it returns 0 then you were too
|
||||
* late and the wait handler has already been executed, or will soon be
|
||||
* executed. If it returns 1 then the wait handler was successfully cancelled.
|
||||
*
|
||||
* @li If a wait handler is cancelled, the asio::error_code passed to
|
||||
* it contains the value asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Time,
|
||||
typename TimeTraits = asio::time_traits<Time>,
|
||||
typename Executor = executor>
|
||||
class basic_deadline_timer
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the timer type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The timer type when rebound to the specified executor.
|
||||
typedef basic_deadline_timer<Time, TimeTraits, Executor1> other;
|
||||
};
|
||||
|
||||
/// The time traits type.
|
||||
typedef TimeTraits traits_type;
|
||||
|
||||
/// The time type.
|
||||
typedef typename traits_type::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename traits_type::duration_type duration_type;
|
||||
|
||||
/// 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 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(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)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @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(const executor_type& ex, const time_type& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code 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");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @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(const executor_type& ex,
|
||||
const duration_type& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code 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");
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_deadline_timer from another.
|
||||
/**
|
||||
* This constructor moves a timer from one object to another.
|
||||
*
|
||||
* @param other The other basic_deadline_timer 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_deadline_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_deadline_timer(basic_deadline_timer&& other)
|
||||
: impl_(std::move(other.impl_))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_deadline_timer from another.
|
||||
/**
|
||||
* This assignment operator moves a timer from one object to another. Cancels
|
||||
* any outstanding asynchronous operations associated with the target object.
|
||||
*
|
||||
* @param other The other basic_deadline_timer 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_deadline_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_deadline_timer& operator=(basic_deadline_timer&& other)
|
||||
{
|
||||
impl_ = std::move(other.impl_);
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destroys the timer.
|
||||
/**
|
||||
* This function destroys the timer, cancelling any outstanding asynchronous
|
||||
* wait operations associated with the timer as if by calling @c cancel.
|
||||
*/
|
||||
~basic_deadline_timer()
|
||||
{
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return impl_.get_executor();
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel(asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.get_service().cancel_one(
|
||||
impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one(asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().cancel_one(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return impl_.get_service().expires_at(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_type& expiry_time)
|
||||
{
|
||||
asio::error_code 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;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_type& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().expires_at(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return impl_.get_service().expires_from_now(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
asio::error_code 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;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration_type& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void wait()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
void wait(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* timer. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li The timer has expired.
|
||||
*
|
||||
* @li The timer was cancelled, in which case the handler is passed the error
|
||||
* code asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the timer expires. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* 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. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
|
||||
WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(
|
||||
ASIO_MOVE_ARG(WaitHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<WaitHandler, void (asio::error_code)>(
|
||||
initiate_async_wait(this), handler);
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_deadline_timer(const basic_deadline_timer&) ASIO_DELETED;
|
||||
basic_deadline_timer& operator=(
|
||||
const basic_deadline_timer&) ASIO_DELETED;
|
||||
|
||||
class initiate_async_wait
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_wait(basic_deadline_timer* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename WaitHandler>
|
||||
void operator()(ASIO_MOVE_ARG(WaitHandler) handler) 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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_deadline_timer* self_;
|
||||
};
|
||||
|
||||
detail::io_object_impl<
|
||||
detail::deadline_timer_service<TimeTraits>, Executor> impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_BASIC_DEADLINE_TIMER_HPP
|
@ -0,0 +1,290 @@
|
||||
//
|
||||
// basic_io_object.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_BASIC_IO_OBJECT_HPP
|
||||
#define ASIO_BASIC_IO_OBJECT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
namespace detail
|
||||
{
|
||||
// Type trait used to determine whether a service supports move.
|
||||
template <typename IoObjectService>
|
||||
class service_has_move
|
||||
{
|
||||
private:
|
||||
typedef IoObjectService service_type;
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
template <typename T, typename U>
|
||||
static auto asio_service_has_move_eval(T* t, U* u)
|
||||
-> decltype(t->move_construct(*u, *u), char());
|
||||
static char (&asio_service_has_move_eval(...))[2];
|
||||
|
||||
public:
|
||||
static const bool value =
|
||||
sizeof(asio_service_has_move_eval(
|
||||
static_cast<service_type*>(0),
|
||||
static_cast<implementation_type*>(0))) == 1;
|
||||
};
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
/// Base class for all I/O objects.
|
||||
/**
|
||||
* @note All I/O objects are non-copyable. However, when using C++0x, certain
|
||||
* I/O objects do support move construction and move assignment.
|
||||
*/
|
||||
#if !defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
template <typename IoObjectService>
|
||||
#else
|
||||
template <typename IoObjectService,
|
||||
bool Movable = detail::service_has_move<IoObjectService>::value>
|
||||
#endif
|
||||
class basic_io_object
|
||||
{
|
||||
public:
|
||||
/// The type of the service that will be used to provide I/O operations.
|
||||
typedef IoObjectService service_type;
|
||||
|
||||
/// The underlying implementation type of I/O object.
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
#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 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 service_.get_io_context();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// The type of the executor associated with the object.
|
||||
typedef asio::io_context::executor_type executor_type;
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return service_.get_io_context().get_executor();
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Construct a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().construct(get_implementation()); @endcode
|
||||
*/
|
||||
explicit basic_io_object(asio::io_context& io_context)
|
||||
: service_(asio::use_service<IoObjectService>(io_context))
|
||||
{
|
||||
service_.construct(implementation_);
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().move_construct(
|
||||
* get_implementation(), other.get_implementation()); @endcode
|
||||
*
|
||||
* @note Available only for services that support movability,
|
||||
*/
|
||||
basic_io_object(basic_io_object&& other);
|
||||
|
||||
/// Move-assign a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().move_assign(get_implementation(),
|
||||
* other.get_service(), other.get_implementation()); @endcode
|
||||
*
|
||||
* @note Available only for services that support movability,
|
||||
*/
|
||||
basic_io_object& operator=(basic_io_object&& other);
|
||||
|
||||
/// Perform a converting move-construction of a basic_io_object.
|
||||
template <typename IoObjectService1>
|
||||
basic_io_object(IoObjectService1& other_service,
|
||||
typename IoObjectService1::implementation_type& other_implementation);
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Protected destructor to prevent deletion through this type.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().destroy(get_implementation()); @endcode
|
||||
*/
|
||||
~basic_io_object()
|
||||
{
|
||||
service_.destroy(implementation_);
|
||||
}
|
||||
|
||||
/// Get the service associated with the I/O object.
|
||||
service_type& get_service()
|
||||
{
|
||||
return service_;
|
||||
}
|
||||
|
||||
/// Get the service associated with the I/O object.
|
||||
const service_type& get_service() const
|
||||
{
|
||||
return service_;
|
||||
}
|
||||
|
||||
/// Get the underlying implementation of the I/O object.
|
||||
implementation_type& get_implementation()
|
||||
{
|
||||
return implementation_;
|
||||
}
|
||||
|
||||
/// Get the underlying implementation of the I/O object.
|
||||
const implementation_type& get_implementation() const
|
||||
{
|
||||
return implementation_;
|
||||
}
|
||||
|
||||
private:
|
||||
basic_io_object(const basic_io_object&);
|
||||
basic_io_object& operator=(const basic_io_object&);
|
||||
|
||||
// The service associated with the I/O object.
|
||||
service_type& service_;
|
||||
|
||||
/// The underlying implementation of the I/O object.
|
||||
implementation_type implementation_;
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
// Specialisation for movable objects.
|
||||
template <typename IoObjectService>
|
||||
class basic_io_object<IoObjectService, true>
|
||||
{
|
||||
public:
|
||||
typedef IoObjectService service_type;
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
asio::io_context& get_io_context()
|
||||
{
|
||||
return service_->get_io_context();
|
||||
}
|
||||
|
||||
asio::io_context& get_io_service()
|
||||
{
|
||||
return service_->get_io_context();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
typedef asio::io_context::executor_type executor_type;
|
||||
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return service_->get_io_context().get_executor();
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit basic_io_object(asio::io_context& io_context)
|
||||
: service_(&asio::use_service<IoObjectService>(io_context))
|
||||
{
|
||||
service_->construct(implementation_);
|
||||
}
|
||||
|
||||
basic_io_object(basic_io_object&& other)
|
||||
: service_(&other.get_service())
|
||||
{
|
||||
service_->move_construct(implementation_, other.implementation_);
|
||||
}
|
||||
|
||||
template <typename IoObjectService1>
|
||||
basic_io_object(IoObjectService1& other_service,
|
||||
typename IoObjectService1::implementation_type& other_implementation)
|
||||
: service_(&asio::use_service<IoObjectService>(
|
||||
other_service.get_io_context()))
|
||||
{
|
||||
service_->converting_move_construct(implementation_,
|
||||
other_service, other_implementation);
|
||||
}
|
||||
|
||||
~basic_io_object()
|
||||
{
|
||||
service_->destroy(implementation_);
|
||||
}
|
||||
|
||||
basic_io_object& operator=(basic_io_object&& other)
|
||||
{
|
||||
service_->move_assign(implementation_,
|
||||
*other.service_, other.implementation_);
|
||||
service_ = other.service_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
service_type& get_service()
|
||||
{
|
||||
return *service_;
|
||||
}
|
||||
|
||||
const service_type& get_service() const
|
||||
{
|
||||
return *service_;
|
||||
}
|
||||
|
||||
implementation_type& get_implementation()
|
||||
{
|
||||
return implementation_;
|
||||
}
|
||||
|
||||
const implementation_type& get_implementation() const
|
||||
{
|
||||
return implementation_;
|
||||
}
|
||||
|
||||
private:
|
||||
basic_io_object(const basic_io_object&);
|
||||
void operator=(const basic_io_object&);
|
||||
|
||||
IoObjectService* service_;
|
||||
implementation_type implementation_;
|
||||
};
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_IO_OBJECT_HPP
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,756 @@
|
||||
//
|
||||
// basic_seq_packet_socket.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_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
#define ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#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
|
||||
* sequenced packet socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol, typename Executor>
|
||||
class basic_seq_packet_socket
|
||||
: 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,
|
||||
Executor>::native_handle_type native_handle_type;
|
||||
#endif
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// 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 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(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)
|
||||
{
|
||||
}
|
||||
|
||||
/// 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 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(const executor_type& ex,
|
||||
const protocol_type& 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)
|
||||
{
|
||||
}
|
||||
|
||||
/// 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 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(const executor_type& ex,
|
||||
const endpoint_type& 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)
|
||||
{
|
||||
}
|
||||
|
||||
/// 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 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.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(const executor_type& ex,
|
||||
const protocol_type& protocol, const native_handle_type& 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)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_seq_packet_socket from another.
|
||||
/**
|
||||
* This constructor moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_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_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_seq_packet_socket(basic_seq_packet_socket&& other) ASIO_NOEXCEPT
|
||||
: basic_socket<Protocol, Executor>(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_seq_packet_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_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_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_seq_packet_socket& operator=(basic_seq_packet_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_seq_packet_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_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_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
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))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_seq_packet_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This assignment operator moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_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_seq_packet_socket(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
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, Executor>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destroys the socket.
|
||||
/**
|
||||
* This function destroys the socket, cancelling any outstanding asynchronous
|
||||
* operations associated with the socket as if by calling @c cancel.
|
||||
*/
|
||||
~basic_seq_packet_socket()
|
||||
{
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the sequenced packet socket. The
|
||||
* function call will block until the data has been sent successfully, or an
|
||||
* until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code 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;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the sequenced packet socket. The
|
||||
* function call will block the data has been sent successfully, or an until
|
||||
* error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->impl_.get_service().send(
|
||||
this->impl_.get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the sequenced packet
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* 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. 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:
|
||||
* @code
|
||||
* socket.async_send(asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_send(this), handler, buffers, flags);
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(asio::buffer(data, size), out_flags);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
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;
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(asio::buffer(data, size), 0, out_flags);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
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;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags, asio::error_code& ec)
|
||||
{
|
||||
return this->impl_.get_service().receive_with_flags(
|
||||
this->impl_.get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the sequenced
|
||||
* packet socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param out_flags Once the asynchronous operation completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record. The caller must guarantee that the referenced
|
||||
* variable remains valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* 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. 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
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(asio::buffer(data, size), out_flags, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags& out_flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_with_flags(this), handler,
|
||||
buffers, socket_base::message_flags(0), &out_flags);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the sequenced
|
||||
* data socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags Once the asynchronous operation completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record. The caller must guarantee that the referenced
|
||||
* variable remains valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* 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. 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
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(
|
||||
* asio::buffer(data, size),
|
||||
* 0, out_flags, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_receive_with_flags(this),
|
||||
handler, buffers, in_flags, &out_flags);
|
||||
}
|
||||
|
||||
private:
|
||||
class initiate_async_send
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_send(basic_seq_packet_socket* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_seq_packet_socket* self_;
|
||||
};
|
||||
|
||||
class initiate_async_receive_with_flags
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_receive_with_flags(basic_seq_packet_socket* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_seq_packet_socket* self_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
@ -0,0 +1,907 @@
|
||||
//
|
||||
// basic_serial_port.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_SERIAL_PORT_HPP
|
||||
#define ASIO_BASIC_SERIAL_PORT_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_SERIAL_PORT) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <string>
|
||||
#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"
|
||||
#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"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides serial port functionality.
|
||||
/**
|
||||
* 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 Executor = executor>
|
||||
class basic_serial_port
|
||||
: public serial_port_base
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the serial port type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The serial port type when rebound to the specified executor.
|
||||
typedef basic_serial_port<Executor1> other;
|
||||
};
|
||||
|
||||
/// 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 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(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)
|
||||
{
|
||||
}
|
||||
|
||||
/// 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 char* 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 char* 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");
|
||||
}
|
||||
|
||||
/// 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");
|
||||
}
|
||||
|
||||
/// 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 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(const executor_type& ex,
|
||||
const native_handle_type& native_serial_port)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code ec;
|
||||
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");
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_serial_port from another.
|
||||
/**
|
||||
* This constructor moves a serial port from one object to another.
|
||||
*
|
||||
* @param other The other basic_serial_port 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_serial_port(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_serial_port(basic_serial_port&& other)
|
||||
: impl_(std::move(other.impl_))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_serial_port from another.
|
||||
/**
|
||||
* This assignment operator moves a serial port from one object to another.
|
||||
*
|
||||
* @param other The other basic_serial_port 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_serial_port(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_serial_port& operator=(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
|
||||
* layers. Since a basic_serial_port cannot contain any further layers, it
|
||||
* simply returns a reference to itself.
|
||||
*
|
||||
* @return A reference to the lowest layer in the stack of layers. Ownership
|
||||
* is not transferred to the caller.
|
||||
*/
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
/**
|
||||
* This function returns a const reference to the lowest layer in a stack of
|
||||
* layers. Since a basic_serial_port cannot contain any further layers, it
|
||||
* simply returns a reference to itself.
|
||||
*
|
||||
* @return A const reference to the lowest layer in the stack of layers.
|
||||
* Ownership is not transferred to the caller.
|
||||
*/
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Open the serial port using the specified device name.
|
||||
/**
|
||||
* This function opens the serial port for the specified device name.
|
||||
*
|
||||
* @param device The platform-specific device name.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void open(const std::string& device)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Open the serial port using the specified device name.
|
||||
/**
|
||||
* This function opens the serial port using the given platform-specific
|
||||
* device name.
|
||||
*
|
||||
* @param device The platform-specific device name.
|
||||
*
|
||||
* @param ec Set the indicate what error occurred, if any.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID open(const std::string& device,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().open(impl_.get_implementation(), device, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Assign an existing native serial port to the serial port.
|
||||
/*
|
||||
* This function opens the serial port to hold an existing native serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void assign(const native_handle_type& native_serial_port)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().assign(impl_.get_implementation(),
|
||||
native_serial_port, ec);
|
||||
asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
|
||||
/// Assign an existing native serial port to the serial port.
|
||||
/*
|
||||
* This function opens the serial port to hold an existing native serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID assign(const native_handle_type& native_serial_port,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().assign(impl_.get_implementation(),
|
||||
native_serial_port, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Determine whether the serial port is open.
|
||||
bool is_open() const
|
||||
{
|
||||
return impl_.get_service().is_open(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
/**
|
||||
* This function is used to close the serial port. Any asynchronous read or
|
||||
* write operations will be cancelled immediately, and will complete with the
|
||||
* asio::error::operation_aborted error.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().close(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "close");
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
/**
|
||||
* This function is used to close the serial port. Any asynchronous read or
|
||||
* write operations will be cancelled immediately, and will complete with the
|
||||
* asio::error::operation_aborted error.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID close(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().close(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Get the native serial port representation.
|
||||
/**
|
||||
* This function may be used to obtain the underlying representation of the
|
||||
* serial port. This is intended to allow access to native serial port
|
||||
* functionality that is not otherwise provided.
|
||||
*/
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return impl_.get_service().native_handle(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
/**
|
||||
* This function causes all outstanding asynchronous read or write operations
|
||||
* to finish immediately, and the handlers for cancelled operations will be
|
||||
* passed the asio::error::operation_aborted error.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
/**
|
||||
* This function causes all outstanding asynchronous read or write operations
|
||||
* to finish immediately, and the handlers for cancelled operations will be
|
||||
* passed the asio::error::operation_aborted error.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID cancel(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Send a break sequence to the serial port.
|
||||
/**
|
||||
* This function causes a break sequence of platform-specific duration to be
|
||||
* sent out the serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void send_break()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().send_break(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "send_break");
|
||||
}
|
||||
|
||||
/// Send a break sequence to the serial port.
|
||||
/**
|
||||
* This function causes a break sequence of platform-specific duration to be
|
||||
* sent out the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID send_break(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().send_break(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Set an option on the serial port.
|
||||
/**
|
||||
* This function is used to set an option on the serial port.
|
||||
*
|
||||
* @param option The option value to be set on the serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @sa SettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename SettableSerialPortOption>
|
||||
void set_option(const SettableSerialPortOption& option)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().set_option(impl_.get_implementation(), option, ec);
|
||||
asio::detail::throw_error(ec, "set_option");
|
||||
}
|
||||
|
||||
/// Set an option on the serial port.
|
||||
/**
|
||||
* This function is used to set an option on the serial port.
|
||||
*
|
||||
* @param option The option value to be set on the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @sa SettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename SettableSerialPortOption>
|
||||
ASIO_SYNC_OP_VOID set_option(const SettableSerialPortOption& option,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().set_option(impl_.get_implementation(), option, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Get an option from the serial port.
|
||||
/**
|
||||
* This function is used to get the current value of an option on the serial
|
||||
* port.
|
||||
*
|
||||
* @param option The option value to be obtained from the serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @sa GettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename GettableSerialPortOption>
|
||||
void get_option(GettableSerialPortOption& option) const
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().get_option(impl_.get_implementation(), option, ec);
|
||||
asio::detail::throw_error(ec, "get_option");
|
||||
}
|
||||
|
||||
/// Get an option from the serial port.
|
||||
/**
|
||||
* This function is used to get the current value of an option on the serial
|
||||
* port.
|
||||
*
|
||||
* @param option The option value to be obtained from the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @sa GettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename GettableSerialPortOption>
|
||||
ASIO_SYNC_OP_VOID get_option(GettableSerialPortOption& option,
|
||||
asio::error_code& ec) const
|
||||
{
|
||||
impl_.get_service().get_option(impl_.get_implementation(), option, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Write some data to the serial port.
|
||||
/**
|
||||
* This function is used to write data to the serial port. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
*
|
||||
* @returns The number of bytes written.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* 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
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.get_service().write_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Write some data to the serial port.
|
||||
/**
|
||||
* This function is used to write data to the serial port. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes written. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().write_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
/**
|
||||
* This function is used to asynchronously write data to the serial port.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the write operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* 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. 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
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* 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
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_write_some(this), handler, buffers);
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
/**
|
||||
* This function is used to read data from the serial port. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* 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
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.get_service().read_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
/**
|
||||
* This function is used to read data from the serial port. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes read. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().read_some(
|
||||
impl_.get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
/**
|
||||
* This function is used to asynchronously read data from the serial port.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the read operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* 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. 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
|
||||
* requested amount of data is read before the asynchronous operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* 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
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
initiate_async_read_some(this), handler, 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;
|
||||
|
||||
class initiate_async_write_some
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_write_some(basic_serial_port* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_serial_port* self_;
|
||||
};
|
||||
|
||||
class initiate_async_read_some
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_read_some(basic_serial_port* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_serial_port* self_;
|
||||
};
|
||||
|
||||
#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
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_SERIAL_PORT)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_BASIC_SERIAL_PORT_HPP
|
@ -0,0 +1,568 @@
|
||||
//
|
||||
// basic_signal_set.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_BASIC_SIGNAL_SET_HPP
|
||||
#define ASIO_BASIC_SIGNAL_SET_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/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/execution_context.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides signal functionality.
|
||||
/**
|
||||
* 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
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Example
|
||||
* Performing an asynchronous wait:
|
||||
* @code
|
||||
* void handler(
|
||||
* const asio::error_code& error,
|
||||
* int signal_number)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // A signal occurred.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a signal set registered for process termination.
|
||||
* asio::signal_set signals(my_context, SIGINT, SIGTERM);
|
||||
*
|
||||
* // Start an asynchronous wait for one of the signals to occur.
|
||||
* signals.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Queueing of signal notifications
|
||||
*
|
||||
* If a signal is registered with a signal_set, and the signal occurs when
|
||||
* there are no waiting handlers, then the signal notification is queued. The
|
||||
* next async_wait operation on that signal_set will dequeue the notification.
|
||||
* If multiple notifications are queued, subsequent async_wait operations
|
||||
* dequeue them one at a time. Signal notifications are dequeued in order of
|
||||
* ascending signal number.
|
||||
*
|
||||
* If a signal number is removed from a signal_set (using the @c remove or @c
|
||||
* erase member functions) then any queued notifications for that signal are
|
||||
* discarded.
|
||||
*
|
||||
* @par Multiple registration of signals
|
||||
*
|
||||
* The same signal number may be registered with different signal_set objects.
|
||||
* When the signal occurs, one handler is called for each signal_set object.
|
||||
*
|
||||
* Note that multiple registration only works for signals that are registered
|
||||
* using Asio. The application must not also register a signal handler using
|
||||
* functions such as @c signal() or @c sigaction().
|
||||
*
|
||||
* @par Signal masking on POSIX platforms
|
||||
*
|
||||
* POSIX allows signals to be blocked using functions such as @c sigprocmask()
|
||||
* and @c pthread_sigmask(). For signals to be delivered, programs must ensure
|
||||
* that any signals registered using signal_set objects are unblocked in at
|
||||
* least one thread.
|
||||
*/
|
||||
template <typename Executor = executor>
|
||||
class basic_signal_set
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the signal set type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The signal set type when rebound to the specified executor.
|
||||
typedef basic_signal_set<Executor1> other;
|
||||
};
|
||||
|
||||
/// Construct a signal set without adding any signals.
|
||||
/**
|
||||
* This constructor creates a signal set without registering for any signals.
|
||||
*
|
||||
* @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 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)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a signal set and add one signal.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for one signal.
|
||||
*
|
||||
* @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(ex);
|
||||
* signals.add(signal_number_1); @endcode
|
||||
*/
|
||||
basic_signal_set(const executor_type& ex, int signal_number_1)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code 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");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add two signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for two signals.
|
||||
*
|
||||
* @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(ex);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2); @endcode
|
||||
*/
|
||||
basic_signal_set(const executor_type& ex, int signal_number_1,
|
||||
int signal_number_2)
|
||||
: impl_(ex)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
/// 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");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add three signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for three signals.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @param signal_number_3 The third signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(ex);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2);
|
||||
* signals.add(signal_number_3); @endcode
|
||||
*/
|
||||
basic_signal_set(const executor_type& ex, int signal_number_1,
|
||||
int signal_number_2, int signal_number_3)
|
||||
: impl_(ex)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
/// 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");
|
||||
}
|
||||
|
||||
/// Destroys the signal set.
|
||||
/**
|
||||
* This function destroys the signal set, cancelling any outstanding
|
||||
* asynchronous wait operations associated with the signal set as if by
|
||||
* calling @c cancel.
|
||||
*/
|
||||
~basic_signal_set()
|
||||
{
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return impl_.get_executor();
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
/**
|
||||
* This function adds the specified signal to the set. It has no effect if the
|
||||
* signal is already in the set.
|
||||
*
|
||||
* @param signal_number The signal to be added to the set.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void add(int signal_number)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
/**
|
||||
* This function adds the specified signal to the set. It has no effect if the
|
||||
* signal is already in the set.
|
||||
*
|
||||
* @param signal_number The signal to be added to the set.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID add(int signal_number,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Remove a signal from a signal_set.
|
||||
/**
|
||||
* This function removes the specified signal from the set. It has no effect
|
||||
* if the signal is not in the set.
|
||||
*
|
||||
* @param signal_number The signal to be removed from the set.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note Removes any notifications that have been queued for the specified
|
||||
* signal number.
|
||||
*/
|
||||
void remove(int signal_number)
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
|
||||
asio::detail::throw_error(ec, "remove");
|
||||
}
|
||||
|
||||
/// Remove a signal from a signal_set.
|
||||
/**
|
||||
* This function removes the specified signal from the set. It has no effect
|
||||
* if the signal is not in the set.
|
||||
*
|
||||
* @param signal_number The signal to be removed from the set.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note Removes any notifications that have been queued for the specified
|
||||
* signal number.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID remove(int signal_number,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Remove all signals from a signal_set.
|
||||
/**
|
||||
* This function removes all signals from the set. It has no effect if the set
|
||||
* is already empty.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note Removes all queued notifications.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().clear(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "clear");
|
||||
}
|
||||
|
||||
/// Remove all signals from a signal_set.
|
||||
/**
|
||||
* This function removes all signals from the set. It has no effect if the set
|
||||
* is already empty.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note Removes all queued notifications.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID clear(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().clear(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Cancel all operations associated with the signal set.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the signal set. The handler for each cancelled
|
||||
* operation will be invoked with the asio::error::operation_aborted
|
||||
* error code.
|
||||
*
|
||||
* Cancellation does not alter the set of registered signals.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If a registered signal occurred before cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
void cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
/// Cancel all operations associated with the signal set.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the signal set. The handler for each cancelled
|
||||
* operation will be invoked with the asio::error::operation_aborted
|
||||
* error code.
|
||||
*
|
||||
* Cancellation does not alter the set of registered signals.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note If a registered signal occurred before cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
ASIO_SYNC_OP_VOID cancel(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous operation to wait for a signal to be delivered.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* signal set. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li One of the registered signals in the signal set occurs; or
|
||||
*
|
||||
* @li The signal set was cancelled, in which case the handler is passed the
|
||||
* error code asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the signal occurs. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* 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. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code, int))
|
||||
SignalHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(SignalHandler,
|
||||
void (asio::error_code, int))
|
||||
async_wait(
|
||||
ASIO_MOVE_ARG(SignalHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<SignalHandler, void (asio::error_code, int)>(
|
||||
initiate_async_wait(this), handler);
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_signal_set(const basic_signal_set&) ASIO_DELETED;
|
||||
basic_signal_set& operator=(const basic_signal_set&) ASIO_DELETED;
|
||||
|
||||
class initiate_async_wait
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_wait(basic_signal_set* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename SignalHandler>
|
||||
void operator()(ASIO_MOVE_ARG(SignalHandler) handler) 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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_signal_set* self_;
|
||||
};
|
||||
|
||||
detail::io_object_impl<detail::signal_set_service, Executor> impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BASIC_SIGNAL_SET_HPP
|
1894
tools/sdk/esp32/include/asio/asio/asio/include/asio/basic_socket.hpp
Normal file
1894
tools/sdk/esp32/include/asio/asio/asio/include/asio/basic_socket.hpp
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,407 @@
|
||||
//
|
||||
// basic_socket_iostream.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_BASIC_SOCKET_IOSTREAM_HPP
|
||||
#define ASIO_BASIC_SOCKET_IOSTREAM_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_NO_IOSTREAM)
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include "asio/basic_socket_streambuf.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include "asio/detail/variadic_templates.hpp"
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// explicit basic_socket_iostream(T1 x1, ..., Tn xn)
|
||||
// : std::basic_iostream<char>(
|
||||
// &this->detail::socket_iostream_base<
|
||||
// Protocol, Clock, WaitTraits>::streambuf_)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define ASIO_PRIVATE_CTR_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
explicit basic_socket_iostream(ASIO_VARIADIC_BYVAL_PARAMS(n)) \
|
||||
: std::basic_iostream<char>( \
|
||||
&this->detail::socket_iostream_base< \
|
||||
Protocol, Clock, WaitTraits>::streambuf_) \
|
||||
{ \
|
||||
this->setf(std::ios_base::unitbuf); \
|
||||
if (rdbuf()->connect(ASIO_VARIADIC_BYVAL_ARGS(n)) == 0) \
|
||||
this->setstate(std::ios_base::failbit); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// void connect(T1 x1, ..., Tn xn)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define ASIO_PRIVATE_CONNECT_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void connect(ASIO_VARIADIC_BYVAL_PARAMS(n)) \
|
||||
{ \
|
||||
if (rdbuf()->connect(ASIO_VARIADIC_BYVAL_ARGS(n)) == 0) \
|
||||
this->setstate(std::ios_base::failbit); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
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, typename Clock, typename WaitTraits>
|
||||
class socket_iostream_base
|
||||
{
|
||||
protected:
|
||||
socket_iostream_base()
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket_iostream_base(socket_iostream_base&& other)
|
||||
: streambuf_(std::move(other.streambuf_))
|
||||
{
|
||||
}
|
||||
|
||||
socket_iostream_base(basic_stream_socket<Protocol> s)
|
||||
: streambuf_(std::move(s))
|
||||
{
|
||||
}
|
||||
|
||||
socket_iostream_base& operator=(socket_iostream_base&& other)
|
||||
{
|
||||
streambuf_ = std::move(other.streambuf_);
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
basic_socket_streambuf<Protocol, Clock, WaitTraits> streambuf_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL)
|
||||
#define ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
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> >
|
||||
#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> >
|
||||
#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)
|
||||
|
||||
/// Iostream interface for a socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Protocol,
|
||||
typename Clock = chrono::steady_clock,
|
||||
typename WaitTraits = wait_traits<Clock> >
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Protocol, typename Clock, typename WaitTraits>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
class basic_socket_iostream
|
||||
: 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) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typedef WaitTraits traits_helper;
|
||||
#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 // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
|
||||
public:
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// The clock type.
|
||||
typedef Clock clock_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// (Deprecated: Use time_point.) The time type.
|
||||
typedef typename WaitTraits::time_type time_type;
|
||||
|
||||
/// The time type.
|
||||
typedef typename WaitTraits::time_point time_point;
|
||||
|
||||
/// (Deprecated: Use duration.) The duration type.
|
||||
typedef typename WaitTraits::duration_type duration_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename WaitTraits::duration duration;
|
||||
#else
|
||||
# if !defined(ASIO_NO_DEPRECATED)
|
||||
typedef typename traits_helper::time_type time_type;
|
||||
typedef typename traits_helper::duration_type duration_type;
|
||||
# endif // !defined(ASIO_NO_DEPRECATED)
|
||||
typedef typename traits_helper::time_type time_point;
|
||||
typedef typename traits_helper::duration_type duration;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_socket_iostream without establishing a connection.
|
||||
basic_socket_iostream()
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Construct a basic_socket_iostream from the supplied socket.
|
||||
explicit basic_socket_iostream(basic_stream_socket<protocol_type> s)
|
||||
: detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>(std::move(s)),
|
||||
std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_STD_IOSTREAM_MOVE) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_socket_iostream from another.
|
||||
basic_socket_iostream(basic_socket_iostream&& other)
|
||||
: detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>(std::move(other)),
|
||||
std::basic_iostream<char>(std::move(other))
|
||||
{
|
||||
this->set_rdbuf(&this->detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>::streambuf_);
|
||||
}
|
||||
|
||||
/// Move-assign a basic_socket_iostream from another.
|
||||
basic_socket_iostream& operator=(basic_socket_iostream&& other)
|
||||
{
|
||||
std::basic_iostream<char>::operator=(std::move(other));
|
||||
detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_STD_IOSTREAM_MOVE)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection to an endpoint corresponding to a resolver query.
|
||||
/**
|
||||
* This constructor automatically establishes a connection based on the
|
||||
* supplied resolver query parameters. The arguments are used to construct
|
||||
* a resolver query object.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
explicit basic_socket_iostream(T1 t1, ..., TN tn);
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
explicit basic_socket_iostream(T... x)
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
#else
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CTR_DEF)
|
||||
#endif
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection to an endpoint corresponding to a resolver query.
|
||||
/**
|
||||
* This function automatically establishes a connection based on the supplied
|
||||
* resolver query parameters. The arguments are used to construct a resolver
|
||||
* query object.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
void connect(T1 t1, ..., TN tn);
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
void connect(T... x)
|
||||
{
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
#else
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CONNECT_DEF)
|
||||
#endif
|
||||
|
||||
/// Close the connection.
|
||||
void close()
|
||||
{
|
||||
if (rdbuf()->close() == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
|
||||
/// Return a pointer to the underlying streambuf.
|
||||
basic_socket_streambuf<Protocol, Clock, WaitTraits>* rdbuf() const
|
||||
{
|
||||
return const_cast<basic_socket_streambuf<Protocol, Clock, WaitTraits>*>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, Clock, WaitTraits>::streambuf_);
|
||||
}
|
||||
|
||||
/// Get a reference to the underlying socket.
|
||||
basic_socket<Protocol>& socket()
|
||||
{
|
||||
return rdbuf()->socket();
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream.
|
||||
*
|
||||
* @par Example
|
||||
* To print the error associated with a failure to establish a connection:
|
||||
* @code tcp::iostream s("www.boost.org", "http");
|
||||
* if (!s)
|
||||
* {
|
||||
* std::cout << "Error: " << s.error().message() << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
const asio::error_code& error() const
|
||||
{
|
||||
return rdbuf()->error();
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use expiry().) Get the stream's expiry time as an absolute
|
||||
/// time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream's expiry time.
|
||||
*/
|
||||
time_point expires_at() const
|
||||
{
|
||||
return rdbuf()->expires_at();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Get the stream's expiry time as an absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream's expiry time.
|
||||
*/
|
||||
time_point expiry() const
|
||||
{
|
||||
return rdbuf()->expiry();
|
||||
}
|
||||
|
||||
/// Set the stream's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the stream.
|
||||
*/
|
||||
void expires_at(const time_point& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_at(expiry_time);
|
||||
}
|
||||
|
||||
/// Set the stream's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_after(const duration& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_after(expiry_time);
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use expiry().) Get the stream's expiry time relative to now.
|
||||
/**
|
||||
* @return A relative time value representing the stream's expiry time.
|
||||
*/
|
||||
duration expires_from_now() const
|
||||
{
|
||||
return rdbuf()->expires_from_now();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expires_after().) Set the stream's expiry time relative
|
||||
/// to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_from_now(const duration& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_from_now(expiry_time);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_socket_iostream(const basic_socket_iostream&) ASIO_DELETED;
|
||||
basic_socket_iostream& operator=(
|
||||
const basic_socket_iostream&) ASIO_DELETED;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef ASIO_PRIVATE_CTR_DEF
|
||||
# undef ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
@ -0,0 +1,687 @@
|
||||
//
|
||||
// basic_socket_streambuf.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_BASIC_SOCKET_STREAMBUF_HPP
|
||||
#define ASIO_BASIC_SOCKET_STREAMBUF_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_NO_IOSTREAM)
|
||||
|
||||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
#include "asio/detail/buffer_sequence_adapter.hpp"
|
||||
#include "asio/detail/memory.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#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 // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include "asio/detail/variadic_templates.hpp"
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// basic_socket_streambuf* connect(T1 x1, ..., Tn xn)
|
||||
// {
|
||||
// init_buffers();
|
||||
// typedef typename Protocol::resolver resolver_type;
|
||||
// resolver_type resolver(socket().get_executor());
|
||||
// connect_to_endpoints(
|
||||
// resolver.resolve(x1, ..., xn, ec_));
|
||||
// return !ec_ ? this : 0;
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define ASIO_PRIVATE_CONNECT_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
basic_socket_streambuf* connect(ASIO_VARIADIC_BYVAL_PARAMS(n)) \
|
||||
{ \
|
||||
init_buffers(); \
|
||||
typedef typename Protocol::resolver resolver_type; \
|
||||
resolver_type resolver(socket().get_executor()); \
|
||||
connect_to_endpoints( \
|
||||
resolver.resolve(ASIO_VARIADIC_BYVAL_ARGS(n), ec_)); \
|
||||
return !ec_ ? this : 0; \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A separate base class is used to ensure that the io_context member is
|
||||
// initialised prior to the basic_socket_streambuf's basic_socket base class.
|
||||
class socket_streambuf_io_context
|
||||
{
|
||||
protected:
|
||||
socket_streambuf_io_context(io_context* ctx)
|
||||
: default_io_context_(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr<io_context> default_io_context_;
|
||||
};
|
||||
|
||||
// A separate base class is used to ensure that the dynamically allocated
|
||||
// buffers are constructed prior to the basic_socket_streambuf's basic_socket
|
||||
// base class. This makes moving the socket is the last potentially throwing
|
||||
// step in the streambuf's move constructor, giving the constructor a strong
|
||||
// exception safety guarantee.
|
||||
class socket_streambuf_buffers
|
||||
{
|
||||
protected:
|
||||
socket_streambuf_buffers()
|
||||
: get_buffer_(buffer_size),
|
||||
put_buffer_(buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
enum { buffer_size = 512 };
|
||||
std::vector<char> get_buffer_;
|
||||
std::vector<char> put_buffer_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL)
|
||||
#define ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
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> >
|
||||
#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> >
|
||||
#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)
|
||||
|
||||
/// Iostream streambuf for a socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Protocol,
|
||||
typename Clock = chrono::steady_clock,
|
||||
typename WaitTraits = wait_traits<Clock> >
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
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>
|
||||
#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
|
||||
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) \
|
||||
&& defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
typedef WaitTraits traits_helper;
|
||||
#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 // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
|
||||
|
||||
public:
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// The clock type.
|
||||
typedef Clock clock_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// (Deprecated: Use time_point.) The time type.
|
||||
typedef typename WaitTraits::time_type time_type;
|
||||
|
||||
/// The time type.
|
||||
typedef typename WaitTraits::time_point time_point;
|
||||
|
||||
/// (Deprecated: Use duration.) The duration type.
|
||||
typedef typename WaitTraits::duration_type duration_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename WaitTraits::duration duration;
|
||||
#else
|
||||
# if !defined(ASIO_NO_DEPRECATED)
|
||||
typedef typename traits_helper::time_type time_type;
|
||||
typedef typename traits_helper::duration_type duration_type;
|
||||
# endif // !defined(ASIO_NO_DEPRECATED)
|
||||
typedef typename traits_helper::time_type time_point;
|
||||
typedef typename traits_helper::duration_type duration;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_socket_streambuf without establishing a connection.
|
||||
basic_socket_streambuf()
|
||||
: detail::socket_streambuf_io_context(new io_context),
|
||||
basic_socket<Protocol>(*default_io_context_),
|
||||
expiry_time_(max_expiry_time())
|
||||
{
|
||||
init_buffers();
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// 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>(std::move(s)),
|
||||
expiry_time_(max_expiry_time())
|
||||
{
|
||||
init_buffers();
|
||||
}
|
||||
|
||||
/// Move-construct a basic_socket_streambuf from another.
|
||||
basic_socket_streambuf(basic_socket_streambuf&& other)
|
||||
: detail::socket_streambuf_io_context(other),
|
||||
basic_socket<Protocol>(std::move(other.socket())),
|
||||
ec_(other.ec_),
|
||||
expiry_time_(other.expiry_time_)
|
||||
{
|
||||
get_buffer_.swap(other.get_buffer_);
|
||||
put_buffer_.swap(other.put_buffer_);
|
||||
setg(other.eback(), other.gptr(), other.egptr());
|
||||
setp(other.pptr(), other.epptr());
|
||||
other.ec_ = asio::error_code();
|
||||
other.expiry_time_ = max_expiry_time();
|
||||
other.init_buffers();
|
||||
}
|
||||
|
||||
/// Move-assign a basic_socket_streambuf from another.
|
||||
basic_socket_streambuf& operator=(basic_socket_streambuf&& other)
|
||||
{
|
||||
this->close();
|
||||
socket() = std::move(other.socket());
|
||||
detail::socket_streambuf_io_context::operator=(other);
|
||||
ec_ = other.ec_;
|
||||
expiry_time_ = other.expiry_time_;
|
||||
get_buffer_.swap(other.get_buffer_);
|
||||
put_buffer_.swap(other.put_buffer_);
|
||||
setg(other.eback(), other.gptr(), other.egptr());
|
||||
setp(other.pptr(), other.epptr());
|
||||
other.ec_ = asio::error_code();
|
||||
other.expiry_time_ = max_expiry_time();
|
||||
other.put_buffer_.resize(buffer_size);
|
||||
other.init_buffers();
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destructor flushes buffered data.
|
||||
virtual ~basic_socket_streambuf()
|
||||
{
|
||||
if (pptr() != pbase())
|
||||
overflow(traits_type::eof());
|
||||
}
|
||||
|
||||
/// Establish a connection.
|
||||
/**
|
||||
* This function establishes a connection to the specified endpoint.
|
||||
*
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
basic_socket_streambuf* connect(const endpoint_type& endpoint)
|
||||
{
|
||||
init_buffers();
|
||||
ec_ = asio::error_code();
|
||||
this->connect_to_endpoints(&endpoint, &endpoint + 1);
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection.
|
||||
/**
|
||||
* This function automatically establishes a connection based on the supplied
|
||||
* resolver query parameters. The arguments are used to construct a resolver
|
||||
* query object.
|
||||
*
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
basic_socket_streambuf* connect(T1 t1, ..., TN tn);
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
basic_socket_streambuf* connect(T... x)
|
||||
{
|
||||
init_buffers();
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
resolver_type resolver(socket().get_executor());
|
||||
connect_to_endpoints(resolver.resolve(x..., ec_));
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
#else
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CONNECT_DEF)
|
||||
#endif
|
||||
|
||||
/// Close the connection.
|
||||
/**
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
basic_socket_streambuf* close()
|
||||
{
|
||||
sync();
|
||||
socket().close(ec_);
|
||||
if (!ec_)
|
||||
init_buffers();
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
|
||||
/// Get a reference to the underlying socket.
|
||||
basic_socket<Protocol>& socket()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream buffer.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream
|
||||
* buffer.
|
||||
*/
|
||||
const asio::error_code& error() const
|
||||
{
|
||||
return ec_;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use error().) Get the last error associated with the stream
|
||||
/// buffer.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream
|
||||
* buffer.
|
||||
*/
|
||||
const asio::error_code& puberror() const
|
||||
{
|
||||
return error();
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expiry().) Get the stream buffer's expiry time as an
|
||||
/// absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream buffer's expiry
|
||||
* time.
|
||||
*/
|
||||
time_point expires_at() const
|
||||
{
|
||||
return expiry_time_;
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Get the stream buffer's expiry time as an absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream buffer's expiry
|
||||
* time.
|
||||
*/
|
||||
time_point expiry() const
|
||||
{
|
||||
return expiry_time_;
|
||||
}
|
||||
|
||||
/// Set the stream buffer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the stream.
|
||||
*/
|
||||
void expires_at(const time_point& expiry_time)
|
||||
{
|
||||
expiry_time_ = expiry_time;
|
||||
}
|
||||
|
||||
/// Set the stream buffer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_after(const duration& expiry_time)
|
||||
{
|
||||
expiry_time_ = traits_helper::add(traits_helper::now(), expiry_time);
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use expiry().) Get the stream buffer's expiry time relative
|
||||
/// to now.
|
||||
/**
|
||||
* @return A relative time value representing the stream buffer's expiry time.
|
||||
*/
|
||||
duration expires_from_now() const
|
||||
{
|
||||
return traits_helper::subtract(expires_at(), traits_helper::now());
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expires_after().) Set the stream buffer's expiry time
|
||||
/// relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_from_now(const duration& expiry_time)
|
||||
{
|
||||
expiry_time_ = traits_helper::add(traits_helper::now(), expiry_time);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
protected:
|
||||
int_type underflow()
|
||||
{
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
ec_ = asio::error::operation_not_supported;
|
||||
return traits_type::eof();
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
if (gptr() != egptr())
|
||||
return traits_type::eof();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// Check if we are past the expiry time.
|
||||
if (traits_helper::less_than(expiry_time_, traits_helper::now()))
|
||||
{
|
||||
ec_ = asio::error::timed_out;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Try to complete the operation without blocking.
|
||||
if (!socket().native_non_blocking())
|
||||
socket().native_non_blocking(true, ec_);
|
||||
detail::buffer_sequence_adapter<mutable_buffer, mutable_buffer>
|
||||
bufs(asio::buffer(get_buffer_) + putback_max);
|
||||
detail::signed_size_type bytes = detail::socket_ops::recv(
|
||||
socket().native_handle(), bufs.buffers(), bufs.count(), 0, ec_);
|
||||
|
||||
// Check if operation succeeded.
|
||||
if (bytes > 0)
|
||||
{
|
||||
setg(&get_buffer_[0], &get_buffer_[0] + putback_max,
|
||||
&get_buffer_[0] + putback_max + bytes);
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
// Check for EOF.
|
||||
if (bytes == 0)
|
||||
{
|
||||
ec_ = asio::error::eof;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Operation failed.
|
||||
if (ec_ != asio::error::would_block
|
||||
&& ec_ != asio::error::try_again)
|
||||
return traits_type::eof();
|
||||
|
||||
// Wait for socket to become ready.
|
||||
if (detail::socket_ops::poll_read(
|
||||
socket().native_handle(), 0, timeout(), ec_) < 0)
|
||||
return traits_type::eof();
|
||||
}
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
}
|
||||
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
ec_ = asio::error::operation_not_supported;
|
||||
return traits_type::eof();
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
char_type ch = traits_type::to_char_type(c);
|
||||
|
||||
// Determine what needs to be sent.
|
||||
const_buffer output_buffer;
|
||||
if (put_buffer_.empty())
|
||||
{
|
||||
if (traits_type::eq_int_type(c, traits_type::eof()))
|
||||
return traits_type::not_eof(c); // Nothing to do.
|
||||
output_buffer = asio::buffer(&ch, sizeof(char_type));
|
||||
}
|
||||
else
|
||||
{
|
||||
output_buffer = asio::buffer(pbase(),
|
||||
(pptr() - pbase()) * sizeof(char_type));
|
||||
}
|
||||
|
||||
while (output_buffer.size() > 0)
|
||||
{
|
||||
// Check if we are past the expiry time.
|
||||
if (traits_helper::less_than(expiry_time_, traits_helper::now()))
|
||||
{
|
||||
ec_ = asio::error::timed_out;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Try to complete the operation without blocking.
|
||||
if (!socket().native_non_blocking())
|
||||
socket().native_non_blocking(true, ec_);
|
||||
detail::buffer_sequence_adapter<
|
||||
const_buffer, const_buffer> bufs(output_buffer);
|
||||
detail::signed_size_type bytes = detail::socket_ops::send(
|
||||
socket().native_handle(), bufs.buffers(), bufs.count(), 0, ec_);
|
||||
|
||||
// Check if operation succeeded.
|
||||
if (bytes > 0)
|
||||
{
|
||||
output_buffer += static_cast<std::size_t>(bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Operation failed.
|
||||
if (ec_ != asio::error::would_block
|
||||
&& ec_ != asio::error::try_again)
|
||||
return traits_type::eof();
|
||||
|
||||
// Wait for socket to become ready.
|
||||
if (detail::socket_ops::poll_write(
|
||||
socket().native_handle(), 0, timeout(), ec_) < 0)
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
if (!put_buffer_.empty())
|
||||
{
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
|
||||
// If the new character is eof then our work here is done.
|
||||
if (traits_type::eq_int_type(c, traits_type::eof()))
|
||||
return traits_type::not_eof(c);
|
||||
|
||||
// Add the new character to the output buffer.
|
||||
*pptr() = ch;
|
||||
pbump(1);
|
||||
}
|
||||
|
||||
return c;
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
}
|
||||
|
||||
int sync()
|
||||
{
|
||||
return overflow(traits_type::eof());
|
||||
}
|
||||
|
||||
std::streambuf* setbuf(char_type* s, std::streamsize n)
|
||||
{
|
||||
if (pptr() == pbase() && s == 0 && n == 0)
|
||||
{
|
||||
put_buffer_.clear();
|
||||
setp(0, 0);
|
||||
sync();
|
||||
return this;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_socket_streambuf(const basic_socket_streambuf&) ASIO_DELETED;
|
||||
basic_socket_streambuf& operator=(
|
||||
const basic_socket_streambuf&) ASIO_DELETED;
|
||||
|
||||
void init_buffers()
|
||||
{
|
||||
setg(&get_buffer_[0],
|
||||
&get_buffer_[0] + putback_max,
|
||||
&get_buffer_[0] + putback_max);
|
||||
|
||||
if (put_buffer_.empty())
|
||||
setp(0, 0);
|
||||
else
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
}
|
||||
|
||||
int timeout() const
|
||||
{
|
||||
int64_t msec = traits_helper::to_posix_duration(
|
||||
traits_helper::subtract(expiry_time_,
|
||||
traits_helper::now())).total_milliseconds();
|
||||
if (msec > (std::numeric_limits<int>::max)())
|
||||
msec = (std::numeric_limits<int>::max)();
|
||||
else if (msec < 0)
|
||||
msec = 0;
|
||||
return static_cast<int>(msec);
|
||||
}
|
||||
|
||||
template <typename EndpointSequence>
|
||||
void connect_to_endpoints(const EndpointSequence& endpoints)
|
||||
{
|
||||
this->connect_to_endpoints(endpoints.begin(), endpoints.end());
|
||||
}
|
||||
|
||||
template <typename EndpointIterator>
|
||||
void connect_to_endpoints(EndpointIterator begin, EndpointIterator end)
|
||||
{
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
ec_ = asio::error::operation_not_supported;
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
if (ec_)
|
||||
return;
|
||||
|
||||
ec_ = asio::error::not_found;
|
||||
for (EndpointIterator i = begin; i != end; ++i)
|
||||
{
|
||||
// Check if we are past the expiry time.
|
||||
if (traits_helper::less_than(expiry_time_, traits_helper::now()))
|
||||
{
|
||||
ec_ = asio::error::timed_out;
|
||||
return;
|
||||
}
|
||||
|
||||
// Close and reopen the socket.
|
||||
typename Protocol::endpoint ep(*i);
|
||||
socket().close(ec_);
|
||||
socket().open(ep.protocol(), ec_);
|
||||
if (ec_)
|
||||
continue;
|
||||
|
||||
// Try to complete the operation without blocking.
|
||||
if (!socket().native_non_blocking())
|
||||
socket().native_non_blocking(true, ec_);
|
||||
detail::socket_ops::connect(socket().native_handle(),
|
||||
ep.data(), ep.size(), ec_);
|
||||
|
||||
// Check if operation succeeded.
|
||||
if (!ec_)
|
||||
return;
|
||||
|
||||
// Operation failed.
|
||||
if (ec_ != asio::error::in_progress
|
||||
&& ec_ != asio::error::would_block)
|
||||
continue;
|
||||
|
||||
// Wait for socket to become ready.
|
||||
if (detail::socket_ops::poll_connect(
|
||||
socket().native_handle(), timeout(), ec_) < 0)
|
||||
continue;
|
||||
|
||||
// Get the error code from the connect operation.
|
||||
int connect_error = 0;
|
||||
size_t connect_error_len = sizeof(connect_error);
|
||||
if (detail::socket_ops::getsockopt(socket().native_handle(), 0,
|
||||
SOL_SOCKET, SO_ERROR, &connect_error, &connect_error_len, ec_)
|
||||
== detail::socket_error_retval)
|
||||
return;
|
||||
|
||||
// Check the result of the connect operation.
|
||||
ec_ = asio::error_code(connect_error,
|
||||
asio::error::get_system_category());
|
||||
if (!ec_)
|
||||
return;
|
||||
}
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
}
|
||||
|
||||
// Helper function to get the maximum expiry time.
|
||||
static time_point max_expiry_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 };
|
||||
asio::error_code ec_;
|
||||
time_point expiry_time_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,452 @@
|
||||
//
|
||||
// basic_streambuf.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_BASIC_STREAMBUF_HPP
|
||||
#define ASIO_BASIC_STREAMBUF_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_NO_IOSTREAM)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include "asio/basic_streambuf_fwd.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/throw_exception.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Automatically resizable buffer class based on std::streambuf.
|
||||
/**
|
||||
* The @c basic_streambuf class is derived from @c std::streambuf to associate
|
||||
* the streambuf's input and output sequences with one or more character
|
||||
* arrays. These character arrays are internal to the @c basic_streambuf
|
||||
* object, but direct access to the array elements is provided to permit them
|
||||
* to be used efficiently with I/O operations. Characters written to the output
|
||||
* sequence of a @c basic_streambuf object are appended to the input sequence
|
||||
* of the same object.
|
||||
*
|
||||
* The @c basic_streambuf class's public interface is intended to permit the
|
||||
* following implementation strategies:
|
||||
*
|
||||
* @li A single contiguous character array, which is reallocated as necessary
|
||||
* to accommodate changes in the size of the character sequence. This is the
|
||||
* implementation approach currently used in Asio.
|
||||
*
|
||||
* @li A sequence of one or more character arrays, where each array is of the
|
||||
* same size. Additional character array objects are appended to the sequence
|
||||
* to accommodate changes in the size of the character sequence.
|
||||
*
|
||||
* @li A sequence of one or more character arrays of varying sizes. Additional
|
||||
* character array objects are appended to the sequence to accommodate changes
|
||||
* in the size of the character sequence.
|
||||
*
|
||||
* The constructor for basic_streambuf accepts a @c size_t argument specifying
|
||||
* the maximum of the sum of the sizes of the input sequence and output
|
||||
* sequence. During the lifetime of the @c basic_streambuf object, the following
|
||||
* invariant holds:
|
||||
* @code size() <= max_size()@endcode
|
||||
* Any member function that would, if successful, cause the invariant to be
|
||||
* violated shall throw an exception of class @c std::length_error.
|
||||
*
|
||||
* The constructor for @c basic_streambuf takes an Allocator argument. A copy
|
||||
* of this argument is used for any memory allocation performed, by the
|
||||
* constructor and by all member functions, during the lifetime of each @c
|
||||
* basic_streambuf object.
|
||||
*
|
||||
* @par Examples
|
||||
* Writing directly from an streambuf to a socket:
|
||||
* @code
|
||||
* asio::streambuf b;
|
||||
* std::ostream os(&b);
|
||||
* os << "Hello, World!\n";
|
||||
*
|
||||
* // try sending some data in input sequence
|
||||
* size_t n = sock.send(b.data());
|
||||
*
|
||||
* b.consume(n); // sent data is removed from input sequence
|
||||
* @endcode
|
||||
*
|
||||
* Reading from a socket directly into a streambuf:
|
||||
* @code
|
||||
* asio::streambuf b;
|
||||
*
|
||||
* // reserve 512 bytes in output sequence
|
||||
* asio::streambuf::mutable_buffers_type bufs = b.prepare(512);
|
||||
*
|
||||
* size_t n = sock.receive(bufs);
|
||||
*
|
||||
* // received data is "committed" from output sequence to input sequence
|
||||
* b.commit(n);
|
||||
*
|
||||
* std::istream is(&b);
|
||||
* std::string s;
|
||||
* is >> s;
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
#else
|
||||
template <typename Allocator>
|
||||
#endif
|
||||
class basic_streambuf
|
||||
: public std::streambuf,
|
||||
private noncopyable
|
||||
{
|
||||
public:
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
typedef implementation_defined const_buffers_type;
|
||||
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
typedef implementation_defined mutable_buffers_type;
|
||||
#else
|
||||
typedef ASIO_CONST_BUFFER const_buffers_type;
|
||||
typedef ASIO_MUTABLE_BUFFER mutable_buffers_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_streambuf object.
|
||||
/**
|
||||
* Constructs a streambuf with the specified maximum size. The initial size
|
||||
* of the streambuf's input sequence is 0.
|
||||
*/
|
||||
explicit basic_streambuf(
|
||||
std::size_t maximum_size = (std::numeric_limits<std::size_t>::max)(),
|
||||
const Allocator& allocator = Allocator())
|
||||
: max_size_(maximum_size),
|
||||
buffer_(allocator)
|
||||
{
|
||||
std::size_t pend = (std::min<std::size_t>)(max_size_, buffer_delta);
|
||||
buffer_.resize((std::max<std::size_t>)(pend, 1));
|
||||
setg(&buffer_[0], &buffer_[0], &buffer_[0]);
|
||||
setp(&buffer_[0], &buffer_[0] + pend);
|
||||
}
|
||||
|
||||
/// Get the size of the input sequence.
|
||||
/**
|
||||
* @returns The size of the input sequence. The value is equal to that
|
||||
* calculated for @c s in the following code:
|
||||
* @code
|
||||
* size_t s = 0;
|
||||
* const_buffers_type bufs = data();
|
||||
* const_buffers_type::const_iterator i = bufs.begin();
|
||||
* while (i != bufs.end())
|
||||
* {
|
||||
* const_buffer buf(*i++);
|
||||
* s += buf.size();
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
std::size_t size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return pptr() - gptr();
|
||||
}
|
||||
|
||||
/// Get the maximum size of the basic_streambuf.
|
||||
/**
|
||||
* @returns The allowed maximum of the sum of the sizes of the input sequence
|
||||
* and output sequence.
|
||||
*/
|
||||
std::size_t max_size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return max_size_;
|
||||
}
|
||||
|
||||
/// Get the current capacity of the basic_streambuf.
|
||||
/**
|
||||
* @returns The current total capacity of the streambuf, i.e. for both the
|
||||
* input sequence and output sequence.
|
||||
*/
|
||||
std::size_t capacity() const ASIO_NOEXCEPT
|
||||
{
|
||||
return buffer_.capacity();
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the input sequence.
|
||||
/**
|
||||
* @returns An object of type @c const_buffers_type that satisfies
|
||||
* ConstBufferSequence requirements, representing all character arrays in the
|
||||
* input sequence.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c basic_streambuf member
|
||||
* function that modifies the input sequence or output sequence.
|
||||
*/
|
||||
const_buffers_type data() const ASIO_NOEXCEPT
|
||||
{
|
||||
return asio::buffer(asio::const_buffer(gptr(),
|
||||
(pptr() - gptr()) * sizeof(char_type)));
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the output sequence, with the given
|
||||
/// size.
|
||||
/**
|
||||
* Ensures that the output sequence can accommodate @c n characters,
|
||||
* reallocating character array objects as necessary.
|
||||
*
|
||||
* @returns An object of type @c mutable_buffers_type that satisfies
|
||||
* MutableBufferSequence requirements, representing character array objects
|
||||
* at the start of the output sequence such that the sum of the buffer sizes
|
||||
* is @c n.
|
||||
*
|
||||
* @throws std::length_error If <tt>size() + n > max_size()</tt>.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c basic_streambuf member
|
||||
* function that modifies the input sequence or output sequence.
|
||||
*/
|
||||
mutable_buffers_type prepare(std::size_t n)
|
||||
{
|
||||
reserve(n);
|
||||
return asio::buffer(asio::mutable_buffer(
|
||||
pptr(), n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
/// Move characters from the output sequence to the input sequence.
|
||||
/**
|
||||
* Appends @c n characters from the start of the output sequence to the input
|
||||
* sequence. The beginning of the output sequence is advanced by @c n
|
||||
* characters.
|
||||
*
|
||||
* Requires a preceding call <tt>prepare(x)</tt> where <tt>x >= n</tt>, and
|
||||
* no intervening operations that modify the input or output sequence.
|
||||
*
|
||||
* @note If @c n is greater than the size of the output sequence, the entire
|
||||
* output sequence is moved to the input sequence and no error is issued.
|
||||
*/
|
||||
void commit(std::size_t n)
|
||||
{
|
||||
n = std::min<std::size_t>(n, epptr() - pptr());
|
||||
pbump(static_cast<int>(n));
|
||||
setg(eback(), gptr(), pptr());
|
||||
}
|
||||
|
||||
/// Remove characters from the input sequence.
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void consume(std::size_t n)
|
||||
{
|
||||
if (egptr() < pptr())
|
||||
setg(&buffer_[0], gptr(), pptr());
|
||||
if (gptr() + n > pptr())
|
||||
n = pptr() - gptr();
|
||||
gbump(static_cast<int>(n));
|
||||
}
|
||||
|
||||
protected:
|
||||
enum { buffer_delta = 128 };
|
||||
|
||||
/// Override std::streambuf behaviour.
|
||||
/**
|
||||
* Behaves according to the specification of @c std::streambuf::underflow().
|
||||
*/
|
||||
int_type underflow()
|
||||
{
|
||||
if (gptr() < pptr())
|
||||
{
|
||||
setg(&buffer_[0], gptr(), pptr());
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
return traits_type::eof();
|
||||
}
|
||||
}
|
||||
|
||||
/// Override std::streambuf behaviour.
|
||||
/**
|
||||
* Behaves according to the specification of @c std::streambuf::overflow(),
|
||||
* with the specialisation that @c std::length_error is thrown if appending
|
||||
* the character to the input sequence would require the condition
|
||||
* <tt>size() > max_size()</tt> to be true.
|
||||
*/
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
if (!traits_type::eq_int_type(c, traits_type::eof()))
|
||||
{
|
||||
if (pptr() == epptr())
|
||||
{
|
||||
std::size_t buffer_size = pptr() - gptr();
|
||||
if (buffer_size < max_size_ && max_size_ - buffer_size < buffer_delta)
|
||||
{
|
||||
reserve(max_size_ - buffer_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
reserve(buffer_delta);
|
||||
}
|
||||
}
|
||||
|
||||
*pptr() = traits_type::to_char_type(c);
|
||||
pbump(1);
|
||||
return c;
|
||||
}
|
||||
|
||||
return traits_type::not_eof(c);
|
||||
}
|
||||
|
||||
void reserve(std::size_t n)
|
||||
{
|
||||
// Get current stream positions as offsets.
|
||||
std::size_t gnext = gptr() - &buffer_[0];
|
||||
std::size_t pnext = pptr() - &buffer_[0];
|
||||
std::size_t pend = epptr() - &buffer_[0];
|
||||
|
||||
// Check if there is already enough space in the put area.
|
||||
if (n <= pend - pnext)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift existing contents of get area to start of buffer.
|
||||
if (gnext > 0)
|
||||
{
|
||||
pnext -= gnext;
|
||||
std::memmove(&buffer_[0], &buffer_[0] + gnext, pnext);
|
||||
}
|
||||
|
||||
// Ensure buffer is large enough to hold at least the specified size.
|
||||
if (n > pend - pnext)
|
||||
{
|
||||
if (n <= max_size_ && pnext <= max_size_ - n)
|
||||
{
|
||||
pend = pnext + n;
|
||||
buffer_.resize((std::max<std::size_t>)(pend, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::length_error ex("asio::streambuf too long");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Update stream positions.
|
||||
setg(&buffer_[0], &buffer_[0], &buffer_[0] + pnext);
|
||||
setp(&buffer_[0] + pnext, &buffer_[0] + pend);
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t max_size_;
|
||||
std::vector<char_type, Allocator> buffer_;
|
||||
|
||||
// Helper function to get the preferred size for reading data.
|
||||
friend std::size_t read_size_helper(
|
||||
basic_streambuf& sb, std::size_t max_size)
|
||||
{
|
||||
return std::min<std::size_t>(
|
||||
std::max<std::size_t>(512, sb.buffer_.capacity() - sb.size()),
|
||||
std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
|
||||
}
|
||||
};
|
||||
|
||||
/// Adapts basic_streambuf to the dynamic buffer sequence type requirements.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
#else
|
||||
template <typename Allocator>
|
||||
#endif
|
||||
class basic_streambuf_ref
|
||||
{
|
||||
public:
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
typedef typename basic_streambuf<Allocator>::const_buffers_type
|
||||
const_buffers_type;
|
||||
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
typedef typename basic_streambuf<Allocator>::mutable_buffers_type
|
||||
mutable_buffers_type;
|
||||
|
||||
/// Construct a basic_streambuf_ref for the given basic_streambuf object.
|
||||
explicit basic_streambuf_ref(basic_streambuf<Allocator>& sb)
|
||||
: sb_(sb)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copy construct a basic_streambuf_ref.
|
||||
basic_streambuf_ref(const basic_streambuf_ref& other) ASIO_NOEXCEPT
|
||||
: sb_(other.sb_)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move construct a basic_streambuf_ref.
|
||||
basic_streambuf_ref(basic_streambuf_ref&& other) ASIO_NOEXCEPT
|
||||
: sb_(other.sb_)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get the size of the input sequence.
|
||||
std::size_t size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return sb_.size();
|
||||
}
|
||||
|
||||
/// Get the maximum size of the dynamic buffer.
|
||||
std::size_t max_size() const ASIO_NOEXCEPT
|
||||
{
|
||||
return sb_.max_size();
|
||||
}
|
||||
|
||||
/// Get the current capacity of the dynamic buffer.
|
||||
std::size_t capacity() const ASIO_NOEXCEPT
|
||||
{
|
||||
return sb_.capacity();
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the input sequence.
|
||||
const_buffers_type data() const ASIO_NOEXCEPT
|
||||
{
|
||||
return sb_.data();
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the output sequence, with the given
|
||||
/// size.
|
||||
mutable_buffers_type prepare(std::size_t n)
|
||||
{
|
||||
return sb_.prepare(n);
|
||||
}
|
||||
|
||||
/// Move bytes from the output sequence to the input sequence.
|
||||
void commit(std::size_t n)
|
||||
{
|
||||
return sb_.commit(n);
|
||||
}
|
||||
|
||||
/// Remove characters from the input sequence.
|
||||
void consume(std::size_t n)
|
||||
{
|
||||
return sb_.consume(n);
|
||||
}
|
||||
|
||||
private:
|
||||
basic_streambuf<Allocator>& sb_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_STREAMBUF_HPP
|
@ -0,0 +1,36 @@
|
||||
//
|
||||
// basic_streambuf_fwd.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_BASIC_STREAMBUF_FWD_HPP
|
||||
#define ASIO_BASIC_STREAMBUF_FWD_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_NO_IOSTREAM)
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
class basic_streambuf;
|
||||
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
class basic_streambuf_ref;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_STREAMBUF_FWD_HPP
|
@ -0,0 +1,763 @@
|
||||
//
|
||||
// basic_waitable_timer.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_BASIC_WAITABLE_TIMER_HPP
|
||||
#define ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#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)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if !defined(ASIO_BASIC_WAITABLE_TIMER_FWD_DECL)
|
||||
#define ASIO_BASIC_WAITABLE_TIMER_FWD_DECL
|
||||
|
||||
// Forward declaration with defaulted arguments.
|
||||
template <typename Clock,
|
||||
typename WaitTraits = asio::wait_traits<Clock>,
|
||||
typename Executor = executor>
|
||||
class basic_waitable_timer;
|
||||
|
||||
#endif // !defined(ASIO_BASIC_WAITABLE_TIMER_FWD_DECL)
|
||||
|
||||
/// Provides waitable timer functionality.
|
||||
/**
|
||||
* The basic_waitable_timer class template provides the ability to perform a
|
||||
* blocking or asynchronous wait for a timer to expire.
|
||||
*
|
||||
* A waitable timer is always in one of two states: "expired" or "not expired".
|
||||
* If the wait() or async_wait() function is called on an expired timer, the
|
||||
* wait operation will complete immediately.
|
||||
*
|
||||
* Most applications will use one of the asio::steady_timer,
|
||||
* asio::system_timer or asio::high_resolution_timer typedefs.
|
||||
*
|
||||
* @note This waitable timer functionality is for use with the C++11 standard
|
||||
* library's @c <chrono> facility, or with the Boost.Chrono library.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Examples
|
||||
* Performing a blocking wait (C++11):
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* asio::steady_timer timer(my_context);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_after(std::chrono::seconds(5));
|
||||
*
|
||||
* // Wait for the timer to expire.
|
||||
* timer.wait();
|
||||
* @endcode
|
||||
*
|
||||
* @par
|
||||
* Performing an asynchronous wait (C++11):
|
||||
* @code
|
||||
* void handler(const asio::error_code& error)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // Timer expired.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* asio::steady_timer timer(my_context,
|
||||
* std::chrono::steady_clock::now() + std::chrono::seconds(60));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
* timer.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Changing an active waitable timer's expiry time
|
||||
*
|
||||
* Changing the expiry time of a timer while there are pending asynchronous
|
||||
* waits causes those wait operations to be cancelled. To ensure that the action
|
||||
* associated with the timer is performed only once, use something like this:
|
||||
* used:
|
||||
*
|
||||
* @code
|
||||
* void on_some_event()
|
||||
* {
|
||||
* if (my_timer.expires_after(seconds(5)) > 0)
|
||||
* {
|
||||
* // We managed to cancel the timer. Start new asynchronous wait.
|
||||
* my_timer.async_wait(on_timeout);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Too late, timer has already expired!
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void on_timeout(const asio::error_code& e)
|
||||
* {
|
||||
* if (e != asio::error::operation_aborted)
|
||||
* {
|
||||
* // Timer was not cancelled, take necessary action.
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @li The asio::basic_waitable_timer::expires_after() function
|
||||
* cancels any pending asynchronous waits, and returns the number of
|
||||
* asynchronous waits that were cancelled. If it returns 0 then you were too
|
||||
* late and the wait handler has already been executed, or will soon be
|
||||
* executed. If it returns 1 then the wait handler was successfully cancelled.
|
||||
*
|
||||
* @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, typename Executor>
|
||||
class basic_waitable_timer
|
||||
{
|
||||
public:
|
||||
/// The type of the executor associated with the object.
|
||||
typedef Executor executor_type;
|
||||
|
||||
/// Rebinds the timer type to another executor.
|
||||
template <typename Executor1>
|
||||
struct rebind_executor
|
||||
{
|
||||
/// The timer type when rebound to the specified executor.
|
||||
typedef basic_waitable_timer<Clock, WaitTraits, Executor1> other;
|
||||
};
|
||||
|
||||
/// The clock type.
|
||||
typedef Clock clock_type;
|
||||
|
||||
/// The duration type of the clock.
|
||||
typedef typename clock_type::duration duration;
|
||||
|
||||
/// The time point type of the clock.
|
||||
typedef typename clock_type::time_point time_point;
|
||||
|
||||
/// The wait traits type.
|
||||
typedef WaitTraits traits_type;
|
||||
|
||||
/// 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 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(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)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @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(const executor_type& ex, const time_point& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code 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");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @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(const executor_type& ex, const duration& expiry_time)
|
||||
: impl_(ex)
|
||||
{
|
||||
asio::error_code 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");
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_waitable_timer from another.
|
||||
/**
|
||||
* This constructor moves a timer from one object to another.
|
||||
*
|
||||
* @param other The other basic_waitable_timer 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_waitable_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_waitable_timer(basic_waitable_timer&& other)
|
||||
: impl_(std::move(other.impl_))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_waitable_timer from another.
|
||||
/**
|
||||
* This assignment operator moves a timer from one object to another. Cancels
|
||||
* any outstanding asynchronous operations associated with the target object.
|
||||
*
|
||||
* @param other The other basic_waitable_timer 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_waitable_timer(const executor_type&)
|
||||
* constructor.
|
||||
*/
|
||||
basic_waitable_timer& operator=(basic_waitable_timer&& other)
|
||||
{
|
||||
impl_ = std::move(other.impl_);
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destroys the timer.
|
||||
/**
|
||||
* This function destroys the timer, cancelling any outstanding asynchronous
|
||||
* wait operations associated with the timer as if by calling @c cancel.
|
||||
*/
|
||||
~basic_waitable_timer()
|
||||
{
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return impl_.get_executor();
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use non-error_code overload.) Cancel any asynchronous
|
||||
/// operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel(asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().cancel(impl_.get_implementation(), ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.get_service().cancel_one(
|
||||
impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use non-error_code overload.) Cancels one asynchronous
|
||||
/// operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one(asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().cancel_one(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expiry().) Get the timer's expiry time as an absolute
|
||||
/// time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_point expires_at() const
|
||||
{
|
||||
return impl_.get_service().expires_at(impl_.get_implementation());
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_point expiry() const
|
||||
{
|
||||
return impl_.get_service().expiry(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_point& expiry_time)
|
||||
{
|
||||
asio::error_code 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;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use non-error_code overload.) Set the timer's expiry time as
|
||||
/// an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_point& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().expires_at(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_after() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_after(const duration& expiry_time)
|
||||
{
|
||||
asio::error_code 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;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated: Use expiry().) Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
duration expires_from_now() const
|
||||
{
|
||||
return impl_.get_service().expires_from_now(impl_.get_implementation());
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expires_after().) Set the timer's expiry time relative
|
||||
/// to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration& expiry_time)
|
||||
{
|
||||
asio::error_code 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;
|
||||
}
|
||||
|
||||
/// (Deprecated: Use expires_after().) Set the timer's expiry time relative
|
||||
/// to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return impl_.get_service().expires_from_now(
|
||||
impl_.get_implementation(), expiry_time, ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void wait()
|
||||
{
|
||||
asio::error_code ec;
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
void wait(asio::error_code& ec)
|
||||
{
|
||||
impl_.get_service().wait(impl_.get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* timer. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li The timer has expired.
|
||||
*
|
||||
* @li The timer was cancelled, in which case the handler is passed the error
|
||||
* code asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the timer expires. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* 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. On
|
||||
* immediate completion, invocation of the handler will be performed in a
|
||||
* manner equivalent to using asio::post().
|
||||
*/
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
|
||||
WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(
|
||||
ASIO_MOVE_ARG(WaitHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return async_initiate<WaitHandler, void (asio::error_code)>(
|
||||
initiate_async_wait(this), handler);
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
basic_waitable_timer(const basic_waitable_timer&) ASIO_DELETED;
|
||||
basic_waitable_timer& operator=(
|
||||
const basic_waitable_timer&) ASIO_DELETED;
|
||||
|
||||
class initiate_async_wait
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
explicit initiate_async_wait(basic_waitable_timer* self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return self_->get_executor();
|
||||
}
|
||||
|
||||
template <typename WaitHandler>
|
||||
void operator()(ASIO_MOVE_ARG(WaitHandler) handler) 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());
|
||||
}
|
||||
|
||||
private:
|
||||
basic_waitable_timer* self_;
|
||||
};
|
||||
|
||||
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"
|
||||
|
||||
#endif // ASIO_BASIC_WAITABLE_TIMER_HPP
|
@ -0,0 +1,580 @@
|
||||
//
|
||||
// bind_executor.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_BIND_EXECUTOR_HPP
|
||||
#define ASIO_BIND_EXECUTOR_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/associated_executor.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/is_executor.hpp"
|
||||
#include "asio/uses_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
struct executor_binder_check
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
// Helper to automatically define nested typedef result_type.
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct executor_binder_result_type
|
||||
{
|
||||
protected:
|
||||
typedef void result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct executor_binder_result_type<T,
|
||||
typename executor_binder_check<typename T::result_type>::type>
|
||||
{
|
||||
typedef typename T::result_type result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename R>
|
||||
struct executor_binder_result_type<R(*)()>
|
||||
{
|
||||
typedef R result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename R>
|
||||
struct executor_binder_result_type<R(&)()>
|
||||
{
|
||||
typedef R result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename R, typename A1>
|
||||
struct executor_binder_result_type<R(*)(A1)>
|
||||
{
|
||||
typedef R result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename R, typename A1>
|
||||
struct executor_binder_result_type<R(&)(A1)>
|
||||
{
|
||||
typedef R result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2>
|
||||
struct executor_binder_result_type<R(*)(A1, A2)>
|
||||
{
|
||||
typedef R result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2>
|
||||
struct executor_binder_result_type<R(&)(A1, A2)>
|
||||
{
|
||||
typedef R result_type;
|
||||
protected:
|
||||
typedef result_type result_type_or_void;
|
||||
};
|
||||
|
||||
// Helper to automatically define nested typedef argument_type.
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct executor_binder_argument_type {};
|
||||
|
||||
template <typename T>
|
||||
struct executor_binder_argument_type<T,
|
||||
typename executor_binder_check<typename T::argument_type>::type>
|
||||
{
|
||||
typedef typename T::argument_type argument_type;
|
||||
};
|
||||
|
||||
template <typename R, typename A1>
|
||||
struct executor_binder_argument_type<R(*)(A1)>
|
||||
{
|
||||
typedef A1 argument_type;
|
||||
};
|
||||
|
||||
template <typename R, typename A1>
|
||||
struct executor_binder_argument_type<R(&)(A1)>
|
||||
{
|
||||
typedef A1 argument_type;
|
||||
};
|
||||
|
||||
// Helper to automatically define nested typedefs first_argument_type and
|
||||
// second_argument_type.
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct executor_binder_argument_types {};
|
||||
|
||||
template <typename T>
|
||||
struct executor_binder_argument_types<T,
|
||||
typename executor_binder_check<typename T::first_argument_type>::type>
|
||||
{
|
||||
typedef typename T::first_argument_type first_argument_type;
|
||||
typedef typename T::second_argument_type second_argument_type;
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2>
|
||||
struct executor_binder_argument_type<R(*)(A1, A2)>
|
||||
{
|
||||
typedef A1 first_argument_type;
|
||||
typedef A2 second_argument_type;
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2>
|
||||
struct executor_binder_argument_type<R(&)(A1, A2)>
|
||||
{
|
||||
typedef A1 first_argument_type;
|
||||
typedef A2 second_argument_type;
|
||||
};
|
||||
|
||||
// Helper to:
|
||||
// - Apply the empty base optimisation to the executor.
|
||||
// - Perform uses_executor construction of the target type, if required.
|
||||
|
||||
template <typename T, typename Executor, bool UsesExecutor>
|
||||
class executor_binder_base;
|
||||
|
||||
template <typename T, typename Executor>
|
||||
class executor_binder_base<T, Executor, true>
|
||||
: protected Executor
|
||||
{
|
||||
protected:
|
||||
template <typename E, typename U>
|
||||
executor_binder_base(ASIO_MOVE_ARG(E) e, ASIO_MOVE_ARG(U) u)
|
||||
: executor_(ASIO_MOVE_CAST(E)(e)),
|
||||
target_(executor_arg_t(), executor_, ASIO_MOVE_CAST(U)(u))
|
||||
{
|
||||
}
|
||||
|
||||
Executor executor_;
|
||||
T target_;
|
||||
};
|
||||
|
||||
template <typename T, typename Executor>
|
||||
class executor_binder_base<T, Executor, false>
|
||||
{
|
||||
protected:
|
||||
template <typename E, typename U>
|
||||
executor_binder_base(ASIO_MOVE_ARG(E) e, ASIO_MOVE_ARG(U) u)
|
||||
: executor_(ASIO_MOVE_CAST(E)(e)),
|
||||
target_(ASIO_MOVE_CAST(U)(u))
|
||||
{
|
||||
}
|
||||
|
||||
Executor executor_;
|
||||
T target_;
|
||||
};
|
||||
|
||||
// Helper to enable SFINAE on zero-argument operator() below.
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct executor_binder_result_of0
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct executor_binder_result_of0<T,
|
||||
typename executor_binder_check<typename result_of<T()>::type>::type>
|
||||
{
|
||||
typedef typename result_of<T()>::type type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// A call wrapper type to bind an executor of type @c Executor to an object of
|
||||
/// type @c T.
|
||||
template <typename T, typename Executor>
|
||||
class executor_binder
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
: public detail::executor_binder_result_type<T>,
|
||||
public detail::executor_binder_argument_type<T>,
|
||||
public detail::executor_binder_argument_types<T>,
|
||||
private detail::executor_binder_base<
|
||||
T, Executor, uses_executor<T, Executor>::value>
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
public:
|
||||
/// The type of the target object.
|
||||
typedef T target_type;
|
||||
|
||||
/// The type of the associated executor.
|
||||
typedef Executor executor_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The return type if a function.
|
||||
/**
|
||||
* The type of @c result_type is based on the type @c T of the wrapper's
|
||||
* target object:
|
||||
*
|
||||
* @li if @c T is a pointer to function type, @c result_type is a synonym for
|
||||
* the return type of @c T;
|
||||
*
|
||||
* @li if @c T is a class type with a member type @c result_type, then @c
|
||||
* result_type is a synonym for @c T::result_type;
|
||||
*
|
||||
* @li otherwise @c result_type is not defined.
|
||||
*/
|
||||
typedef see_below result_type;
|
||||
|
||||
/// The type of the function's argument.
|
||||
/**
|
||||
* The type of @c argument_type is based on the type @c T of the wrapper's
|
||||
* target object:
|
||||
*
|
||||
* @li if @c T is a pointer to a function type accepting a single argument,
|
||||
* @c argument_type is a synonym for the return type of @c T;
|
||||
*
|
||||
* @li if @c T is a class type with a member type @c argument_type, then @c
|
||||
* argument_type is a synonym for @c T::argument_type;
|
||||
*
|
||||
* @li otherwise @c argument_type is not defined.
|
||||
*/
|
||||
typedef see_below argument_type;
|
||||
|
||||
/// The type of the function's first argument.
|
||||
/**
|
||||
* The type of @c first_argument_type is based on the type @c T of the
|
||||
* wrapper's target object:
|
||||
*
|
||||
* @li if @c T is a pointer to a function type accepting two arguments, @c
|
||||
* first_argument_type is a synonym for the return type of @c T;
|
||||
*
|
||||
* @li if @c T is a class type with a member type @c first_argument_type,
|
||||
* then @c first_argument_type is a synonym for @c T::first_argument_type;
|
||||
*
|
||||
* @li otherwise @c first_argument_type is not defined.
|
||||
*/
|
||||
typedef see_below first_argument_type;
|
||||
|
||||
/// The type of the function's second argument.
|
||||
/**
|
||||
* The type of @c second_argument_type is based on the type @c T of the
|
||||
* wrapper's target object:
|
||||
*
|
||||
* @li if @c T is a pointer to a function type accepting two arguments, @c
|
||||
* second_argument_type is a synonym for the return type of @c T;
|
||||
*
|
||||
* @li if @c T is a class type with a member type @c first_argument_type,
|
||||
* then @c second_argument_type is a synonym for @c T::second_argument_type;
|
||||
*
|
||||
* @li otherwise @c second_argument_type is not defined.
|
||||
*/
|
||||
typedef see_below second_argument_type;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Construct an executor wrapper for the specified object.
|
||||
/**
|
||||
* This constructor is only valid if the type @c T is constructible from type
|
||||
* @c U.
|
||||
*/
|
||||
template <typename U>
|
||||
executor_binder(executor_arg_t, const executor_type& e,
|
||||
ASIO_MOVE_ARG(U) u)
|
||||
: base_type(e, ASIO_MOVE_CAST(U)(u))
|
||||
{
|
||||
}
|
||||
|
||||
/// Copy constructor.
|
||||
executor_binder(const executor_binder& other)
|
||||
: base_type(other.get_executor(), other.get())
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a copy, but specify a different executor.
|
||||
executor_binder(executor_arg_t, const executor_type& e,
|
||||
const executor_binder& other)
|
||||
: base_type(e, other.get())
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a copy of a different executor wrapper type.
|
||||
/**
|
||||
* This constructor is only valid if the @c Executor type is constructible
|
||||
* from type @c OtherExecutor, and the type @c T is constructible from type
|
||||
* @c U.
|
||||
*/
|
||||
template <typename U, typename OtherExecutor>
|
||||
executor_binder(const executor_binder<U, OtherExecutor>& other)
|
||||
: base_type(other.get_executor(), other.get())
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a copy of a different executor wrapper type, but specify a
|
||||
/// different executor.
|
||||
/**
|
||||
* This constructor is only valid if the type @c T is constructible from type
|
||||
* @c U.
|
||||
*/
|
||||
template <typename U, typename OtherExecutor>
|
||||
executor_binder(executor_arg_t, const executor_type& e,
|
||||
const executor_binder<U, OtherExecutor>& other)
|
||||
: base_type(e, other.get())
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Move constructor.
|
||||
executor_binder(executor_binder&& other)
|
||||
: base_type(ASIO_MOVE_CAST(executor_type)(other.get_executor()),
|
||||
ASIO_MOVE_CAST(T)(other.get()))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move construct the target object, but specify a different executor.
|
||||
executor_binder(executor_arg_t, const executor_type& e,
|
||||
executor_binder&& other)
|
||||
: base_type(e, ASIO_MOVE_CAST(T)(other.get()))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move construct from a different executor wrapper type.
|
||||
template <typename U, typename OtherExecutor>
|
||||
executor_binder(executor_binder<U, OtherExecutor>&& other)
|
||||
: base_type(ASIO_MOVE_CAST(OtherExecutor)(other.get_executor()),
|
||||
ASIO_MOVE_CAST(U)(other.get()))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move construct from a different executor wrapper type, but specify a
|
||||
/// different executor.
|
||||
template <typename U, typename OtherExecutor>
|
||||
executor_binder(executor_arg_t, const executor_type& e,
|
||||
executor_binder<U, OtherExecutor>&& other)
|
||||
: base_type(e, ASIO_MOVE_CAST(U)(other.get()))
|
||||
{
|
||||
}
|
||||
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destructor.
|
||||
~executor_binder()
|
||||
{
|
||||
}
|
||||
|
||||
/// Obtain a reference to the target object.
|
||||
target_type& get() ASIO_NOEXCEPT
|
||||
{
|
||||
return this->target_;
|
||||
}
|
||||
|
||||
/// Obtain a reference to the target object.
|
||||
const target_type& get() const ASIO_NOEXCEPT
|
||||
{
|
||||
return this->target_;
|
||||
}
|
||||
|
||||
/// Obtain the associated executor.
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return this->executor_;
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename... Args> auto operator()(Args&& ...);
|
||||
template <typename... Args> auto operator()(Args&& ...) const;
|
||||
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
/// Forwarding function call operator.
|
||||
template <typename... Args>
|
||||
typename result_of<T(Args...)>::type operator()(
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
return this->target_(ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
/// Forwarding function call operator.
|
||||
template <typename... Args>
|
||||
typename result_of<T(Args...)>::type operator()(
|
||||
ASIO_MOVE_ARG(Args)... args) const
|
||||
{
|
||||
return this->target_(ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#elif defined(ASIO_HAS_STD_TYPE_TRAITS) && !defined(_MSC_VER)
|
||||
|
||||
typename detail::executor_binder_result_of0<T>::type operator()()
|
||||
{
|
||||
return this->target_();
|
||||
}
|
||||
|
||||
typename detail::executor_binder_result_of0<T>::type operator()() const
|
||||
{
|
||||
return this->target_();
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_BIND_EXECUTOR_CALL_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
typename result_of<T(ASIO_VARIADIC_TARGS(n))>::type operator()( \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
return this->target_(ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
\
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
typename result_of<T(ASIO_VARIADIC_TARGS(n))>::type operator()( \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) const \
|
||||
{ \
|
||||
return this->target_(ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_BIND_EXECUTOR_CALL_DEF)
|
||||
#undef ASIO_PRIVATE_BIND_EXECUTOR_CALL_DEF
|
||||
|
||||
#else // defined(ASIO_HAS_STD_TYPE_TRAITS) && !defined(_MSC_VER)
|
||||
|
||||
typedef typename detail::executor_binder_result_type<T>::result_type_or_void
|
||||
result_type_or_void;
|
||||
|
||||
result_type_or_void operator()()
|
||||
{
|
||||
return this->target_();
|
||||
}
|
||||
|
||||
result_type_or_void operator()() const
|
||||
{
|
||||
return this->target_();
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_BIND_EXECUTOR_CALL_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
result_type_or_void operator()( \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
return this->target_(ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
\
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
result_type_or_void operator()( \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) const \
|
||||
{ \
|
||||
return this->target_(ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_BIND_EXECUTOR_CALL_DEF)
|
||||
#undef ASIO_PRIVATE_BIND_EXECUTOR_CALL_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_STD_TYPE_TRAITS) && !defined(_MSC_VER)
|
||||
|
||||
private:
|
||||
typedef detail::executor_binder_base<T, Executor,
|
||||
uses_executor<T, Executor>::value> base_type;
|
||||
};
|
||||
|
||||
/// Associate an object of type @c T with an executor of type @c Executor.
|
||||
template <typename Executor, typename T>
|
||||
inline executor_binder<typename decay<T>::type, Executor>
|
||||
bind_executor(const Executor& ex, ASIO_MOVE_ARG(T) t,
|
||||
typename enable_if<is_executor<Executor>::value>::type* = 0)
|
||||
{
|
||||
return executor_binder<typename decay<T>::type, Executor>(
|
||||
executor_arg_t(), ex, ASIO_MOVE_CAST(T)(t));
|
||||
}
|
||||
|
||||
/// Associate an object of type @c T with an execution context's executor.
|
||||
template <typename ExecutionContext, typename T>
|
||||
inline executor_binder<typename decay<T>::type,
|
||||
typename ExecutionContext::executor_type>
|
||||
bind_executor(ExecutionContext& ctx, ASIO_MOVE_ARG(T) t,
|
||||
typename enable_if<is_convertible<
|
||||
ExecutionContext&, execution_context&>::value>::type* = 0)
|
||||
{
|
||||
return executor_binder<typename decay<T>::type,
|
||||
typename ExecutionContext::executor_type>(
|
||||
executor_arg_t(), ctx.get_executor(), ASIO_MOVE_CAST(T)(t));
|
||||
}
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename T, typename Executor>
|
||||
struct uses_executor<executor_binder<T, Executor>, Executor>
|
||||
: true_type {};
|
||||
|
||||
template <typename T, typename Executor, typename Signature>
|
||||
class async_result<executor_binder<T, Executor>, Signature>
|
||||
{
|
||||
public:
|
||||
typedef executor_binder<
|
||||
typename async_result<T, Signature>::completion_handler_type, Executor>
|
||||
completion_handler_type;
|
||||
|
||||
typedef typename async_result<T, Signature>::return_type return_type;
|
||||
|
||||
explicit async_result(executor_binder<T, Executor>& b)
|
||||
: target_(b.get())
|
||||
{
|
||||
}
|
||||
|
||||
return_type get()
|
||||
{
|
||||
return target_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
async_result(const async_result&) ASIO_DELETED;
|
||||
async_result& operator=(const async_result&) ASIO_DELETED;
|
||||
|
||||
async_result<T, Signature> target_;
|
||||
};
|
||||
|
||||
template <typename T, typename Executor, typename Allocator>
|
||||
struct associated_allocator<executor_binder<T, Executor>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<T, Allocator>::type type;
|
||||
|
||||
static type get(const executor_binder<T, Executor>& b,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<T, Allocator>::get(b.get(), a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Executor, typename Executor1>
|
||||
struct associated_executor<executor_binder<T, Executor>, Executor1>
|
||||
{
|
||||
typedef Executor type;
|
||||
|
||||
static type get(const executor_binder<T, Executor>& b,
|
||||
const Executor1& = Executor1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return b.get_executor();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BIND_EXECUTOR_HPP
|
2494
tools/sdk/esp32/include/asio/asio/asio/include/asio/buffer.hpp
Normal file
2494
tools/sdk/esp32/include/asio/asio/asio/include/asio/buffer.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,253 @@
|
||||
//
|
||||
// buffered_read_stream.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_BUFFERED_READ_STREAM_HPP
|
||||
#define ASIO_BUFFERED_READ_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/buffered_read_stream_fwd.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/buffer_resize_guard.hpp"
|
||||
#include "asio/detail/buffered_stream_storage.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Adds buffering to the read-related operations of a stream.
|
||||
/**
|
||||
* The buffered_read_stream class template can be used to add buffering to the
|
||||
* synchronous and asynchronous read operations of a stream.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Stream>
|
||||
class buffered_read_stream
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
|
||||
/// The type of the lowest layer.
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
|
||||
/// The type of the executor associated with the object.
|
||||
typedef typename lowest_layer_type::executor_type executor_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The default buffer size.
|
||||
static const std::size_t default_buffer_size = implementation_defined;
|
||||
#else
|
||||
ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
|
||||
#endif
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_read_stream(Arg& a)
|
||||
: next_layer_(a),
|
||||
storage_(default_buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
buffered_read_stream(Arg& a, std::size_t buffer_size)
|
||||
: next_layer_(a),
|
||||
storage_(buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a reference to the next layer.
|
||||
next_layer_type& next_layer()
|
||||
{
|
||||
return next_layer_;
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
next_layer_.close();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
ASIO_SYNC_OP_VOID close(asio::error_code& ec)
|
||||
{
|
||||
next_layer_.close(ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written.
|
||||
/// Throws an exception on failure.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
return next_layer_.write_some(buffers);
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.write_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write. The data being written must be valid for the
|
||||
/// lifetime of the asynchronous operation.
|
||||
template <typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return next_layer_.async_write_some(buffers,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation. Throws an exception on failure.
|
||||
std::size_t fill();
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation, or 0 if an error occurred.
|
||||
std::size_t fill(asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous fill.
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_fill(
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type));
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read. Throws
|
||||
/// an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers);
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read or 0 if
|
||||
/// an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous read. The buffer into which the data will be read
|
||||
/// must be valid for the lifetime of the asynchronous operation.
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type));
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read.
|
||||
/// Throws an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers);
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec);
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail()
|
||||
{
|
||||
return storage_.size();
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail(asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return storage_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
/// Copy data out of the internal buffer to the specified target buffer.
|
||||
/// Returns the number of bytes copied.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t copy(const MutableBufferSequence& buffers)
|
||||
{
|
||||
std::size_t bytes_copied = asio::buffer_copy(
|
||||
buffers, storage_.data(), storage_.size());
|
||||
storage_.consume(bytes_copied);
|
||||
return bytes_copied;
|
||||
}
|
||||
|
||||
/// Copy data from the internal buffer to the specified target buffer, without
|
||||
/// removing the data from the internal buffer. Returns the number of bytes
|
||||
/// copied.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek_copy(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return asio::buffer_copy(buffers, storage_.data(), storage_.size());
|
||||
}
|
||||
|
||||
/// The next layer.
|
||||
Stream next_layer_;
|
||||
|
||||
// The data in the buffer.
|
||||
detail::buffered_stream_storage storage_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/buffered_read_stream.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERED_READ_STREAM_HPP
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// buffered_read_stream_fwd.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_BUFFERED_READ_STREAM_FWD_HPP
|
||||
#define ASIO_BUFFERED_READ_STREAM_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Stream>
|
||||
class buffered_read_stream;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BUFFERED_READ_STREAM_FWD_HPP
|
@ -0,0 +1,279 @@
|
||||
//
|
||||
// buffered_stream.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_BUFFERED_STREAM_HPP
|
||||
#define ASIO_BUFFERED_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/buffered_stream_fwd.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Adds buffering to the read- and write-related operations of a stream.
|
||||
/**
|
||||
* The buffered_stream class template can be used to add buffering to the
|
||||
* synchronous and asynchronous read and write operations of a stream.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Stream>
|
||||
class buffered_stream
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
|
||||
/// The type of the lowest layer.
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
|
||||
/// The type of the executor associated with the object.
|
||||
typedef typename lowest_layer_type::executor_type executor_type;
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_stream(Arg& a)
|
||||
: inner_stream_impl_(a),
|
||||
stream_impl_(inner_stream_impl_)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_stream(Arg& a, std::size_t read_buffer_size,
|
||||
std::size_t write_buffer_size)
|
||||
: inner_stream_impl_(a, write_buffer_size),
|
||||
stream_impl_(inner_stream_impl_, read_buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a reference to the next layer.
|
||||
next_layer_type& next_layer()
|
||||
{
|
||||
return stream_impl_.next_layer().next_layer();
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return stream_impl_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return stream_impl_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return stream_impl_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
stream_impl_.close();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
ASIO_SYNC_OP_VOID close(asio::error_code& ec)
|
||||
{
|
||||
stream_impl_.close(ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation. Throws an
|
||||
/// exception on failure.
|
||||
std::size_t flush()
|
||||
{
|
||||
return stream_impl_.next_layer().flush();
|
||||
}
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation, or 0 if an
|
||||
/// error occurred.
|
||||
std::size_t flush(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.next_layer().flush(ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous flush.
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_flush(
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return stream_impl_.next_layer().async_flush(
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written.
|
||||
/// Throws an exception on failure.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
return stream_impl_.write_some(buffers);
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.write_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write. The data being written must be valid for the
|
||||
/// lifetime of the asynchronous operation.
|
||||
template <typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return stream_impl_.async_write_some(buffers,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation. Throws an exception on failure.
|
||||
std::size_t fill()
|
||||
{
|
||||
return stream_impl_.fill();
|
||||
}
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation, or 0 if an error occurred.
|
||||
std::size_t fill(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.fill(ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous fill.
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_fill(
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return stream_impl_.async_fill(ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read. Throws
|
||||
/// an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return stream_impl_.read_some(buffers);
|
||||
}
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read or 0 if
|
||||
/// an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.read_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read. The buffer into which the data will be read
|
||||
/// must be valid for the lifetime of the asynchronous operation.
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return stream_impl_.async_read_some(buffers,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read.
|
||||
/// Throws an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return stream_impl_.peek(buffers);
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.peek(buffers, ec);
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail()
|
||||
{
|
||||
return stream_impl_.in_avail();
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.in_avail(ec);
|
||||
}
|
||||
|
||||
private:
|
||||
// The buffered write stream.
|
||||
typedef buffered_write_stream<Stream> write_stream_type;
|
||||
write_stream_type inner_stream_impl_;
|
||||
|
||||
// The buffered read stream.
|
||||
typedef buffered_read_stream<write_stream_type&> read_stream_type;
|
||||
read_stream_type stream_impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERED_STREAM_HPP
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// buffered_stream_fwd.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_BUFFERED_STREAM_FWD_HPP
|
||||
#define ASIO_BUFFERED_STREAM_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Stream>
|
||||
class buffered_stream;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BUFFERED_STREAM_FWD_HPP
|
@ -0,0 +1,245 @@
|
||||
//
|
||||
// buffered_write_stream.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_BUFFERED_WRITE_STREAM_HPP
|
||||
#define ASIO_BUFFERED_WRITE_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/buffered_write_stream_fwd.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/buffered_stream_storage.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/write.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Adds buffering to the write-related operations of a stream.
|
||||
/**
|
||||
* The buffered_write_stream class template can be used to add buffering to the
|
||||
* synchronous and asynchronous write operations of a stream.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Stream>
|
||||
class buffered_write_stream
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
|
||||
/// The type of the lowest layer.
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
|
||||
/// The type of the executor associated with the object.
|
||||
typedef typename lowest_layer_type::executor_type executor_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The default buffer size.
|
||||
static const std::size_t default_buffer_size = implementation_defined;
|
||||
#else
|
||||
ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
|
||||
#endif
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_write_stream(Arg& a)
|
||||
: next_layer_(a),
|
||||
storage_(default_buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
buffered_write_stream(Arg& a, std::size_t buffer_size)
|
||||
: next_layer_(a),
|
||||
storage_(buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a reference to the next layer.
|
||||
next_layer_type& next_layer()
|
||||
{
|
||||
return next_layer_;
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get the executor associated with the object.
|
||||
executor_type get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
next_layer_.close();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
ASIO_SYNC_OP_VOID close(asio::error_code& ec)
|
||||
{
|
||||
next_layer_.close(ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation. Throws an
|
||||
/// exception on failure.
|
||||
std::size_t flush();
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation, or 0 if an
|
||||
/// error occurred.
|
||||
std::size_t flush(asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous flush.
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_flush(
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type));
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written.
|
||||
/// Throws an exception on failure.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers);
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written,
|
||||
/// or 0 if an error occurred and the error handler did not throw.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous write. The data being written must be valid for the
|
||||
/// lifetime of the asynchronous operation.
|
||||
template <typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type));
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read. Throws
|
||||
/// an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return next_layer_.read_some(buffers);
|
||||
}
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read or 0 if
|
||||
/// an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.read_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read. The buffer into which the data will be read
|
||||
/// must be valid for the lifetime of the asynchronous operation.
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
|
||||
{
|
||||
return next_layer_.async_read_some(buffers,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read.
|
||||
/// Throws an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return next_layer_.peek(buffers);
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.peek(buffers, ec);
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail()
|
||||
{
|
||||
return next_layer_.in_avail();
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail(asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.in_avail(ec);
|
||||
}
|
||||
|
||||
private:
|
||||
/// Copy data into the internal buffer from the specified source buffer.
|
||||
/// Returns the number of bytes copied.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t copy(const ConstBufferSequence& buffers);
|
||||
|
||||
/// The next layer.
|
||||
Stream next_layer_;
|
||||
|
||||
// The data in the buffer.
|
||||
detail::buffered_stream_storage storage_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/buffered_write_stream.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERED_WRITE_STREAM_HPP
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// buffered_write_stream_fwd.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_BUFFERED_WRITE_STREAM_FWD_HPP
|
||||
#define ASIO_BUFFERED_WRITE_STREAM_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Stream>
|
||||
class buffered_write_stream;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BUFFERED_WRITE_STREAM_FWD_HPP
|
@ -0,0 +1,521 @@
|
||||
//
|
||||
// buffers_iterator.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_BUFFERS_ITERATOR_HPP
|
||||
#define ASIO_BUFFERS_ITERATOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/assert.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool IsMutable>
|
||||
struct buffers_iterator_types_helper;
|
||||
|
||||
template <>
|
||||
struct buffers_iterator_types_helper<false>
|
||||
{
|
||||
typedef const_buffer buffer_type;
|
||||
template <typename ByteType>
|
||||
struct byte_type
|
||||
{
|
||||
typedef typename add_const<ByteType>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct buffers_iterator_types_helper<true>
|
||||
{
|
||||
typedef mutable_buffer buffer_type;
|
||||
template <typename ByteType>
|
||||
struct byte_type
|
||||
{
|
||||
typedef ByteType type;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename BufferSequence, typename ByteType>
|
||||
struct buffers_iterator_types
|
||||
{
|
||||
enum
|
||||
{
|
||||
is_mutable = is_convertible<
|
||||
typename BufferSequence::value_type,
|
||||
mutable_buffer>::value
|
||||
};
|
||||
typedef buffers_iterator_types_helper<is_mutable> helper;
|
||||
typedef typename helper::buffer_type buffer_type;
|
||||
typedef typename helper::template byte_type<ByteType>::type byte_type;
|
||||
typedef typename BufferSequence::const_iterator const_iterator;
|
||||
};
|
||||
|
||||
template <typename ByteType>
|
||||
struct buffers_iterator_types<mutable_buffer, ByteType>
|
||||
{
|
||||
typedef mutable_buffer buffer_type;
|
||||
typedef ByteType byte_type;
|
||||
typedef const mutable_buffer* const_iterator;
|
||||
};
|
||||
|
||||
template <typename ByteType>
|
||||
struct buffers_iterator_types<const_buffer, ByteType>
|
||||
{
|
||||
typedef const_buffer buffer_type;
|
||||
typedef typename add_const<ByteType>::type byte_type;
|
||||
typedef const const_buffer* const_iterator;
|
||||
};
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename ByteType>
|
||||
struct buffers_iterator_types<mutable_buffers_1, ByteType>
|
||||
{
|
||||
typedef mutable_buffer buffer_type;
|
||||
typedef ByteType byte_type;
|
||||
typedef const mutable_buffer* const_iterator;
|
||||
};
|
||||
|
||||
template <typename ByteType>
|
||||
struct buffers_iterator_types<const_buffers_1, ByteType>
|
||||
{
|
||||
typedef const_buffer buffer_type;
|
||||
typedef typename add_const<ByteType>::type byte_type;
|
||||
typedef const const_buffer* const_iterator;
|
||||
};
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
/// A random access iterator over the bytes in a buffer sequence.
|
||||
template <typename BufferSequence, typename ByteType = char>
|
||||
class buffers_iterator
|
||||
{
|
||||
private:
|
||||
typedef typename detail::buffers_iterator_types<
|
||||
BufferSequence, ByteType>::buffer_type buffer_type;
|
||||
|
||||
typedef typename detail::buffers_iterator_types<BufferSequence,
|
||||
ByteType>::const_iterator buffer_sequence_iterator_type;
|
||||
|
||||
public:
|
||||
/// The type used for the distance between two iterators.
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
/// The type of the value pointed to by the iterator.
|
||||
typedef ByteType value_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type of the result of applying operator->() to the iterator.
|
||||
/**
|
||||
* If the buffer sequence stores buffer objects that are convertible to
|
||||
* mutable_buffer, this is a pointer to a non-const ByteType. Otherwise, a
|
||||
* pointer to a const ByteType.
|
||||
*/
|
||||
typedef const_or_non_const_ByteType* pointer;
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
typedef typename detail::buffers_iterator_types<
|
||||
BufferSequence, ByteType>::byte_type* pointer;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type of the result of applying operator*() to the iterator.
|
||||
/**
|
||||
* If the buffer sequence stores buffer objects that are convertible to
|
||||
* mutable_buffer, this is a reference to a non-const ByteType. Otherwise, a
|
||||
* reference to a const ByteType.
|
||||
*/
|
||||
typedef const_or_non_const_ByteType& reference;
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
typedef typename detail::buffers_iterator_types<
|
||||
BufferSequence, ByteType>::byte_type& reference;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// The iterator category.
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
|
||||
/// Default constructor. Creates an iterator in an undefined state.
|
||||
buffers_iterator()
|
||||
: current_buffer_(),
|
||||
current_buffer_position_(0),
|
||||
begin_(),
|
||||
current_(),
|
||||
end_(),
|
||||
position_(0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct an iterator representing the beginning of the buffers' data.
|
||||
static buffers_iterator begin(const BufferSequence& buffers)
|
||||
#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
__attribute__ ((__noinline__))
|
||||
#endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
{
|
||||
buffers_iterator new_iter;
|
||||
new_iter.begin_ = asio::buffer_sequence_begin(buffers);
|
||||
new_iter.current_ = asio::buffer_sequence_begin(buffers);
|
||||
new_iter.end_ = asio::buffer_sequence_end(buffers);
|
||||
while (new_iter.current_ != new_iter.end_)
|
||||
{
|
||||
new_iter.current_buffer_ = *new_iter.current_;
|
||||
if (new_iter.current_buffer_.size() > 0)
|
||||
break;
|
||||
++new_iter.current_;
|
||||
}
|
||||
return new_iter;
|
||||
}
|
||||
|
||||
/// Construct an iterator representing the end of the buffers' data.
|
||||
static buffers_iterator end(const BufferSequence& buffers)
|
||||
#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
__attribute__ ((__noinline__))
|
||||
#endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
{
|
||||
buffers_iterator new_iter;
|
||||
new_iter.begin_ = asio::buffer_sequence_begin(buffers);
|
||||
new_iter.current_ = asio::buffer_sequence_begin(buffers);
|
||||
new_iter.end_ = asio::buffer_sequence_end(buffers);
|
||||
while (new_iter.current_ != new_iter.end_)
|
||||
{
|
||||
buffer_type buffer = *new_iter.current_;
|
||||
new_iter.position_ += buffer.size();
|
||||
++new_iter.current_;
|
||||
}
|
||||
return new_iter;
|
||||
}
|
||||
|
||||
/// Dereference an iterator.
|
||||
reference operator*() const
|
||||
{
|
||||
return dereference();
|
||||
}
|
||||
|
||||
/// Dereference an iterator.
|
||||
pointer operator->() const
|
||||
{
|
||||
return &dereference();
|
||||
}
|
||||
|
||||
/// Access an individual element.
|
||||
reference operator[](std::ptrdiff_t difference) const
|
||||
{
|
||||
buffers_iterator tmp(*this);
|
||||
tmp.advance(difference);
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
/// Increment operator (prefix).
|
||||
buffers_iterator& operator++()
|
||||
{
|
||||
increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Increment operator (postfix).
|
||||
buffers_iterator operator++(int)
|
||||
{
|
||||
buffers_iterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Decrement operator (prefix).
|
||||
buffers_iterator& operator--()
|
||||
{
|
||||
decrement();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Decrement operator (postfix).
|
||||
buffers_iterator operator--(int)
|
||||
{
|
||||
buffers_iterator tmp(*this);
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Addition operator.
|
||||
buffers_iterator& operator+=(std::ptrdiff_t difference)
|
||||
{
|
||||
advance(difference);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Subtraction operator.
|
||||
buffers_iterator& operator-=(std::ptrdiff_t difference)
|
||||
{
|
||||
advance(-difference);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Addition operator.
|
||||
friend buffers_iterator operator+(const buffers_iterator& iter,
|
||||
std::ptrdiff_t difference)
|
||||
{
|
||||
buffers_iterator tmp(iter);
|
||||
tmp.advance(difference);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Addition operator.
|
||||
friend buffers_iterator operator+(std::ptrdiff_t difference,
|
||||
const buffers_iterator& iter)
|
||||
{
|
||||
buffers_iterator tmp(iter);
|
||||
tmp.advance(difference);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Subtraction operator.
|
||||
friend buffers_iterator operator-(const buffers_iterator& iter,
|
||||
std::ptrdiff_t difference)
|
||||
{
|
||||
buffers_iterator tmp(iter);
|
||||
tmp.advance(-difference);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Subtraction operator.
|
||||
friend std::ptrdiff_t operator-(const buffers_iterator& a,
|
||||
const buffers_iterator& b)
|
||||
{
|
||||
return b.distance_to(a);
|
||||
}
|
||||
|
||||
/// Test two iterators for equality.
|
||||
friend bool operator==(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return a.equal(b);
|
||||
}
|
||||
|
||||
/// Test two iterators for inequality.
|
||||
friend bool operator!=(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return !a.equal(b);
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator<(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return a.distance_to(b) > 0;
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator<=(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return !(b < a);
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator>(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return b < a;
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator>=(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return !(a < b);
|
||||
}
|
||||
|
||||
private:
|
||||
// Dereference the iterator.
|
||||
reference dereference() const
|
||||
{
|
||||
return static_cast<pointer>(
|
||||
current_buffer_.data())[current_buffer_position_];
|
||||
}
|
||||
|
||||
// Compare two iterators for equality.
|
||||
bool equal(const buffers_iterator& other) const
|
||||
{
|
||||
return position_ == other.position_;
|
||||
}
|
||||
|
||||
// Increment the iterator.
|
||||
void increment()
|
||||
{
|
||||
ASIO_ASSERT(current_ != end_ && "iterator out of bounds");
|
||||
++position_;
|
||||
|
||||
// Check if the increment can be satisfied by the current buffer.
|
||||
++current_buffer_position_;
|
||||
if (current_buffer_position_ != current_buffer_.size())
|
||||
return;
|
||||
|
||||
// Find the next non-empty buffer.
|
||||
++current_;
|
||||
current_buffer_position_ = 0;
|
||||
while (current_ != end_)
|
||||
{
|
||||
current_buffer_ = *current_;
|
||||
if (current_buffer_.size() > 0)
|
||||
return;
|
||||
++current_;
|
||||
}
|
||||
}
|
||||
|
||||
// Decrement the iterator.
|
||||
void decrement()
|
||||
{
|
||||
ASIO_ASSERT(position_ > 0 && "iterator out of bounds");
|
||||
--position_;
|
||||
|
||||
// Check if the decrement can be satisfied by the current buffer.
|
||||
if (current_buffer_position_ != 0)
|
||||
{
|
||||
--current_buffer_position_;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the previous non-empty buffer.
|
||||
buffer_sequence_iterator_type iter = current_;
|
||||
while (iter != begin_)
|
||||
{
|
||||
--iter;
|
||||
buffer_type buffer = *iter;
|
||||
std::size_t buffer_size = buffer.size();
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
current_ = iter;
|
||||
current_buffer_ = buffer;
|
||||
current_buffer_position_ = buffer_size - 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Advance the iterator by the specified distance.
|
||||
void advance(std::ptrdiff_t n)
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
ASIO_ASSERT(current_ != end_ && "iterator out of bounds");
|
||||
for (;;)
|
||||
{
|
||||
std::ptrdiff_t current_buffer_balance
|
||||
= current_buffer_.size() - current_buffer_position_;
|
||||
|
||||
// Check if the advance can be satisfied by the current buffer.
|
||||
if (current_buffer_balance > n)
|
||||
{
|
||||
position_ += n;
|
||||
current_buffer_position_ += n;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update position.
|
||||
n -= current_buffer_balance;
|
||||
position_ += current_buffer_balance;
|
||||
|
||||
// Move to next buffer. If it is empty then it will be skipped on the
|
||||
// next iteration of this loop.
|
||||
if (++current_ == end_)
|
||||
{
|
||||
ASIO_ASSERT(n == 0 && "iterator out of bounds");
|
||||
current_buffer_ = buffer_type();
|
||||
current_buffer_position_ = 0;
|
||||
return;
|
||||
}
|
||||
current_buffer_ = *current_;
|
||||
current_buffer_position_ = 0;
|
||||
}
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
std::size_t abs_n = -n;
|
||||
ASIO_ASSERT(position_ >= abs_n && "iterator out of bounds");
|
||||
for (;;)
|
||||
{
|
||||
// Check if the advance can be satisfied by the current buffer.
|
||||
if (current_buffer_position_ >= abs_n)
|
||||
{
|
||||
position_ -= abs_n;
|
||||
current_buffer_position_ -= abs_n;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update position.
|
||||
abs_n -= current_buffer_position_;
|
||||
position_ -= current_buffer_position_;
|
||||
|
||||
// Check if we've reached the beginning of the buffers.
|
||||
if (current_ == begin_)
|
||||
{
|
||||
ASIO_ASSERT(abs_n == 0 && "iterator out of bounds");
|
||||
current_buffer_position_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the previous non-empty buffer.
|
||||
buffer_sequence_iterator_type iter = current_;
|
||||
while (iter != begin_)
|
||||
{
|
||||
--iter;
|
||||
buffer_type buffer = *iter;
|
||||
std::size_t buffer_size = buffer.size();
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
current_ = iter;
|
||||
current_buffer_ = buffer;
|
||||
current_buffer_position_ = buffer_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the distance between two iterators.
|
||||
std::ptrdiff_t distance_to(const buffers_iterator& other) const
|
||||
{
|
||||
return other.position_ - position_;
|
||||
}
|
||||
|
||||
buffer_type current_buffer_;
|
||||
std::size_t current_buffer_position_;
|
||||
buffer_sequence_iterator_type begin_;
|
||||
buffer_sequence_iterator_type current_;
|
||||
buffer_sequence_iterator_type end_;
|
||||
std::size_t position_;
|
||||
};
|
||||
|
||||
/// Construct an iterator representing the beginning of the buffers' data.
|
||||
template <typename BufferSequence>
|
||||
inline buffers_iterator<BufferSequence> buffers_begin(
|
||||
const BufferSequence& buffers)
|
||||
{
|
||||
return buffers_iterator<BufferSequence>::begin(buffers);
|
||||
}
|
||||
|
||||
/// Construct an iterator representing the end of the buffers' data.
|
||||
template <typename BufferSequence>
|
||||
inline buffers_iterator<BufferSequence> buffers_end(
|
||||
const BufferSequence& buffers)
|
||||
{
|
||||
return buffers_iterator<BufferSequence>::end(buffers);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERS_ITERATOR_HPP
|
100
tools/sdk/esp32/include/asio/asio/asio/include/asio/co_spawn.hpp
Normal file
100
tools/sdk/esp32/include/asio/asio/asio/include/asio/co_spawn.hpp
Normal file
@ -0,0 +1,100 @@
|
||||
//
|
||||
// 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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
|
||||
typename result_of<F()>::type>::type) CompletionToken
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
|
||||
typename detail::awaitable_signature<typename result_of<F()>::type>::type)
|
||||
co_spawn(const Executor& ex, F&& f,
|
||||
CompletionToken&& token
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
|
||||
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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
|
||||
typename result_of<F()>::type>::type) CompletionToken
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
|
||||
typename ExecutionContext::executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
|
||||
typename detail::awaitable_signature<typename result_of<F()>::type>::type)
|
||||
co_spawn(ExecutionContext& ctx, F&& f,
|
||||
CompletionToken&& token
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(
|
||||
typename ExecutionContext::executor_type),
|
||||
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
|
@ -0,0 +1,218 @@
|
||||
//
|
||||
// completion_condition.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_COMPLETION_CONDITION_HPP
|
||||
#define ASIO_COMPLETION_CONDITION_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// The default maximum number of bytes to transfer in a single operation.
|
||||
enum default_max_transfer_size_t { default_max_transfer_size = 65536 };
|
||||
|
||||
// Adapt result of old-style completion conditions (which had a bool result
|
||||
// where true indicated that the operation was complete).
|
||||
inline std::size_t adapt_completion_condition_result(bool result)
|
||||
{
|
||||
return result ? 0 : default_max_transfer_size;
|
||||
}
|
||||
|
||||
// Adapt result of current completion conditions (which have a size_t result
|
||||
// where 0 means the operation is complete, and otherwise the result is the
|
||||
// maximum number of bytes to transfer on the next underlying operation).
|
||||
inline std::size_t adapt_completion_condition_result(std::size_t result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
class transfer_all_t
|
||||
{
|
||||
public:
|
||||
typedef std::size_t result_type;
|
||||
|
||||
template <typename Error>
|
||||
std::size_t operator()(const Error& err, std::size_t)
|
||||
{
|
||||
return !!err ? 0 : default_max_transfer_size;
|
||||
}
|
||||
};
|
||||
|
||||
class transfer_at_least_t
|
||||
{
|
||||
public:
|
||||
typedef std::size_t result_type;
|
||||
|
||||
explicit transfer_at_least_t(std::size_t minimum)
|
||||
: minimum_(minimum)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Error>
|
||||
std::size_t operator()(const Error& err, std::size_t bytes_transferred)
|
||||
{
|
||||
return (!!err || bytes_transferred >= minimum_)
|
||||
? 0 : default_max_transfer_size;
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t minimum_;
|
||||
};
|
||||
|
||||
class transfer_exactly_t
|
||||
{
|
||||
public:
|
||||
typedef std::size_t result_type;
|
||||
|
||||
explicit transfer_exactly_t(std::size_t size)
|
||||
: size_(size)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Error>
|
||||
std::size_t operator()(const Error& err, std::size_t bytes_transferred)
|
||||
{
|
||||
return (!!err || bytes_transferred >= size_) ? 0 :
|
||||
(size_ - bytes_transferred < default_max_transfer_size
|
||||
? size_ - bytes_transferred : std::size_t(default_max_transfer_size));
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t size_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* @defgroup completion_condition Completion Condition Function Objects
|
||||
*
|
||||
* Function objects used for determining when a read or write operation should
|
||||
* complete.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/// Return a completion condition function object that indicates that a read or
|
||||
/// write operation should continue until all of the data has been transferred,
|
||||
/// or until an error occurs.
|
||||
/**
|
||||
* This function is used to create an object, of unspecified type, that meets
|
||||
* CompletionCondition requirements.
|
||||
*
|
||||
* @par Example
|
||||
* Reading until a buffer is full:
|
||||
* @code
|
||||
* boost::array<char, 128> buf;
|
||||
* asio::error_code ec;
|
||||
* std::size_t n = asio::read(
|
||||
* sock, asio::buffer(buf),
|
||||
* asio::transfer_all(), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // n == 128
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
unspecified transfer_all();
|
||||
#else
|
||||
inline detail::transfer_all_t transfer_all()
|
||||
{
|
||||
return detail::transfer_all_t();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Return a completion condition function object that indicates that a read or
|
||||
/// write operation should continue until a minimum number of bytes has been
|
||||
/// transferred, or until an error occurs.
|
||||
/**
|
||||
* This function is used to create an object, of unspecified type, that meets
|
||||
* CompletionCondition requirements.
|
||||
*
|
||||
* @par Example
|
||||
* Reading until a buffer is full or contains at least 64 bytes:
|
||||
* @code
|
||||
* boost::array<char, 128> buf;
|
||||
* asio::error_code ec;
|
||||
* std::size_t n = asio::read(
|
||||
* sock, asio::buffer(buf),
|
||||
* asio::transfer_at_least(64), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // n >= 64 && n <= 128
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
unspecified transfer_at_least(std::size_t minimum);
|
||||
#else
|
||||
inline detail::transfer_at_least_t transfer_at_least(std::size_t minimum)
|
||||
{
|
||||
return detail::transfer_at_least_t(minimum);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Return a completion condition function object that indicates that a read or
|
||||
/// write operation should continue until an exact number of bytes has been
|
||||
/// transferred, or until an error occurs.
|
||||
/**
|
||||
* This function is used to create an object, of unspecified type, that meets
|
||||
* CompletionCondition requirements.
|
||||
*
|
||||
* @par Example
|
||||
* Reading until a buffer is full or contains exactly 64 bytes:
|
||||
* @code
|
||||
* boost::array<char, 128> buf;
|
||||
* asio::error_code ec;
|
||||
* std::size_t n = asio::read(
|
||||
* sock, asio::buffer(buf),
|
||||
* asio::transfer_exactly(64), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // n == 64
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
unspecified transfer_exactly(std::size_t size);
|
||||
#else
|
||||
inline detail::transfer_exactly_t transfer_exactly(std::size_t size)
|
||||
{
|
||||
return detail::transfer_exactly_t(size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*@}*/
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_COMPLETION_CONDITION_HPP
|
136
tools/sdk/esp32/include/asio/asio/asio/include/asio/compose.hpp
Normal file
136
tools/sdk/esp32/include/asio/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_AUTO_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_AUTO_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_AUTO_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
|
1076
tools/sdk/esp32/include/asio/asio/asio/include/asio/connect.hpp
Normal file
1076
tools/sdk/esp32/include/asio/asio/asio/include/asio/connect.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,328 @@
|
||||
//
|
||||
// coroutine.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_COROUTINE_HPP
|
||||
#define ASIO_COROUTINE_HPP
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class coroutine_ref;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Provides support for implementing stackless coroutines.
|
||||
/**
|
||||
* The @c coroutine class may be used to implement stackless coroutines. The
|
||||
* class itself is used to store the current state of the coroutine.
|
||||
*
|
||||
* Coroutines are copy-constructible and assignable, and the space overhead is
|
||||
* a single int. They can be used as a base class:
|
||||
*
|
||||
* @code class session : coroutine
|
||||
* {
|
||||
* ...
|
||||
* }; @endcode
|
||||
*
|
||||
* or as a data member:
|
||||
*
|
||||
* @code class session
|
||||
* {
|
||||
* ...
|
||||
* coroutine coro_;
|
||||
* }; @endcode
|
||||
*
|
||||
* or even bound in as a function argument using lambdas or @c bind(). The
|
||||
* important thing is that as the application maintains a copy of the object
|
||||
* for as long as the coroutine must be kept alive.
|
||||
*
|
||||
* @par Pseudo-keywords
|
||||
*
|
||||
* A coroutine is used in conjunction with certain "pseudo-keywords", which
|
||||
* are implemented as macros. These macros are defined by a header file:
|
||||
*
|
||||
* @code #include <asio/yield.hpp>@endcode
|
||||
*
|
||||
* and may conversely be undefined as follows:
|
||||
*
|
||||
* @code #include <asio/unyield.hpp>@endcode
|
||||
*
|
||||
* <b>reenter</b>
|
||||
*
|
||||
* The @c reenter macro is used to define the body of a coroutine. It takes a
|
||||
* single argument: a pointer or reference to a coroutine object. For example,
|
||||
* if the base class is a coroutine object you may write:
|
||||
*
|
||||
* @code reenter (this)
|
||||
* {
|
||||
* ... coroutine body ...
|
||||
* } @endcode
|
||||
*
|
||||
* and if a data member or other variable you can write:
|
||||
*
|
||||
* @code reenter (coro_)
|
||||
* {
|
||||
* ... coroutine body ...
|
||||
* } @endcode
|
||||
*
|
||||
* When @c reenter is executed at runtime, control jumps to the location of the
|
||||
* last @c yield or @c fork.
|
||||
*
|
||||
* The coroutine body may also be a single statement, such as:
|
||||
*
|
||||
* @code reenter (this) for (;;)
|
||||
* {
|
||||
* ...
|
||||
* } @endcode
|
||||
*
|
||||
* @b Limitation: The @c reenter macro is implemented using a switch. This
|
||||
* means that you must take care when using local variables within the
|
||||
* coroutine body. The local variable is not allowed in a position where
|
||||
* reentering the coroutine could bypass the variable definition.
|
||||
*
|
||||
* <b>yield <em>statement</em></b>
|
||||
*
|
||||
* This form of the @c yield keyword is often used with asynchronous operations:
|
||||
*
|
||||
* @code yield socket_->async_read_some(buffer(*buffer_), *this); @endcode
|
||||
*
|
||||
* This divides into four logical steps:
|
||||
*
|
||||
* @li @c yield saves the current state of the coroutine.
|
||||
* @li The statement initiates the asynchronous operation.
|
||||
* @li The resume point is defined immediately following the statement.
|
||||
* @li Control is transferred to the end of the coroutine body.
|
||||
*
|
||||
* When the asynchronous operation completes, the function object is invoked
|
||||
* and @c reenter causes control to transfer to the resume point. It is
|
||||
* important to remember to carry the coroutine state forward with the
|
||||
* asynchronous operation. In the above snippet, the current class is a
|
||||
* function object object with a coroutine object as base class or data member.
|
||||
*
|
||||
* The statement may also be a compound statement, and this permits us to
|
||||
* define local variables with limited scope:
|
||||
*
|
||||
* @code yield
|
||||
* {
|
||||
* mutable_buffers_1 b = buffer(*buffer_);
|
||||
* socket_->async_read_some(b, *this);
|
||||
* } @endcode
|
||||
*
|
||||
* <b>yield return <em>expression</em> ;</b>
|
||||
*
|
||||
* This form of @c yield is often used in generators or coroutine-based parsers.
|
||||
* For example, the function object:
|
||||
*
|
||||
* @code struct interleave : coroutine
|
||||
* {
|
||||
* istream& is1;
|
||||
* istream& is2;
|
||||
* char operator()(char c)
|
||||
* {
|
||||
* reenter (this) for (;;)
|
||||
* {
|
||||
* yield return is1.get();
|
||||
* yield return is2.get();
|
||||
* }
|
||||
* }
|
||||
* }; @endcode
|
||||
*
|
||||
* defines a trivial coroutine that interleaves the characters from two input
|
||||
* streams.
|
||||
*
|
||||
* This type of @c yield divides into three logical steps:
|
||||
*
|
||||
* @li @c yield saves the current state of the coroutine.
|
||||
* @li The resume point is defined immediately following the semicolon.
|
||||
* @li The value of the expression is returned from the function.
|
||||
*
|
||||
* <b>yield ;</b>
|
||||
*
|
||||
* This form of @c yield is equivalent to the following steps:
|
||||
*
|
||||
* @li @c yield saves the current state of the coroutine.
|
||||
* @li The resume point is defined immediately following the semicolon.
|
||||
* @li Control is transferred to the end of the coroutine body.
|
||||
*
|
||||
* This form might be applied when coroutines are used for cooperative
|
||||
* threading and scheduling is explicitly managed. For example:
|
||||
*
|
||||
* @code struct task : coroutine
|
||||
* {
|
||||
* ...
|
||||
* void operator()()
|
||||
* {
|
||||
* reenter (this)
|
||||
* {
|
||||
* while (... not finished ...)
|
||||
* {
|
||||
* ... do something ...
|
||||
* yield;
|
||||
* ... do some more ...
|
||||
* yield;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
* };
|
||||
* ...
|
||||
* task t1, t2;
|
||||
* for (;;)
|
||||
* {
|
||||
* t1();
|
||||
* t2();
|
||||
* } @endcode
|
||||
*
|
||||
* <b>yield break ;</b>
|
||||
*
|
||||
* The final form of @c yield is used to explicitly terminate the coroutine.
|
||||
* This form is comprised of two steps:
|
||||
*
|
||||
* @li @c yield sets the coroutine state to indicate termination.
|
||||
* @li Control is transferred to the end of the coroutine body.
|
||||
*
|
||||
* Once terminated, calls to is_complete() return true and the coroutine cannot
|
||||
* be reentered.
|
||||
*
|
||||
* Note that a coroutine may also be implicitly terminated if the coroutine
|
||||
* body is exited without a yield, e.g. by return, throw or by running to the
|
||||
* end of the body.
|
||||
*
|
||||
* <b>fork <em>statement</em></b>
|
||||
*
|
||||
* The @c fork pseudo-keyword is used when "forking" a coroutine, i.e. splitting
|
||||
* it into two (or more) copies. One use of @c fork is in a server, where a new
|
||||
* coroutine is created to handle each client connection:
|
||||
*
|
||||
* @code reenter (this)
|
||||
* {
|
||||
* do
|
||||
* {
|
||||
* socket_.reset(new tcp::socket(my_context_));
|
||||
* yield acceptor->async_accept(*socket_, *this);
|
||||
* fork server(*this)();
|
||||
* } while (is_parent());
|
||||
* ... client-specific handling follows ...
|
||||
* } @endcode
|
||||
*
|
||||
* The logical steps involved in a @c fork are:
|
||||
*
|
||||
* @li @c fork saves the current state of the coroutine.
|
||||
* @li The statement creates a copy of the coroutine and either executes it
|
||||
* immediately or schedules it for later execution.
|
||||
* @li The resume point is defined immediately following the semicolon.
|
||||
* @li For the "parent", control immediately continues from the next line.
|
||||
*
|
||||
* The functions is_parent() and is_child() can be used to differentiate
|
||||
* between parent and child. You would use these functions to alter subsequent
|
||||
* control flow.
|
||||
*
|
||||
* 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 asio::post().
|
||||
*
|
||||
* @par Alternate macro names
|
||||
*
|
||||
* If preferred, an application can use macro names that follow a more typical
|
||||
* naming convention, rather than the pseudo-keywords. These are:
|
||||
*
|
||||
* @li @c ASIO_CORO_REENTER instead of @c reenter
|
||||
* @li @c ASIO_CORO_YIELD instead of @c yield
|
||||
* @li @c ASIO_CORO_FORK instead of @c fork
|
||||
*/
|
||||
class coroutine
|
||||
{
|
||||
public:
|
||||
/// Constructs a coroutine in its initial state.
|
||||
coroutine() : value_(0) {}
|
||||
|
||||
/// Returns true if the coroutine is the child of a fork.
|
||||
bool is_child() const { return value_ < 0; }
|
||||
|
||||
/// Returns true if the coroutine is the parent of a fork.
|
||||
bool is_parent() const { return !is_child(); }
|
||||
|
||||
/// Returns true if the coroutine has reached its terminal state.
|
||||
bool is_complete() const { return value_ == -1; }
|
||||
|
||||
private:
|
||||
friend class detail::coroutine_ref;
|
||||
int value_;
|
||||
};
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
class coroutine_ref
|
||||
{
|
||||
public:
|
||||
coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {}
|
||||
coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {}
|
||||
~coroutine_ref() { if (!modified_) value_ = -1; }
|
||||
operator int() const { return value_; }
|
||||
int& operator=(int v) { modified_ = true; return value_ = v; }
|
||||
private:
|
||||
void operator=(const coroutine_ref&);
|
||||
int& value_;
|
||||
bool modified_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#define ASIO_CORO_REENTER(c) \
|
||||
switch (::asio::detail::coroutine_ref _coro_value = c) \
|
||||
case -1: if (_coro_value) \
|
||||
{ \
|
||||
goto terminate_coroutine; \
|
||||
terminate_coroutine: \
|
||||
_coro_value = -1; \
|
||||
goto bail_out_of_coroutine; \
|
||||
bail_out_of_coroutine: \
|
||||
break; \
|
||||
} \
|
||||
else /* fall-through */ case 0:
|
||||
|
||||
#define ASIO_CORO_YIELD_IMPL(n) \
|
||||
for (_coro_value = (n);;) \
|
||||
if (_coro_value == 0) \
|
||||
{ \
|
||||
case (n): ; \
|
||||
break; \
|
||||
} \
|
||||
else \
|
||||
switch (_coro_value ? 0 : 1) \
|
||||
for (;;) \
|
||||
/* fall-through */ case -1: if (_coro_value) \
|
||||
goto terminate_coroutine; \
|
||||
else for (;;) \
|
||||
/* fall-through */ case 1: if (_coro_value) \
|
||||
goto bail_out_of_coroutine; \
|
||||
else /* fall-through */ case 0:
|
||||
|
||||
#define ASIO_CORO_FORK_IMPL(n) \
|
||||
for (_coro_value = -(n);; _coro_value = (n)) \
|
||||
if (_coro_value == (n)) \
|
||||
{ \
|
||||
case -(n): ; \
|
||||
break; \
|
||||
} \
|
||||
else
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define ASIO_CORO_YIELD ASIO_CORO_YIELD_IMPL(__COUNTER__ + 1)
|
||||
# define ASIO_CORO_FORK ASIO_CORO_FORK_IMPL(__COUNTER__ + 1)
|
||||
#else // defined(_MSC_VER)
|
||||
# define ASIO_CORO_YIELD ASIO_CORO_YIELD_IMPL(__LINE__)
|
||||
# define ASIO_CORO_FORK ASIO_CORO_FORK_IMPL(__LINE__)
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
#endif // ASIO_COROUTINE_HPP
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// deadline_timer.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_DEADLINE_TIMER_HPP
|
||||
#define ASIO_DEADLINE_TIMER_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_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include "asio/detail/socket_types.hpp" // Must come before posix_time.
|
||||
#include "asio/basic_deadline_timer.hpp"
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Typedef for the typical usage of timer. Uses a UTC clock.
|
||||
typedef basic_deadline_timer<boost::posix_time::ptime> deadline_timer;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_DEADLINE_TIMER_HPP
|
127
tools/sdk/esp32/include/asio/asio/asio/include/asio/defer.hpp
Normal file
127
tools/sdk/esp32/include/asio/asio/asio/include/asio/defer.hpp
Normal file
@ -0,0 +1,127 @@
|
||||
//
|
||||
// defer.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_DEFER_HPP
|
||||
#define ASIO_DEFER_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/type_traits.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/is_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Submits a completion token or function object for execution.
|
||||
/**
|
||||
* This function submits an object for execution using the object's associated
|
||||
* 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
|
||||
* with <tt>handler(forward<CompletionToken>(token))</tt>.
|
||||
*
|
||||
* @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
|
||||
* initializing the object as <tt>result(handler)</tt>.
|
||||
*
|
||||
* @li Obtains the handler's associated executor object @c ex by performing
|
||||
* <tt>get_associated_executor(handler)</tt>.
|
||||
*
|
||||
* @li Obtains the handler's associated allocator object @c alloc by performing
|
||||
* <tt>get_associated_allocator(handler)</tt>.
|
||||
*
|
||||
* @li Performs <tt>ex.defer(std::move(handler), alloc)</tt>.
|
||||
*
|
||||
* @li Returns <tt>result.get()</tt>.
|
||||
*/
|
||||
template <ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
ASIO_MOVE_ARG(CompletionToken) token);
|
||||
|
||||
/// Submits a completion token or function object for execution.
|
||||
/**
|
||||
* This function submits an object for execution using the specified 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
|
||||
* with <tt>handler(forward<CompletionToken>(token))</tt>.
|
||||
*
|
||||
* @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
|
||||
* initializing the object as <tt>result(handler)</tt>.
|
||||
*
|
||||
* @li Obtains the handler's associated executor object @c ex1 by performing
|
||||
* <tt>get_associated_executor(handler)</tt>.
|
||||
*
|
||||
* @li Creates a work object @c w by performing <tt>make_work(ex1)</tt>.
|
||||
*
|
||||
* @li Obtains the handler's associated allocator object @c alloc by performing
|
||||
* <tt>get_associated_allocator(handler)</tt>.
|
||||
*
|
||||
* @li Constructs a function object @c f with a function call operator that
|
||||
* performs <tt>ex1.dispatch(std::move(handler), alloc)</tt> followed by
|
||||
* <tt>w.reset()</tt>.
|
||||
*
|
||||
* @li Performs <tt>Executor(ex).defer(std::move(f), alloc)</tt>.
|
||||
*
|
||||
* @li Returns <tt>result.get()</tt>.
|
||||
*/
|
||||
template <typename Executor,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
const Executor& ex,
|
||||
ASIO_MOVE_ARG(CompletionToken) token
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
|
||||
typename enable_if<is_executor<Executor>::value>::type* = 0);
|
||||
|
||||
/// Submits a completion token or function object for execution.
|
||||
/**
|
||||
* @returns <tt>defer(ctx.get_executor(), forward<CompletionToken>(token))</tt>.
|
||||
*/
|
||||
template <typename ExecutionContext,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
|
||||
typename ExecutionContext::executor_type)>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
ExecutionContext& ctx,
|
||||
ASIO_MOVE_ARG(CompletionToken) token
|
||||
ASIO_DEFAULT_COMPLETION_TOKEN(
|
||||
typename ExecutionContext::executor_type),
|
||||
typename enable_if<is_convertible<
|
||||
ExecutionContext&, execution_context&>::value>::type* = 0);
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/defer.hpp"
|
||||
|
||||
#endif // ASIO_DEFER_HPP
|
@ -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
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// detail/array.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_DETAIL_ARRAY_HPP
|
||||
#define ASIO_DETAIL_ARRAY_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_STD_ARRAY)
|
||||
# include <array>
|
||||
#else // defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
using std::array;
|
||||
#else // defined(ASIO_HAS_STD_ARRAY)
|
||||
using boost::array;
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_ARRAY_HPP
|
@ -0,0 +1,34 @@
|
||||
//
|
||||
// detail/array_fwd.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_DETAIL_ARRAY_FWD_HPP
|
||||
#define ASIO_DETAIL_ARRAY_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T, std::size_t N>
|
||||
class array;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// Standard library components can't be forward declared, so we'll have to
|
||||
// include the array header. Fortunately, it's fairly lightweight and doesn't
|
||||
// add significantly to the compile time.
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
#endif // ASIO_DETAIL_ARRAY_FWD_HPP
|
@ -0,0 +1,32 @@
|
||||
//
|
||||
// detail/assert.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_DETAIL_ASSERT_HPP
|
||||
#define ASIO_DETAIL_ASSERT_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_BOOST_ASSERT)
|
||||
# include <boost/assert.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# include <cassert>
|
||||
#endif // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# define ASIO_ASSERT(expr) BOOST_ASSERT(expr)
|
||||
#else // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# define ASIO_ASSERT(expr) assert(expr)
|
||||
#endif // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
|
||||
#endif // ASIO_DETAIL_ASSERT_HPP
|
@ -0,0 +1,45 @@
|
||||
//
|
||||
// detail/atomic_count.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_DETAIL_ATOMIC_COUNT_HPP
|
||||
#define ASIO_DETAIL_ATOMIC_COUNT_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_THREADS)
|
||||
// Nothing to include.
|
||||
#elif defined(ASIO_HAS_STD_ATOMIC)
|
||||
# include <atomic>
|
||||
#else // defined(ASIO_HAS_STD_ATOMIC)
|
||||
# include <boost/detail/atomic_count.hpp>
|
||||
#endif // defined(ASIO_HAS_STD_ATOMIC)
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
#if !defined(ASIO_HAS_THREADS)
|
||||
typedef long atomic_count;
|
||||
inline void increment(atomic_count& a, long b) { a += b; }
|
||||
#elif defined(ASIO_HAS_STD_ATOMIC)
|
||||
typedef std::atomic<long> atomic_count;
|
||||
inline void increment(atomic_count& a, long b) { a += b; }
|
||||
#else // defined(ASIO_HAS_STD_ATOMIC)
|
||||
typedef boost::detail::atomic_count atomic_count;
|
||||
inline void increment(atomic_count& a, long b) { while (b > 0) ++a, --b; }
|
||||
#endif // defined(ASIO_HAS_STD_ATOMIC)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_ATOMIC_COUNT_HPP
|
@ -0,0 +1,69 @@
|
||||
//
|
||||
// detail/base_from_completion_cond.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_DETAIL_BASE_FROM_COMPLETION_COND_HPP
|
||||
#define ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename CompletionCondition>
|
||||
class base_from_completion_cond
|
||||
{
|
||||
protected:
|
||||
explicit base_from_completion_cond(CompletionCondition& completion_condition)
|
||||
: completion_condition_(
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition))
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t check_for_completion(
|
||||
const asio::error_code& ec,
|
||||
std::size_t total_transferred)
|
||||
{
|
||||
return detail::adapt_completion_condition_result(
|
||||
completion_condition_(ec, total_transferred));
|
||||
}
|
||||
|
||||
private:
|
||||
CompletionCondition completion_condition_;
|
||||
};
|
||||
|
||||
template <>
|
||||
class base_from_completion_cond<transfer_all_t>
|
||||
{
|
||||
protected:
|
||||
explicit base_from_completion_cond(transfer_all_t)
|
||||
{
|
||||
}
|
||||
|
||||
static std::size_t check_for_completion(
|
||||
const asio::error_code& ec,
|
||||
std::size_t total_transferred)
|
||||
{
|
||||
return transfer_all_t()(ec, total_transferred);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
|
@ -0,0 +1,816 @@
|
||||
//
|
||||
// detail/bind_handler.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_DETAIL_BIND_HANDLER_HPP
|
||||
#define ASIO_DETAIL_BIND_HANDLER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
class binder1
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
binder1(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1)
|
||||
: handler_(ASIO_MOVE_CAST(T)(handler)),
|
||||
arg1_(arg1)
|
||||
{
|
||||
}
|
||||
|
||||
binder1(Handler& handler, const Arg1& arg1)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
binder1(const binder1& other)
|
||||
: handler_(other.handler_),
|
||||
arg1_(other.arg1_)
|
||||
{
|
||||
}
|
||||
|
||||
binder1(binder1&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline binder1<typename decay<Handler>::type, Arg1> bind_handler(
|
||||
ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1)
|
||||
{
|
||||
return binder1<typename decay<Handler>::type, Arg1>(0,
|
||||
ASIO_MOVE_CAST(Handler)(handler), arg1);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
class binder2
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
binder2(int, ASIO_MOVE_ARG(T) handler,
|
||||
const Arg1& arg1, const Arg2& arg2)
|
||||
: handler_(ASIO_MOVE_CAST(T)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2)
|
||||
{
|
||||
}
|
||||
|
||||
binder2(Handler& handler, const Arg1& arg1, const Arg2& arg2)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
binder2(const binder2& other)
|
||||
: handler_(other.handler_),
|
||||
arg1_(other.arg1_),
|
||||
arg2_(other.arg2_)
|
||||
{
|
||||
}
|
||||
|
||||
binder2(binder2&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
|
||||
arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline binder2<typename decay<Handler>::type, Arg1, Arg2> bind_handler(
|
||||
ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1, const Arg2& arg2)
|
||||
{
|
||||
return binder2<typename decay<Handler>::type, Arg1, Arg2>(0,
|
||||
ASIO_MOVE_CAST(Handler)(handler), arg1, arg2);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
class binder3
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
binder3(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3)
|
||||
: handler_(ASIO_MOVE_CAST(T)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3)
|
||||
{
|
||||
}
|
||||
|
||||
binder3(Handler& handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
binder3(const binder3& other)
|
||||
: handler_(other.handler_),
|
||||
arg1_(other.arg1_),
|
||||
arg2_(other.arg2_),
|
||||
arg3_(other.arg3_)
|
||||
{
|
||||
}
|
||||
|
||||
binder3(binder3&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
|
||||
arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)),
|
||||
arg3_(ASIO_MOVE_CAST(Arg3)(other.arg3_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_, arg3_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
Arg3 arg3_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler,
|
||||
typename Arg1, typename Arg2, typename Arg3>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler,
|
||||
typename Arg1, typename Arg2, typename Arg3>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline binder3<typename decay<Handler>::type, Arg1, Arg2, Arg3> bind_handler(
|
||||
ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3)
|
||||
{
|
||||
return binder3<typename decay<Handler>::type, Arg1, Arg2, Arg3>(0,
|
||||
ASIO_MOVE_CAST(Handler)(handler), arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
class binder4
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
binder4(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
|
||||
: handler_(ASIO_MOVE_CAST(T)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4)
|
||||
{
|
||||
}
|
||||
|
||||
binder4(Handler& handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
binder4(const binder4& other)
|
||||
: handler_(other.handler_),
|
||||
arg1_(other.arg1_),
|
||||
arg2_(other.arg2_),
|
||||
arg3_(other.arg3_),
|
||||
arg4_(other.arg4_)
|
||||
{
|
||||
}
|
||||
|
||||
binder4(binder4&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
|
||||
arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)),
|
||||
arg3_(ASIO_MOVE_CAST(Arg3)(other.arg3_)),
|
||||
arg4_(ASIO_MOVE_CAST(Arg4)(other.arg4_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_),
|
||||
static_cast<const Arg4&>(arg4_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_, arg3_, arg4_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
Arg3 arg3_;
|
||||
Arg4 arg4_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4>
|
||||
inline binder4<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4>
|
||||
bind_handler(ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
|
||||
{
|
||||
return binder4<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4>(0,
|
||||
ASIO_MOVE_CAST(Handler)(handler), arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
class binder5
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
binder5(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
|
||||
: handler_(ASIO_MOVE_CAST(T)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4),
|
||||
arg5_(arg5)
|
||||
{
|
||||
}
|
||||
|
||||
binder5(Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4),
|
||||
arg5_(arg5)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
binder5(const binder5& other)
|
||||
: handler_(other.handler_),
|
||||
arg1_(other.arg1_),
|
||||
arg2_(other.arg2_),
|
||||
arg3_(other.arg3_),
|
||||
arg4_(other.arg4_),
|
||||
arg5_(other.arg5_)
|
||||
{
|
||||
}
|
||||
|
||||
binder5(binder5&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
|
||||
arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)),
|
||||
arg3_(ASIO_MOVE_CAST(Arg3)(other.arg3_)),
|
||||
arg4_(ASIO_MOVE_CAST(Arg4)(other.arg4_)),
|
||||
arg5_(ASIO_MOVE_CAST(Arg5)(other.arg5_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_),
|
||||
static_cast<const Arg4&>(arg4_), static_cast<const Arg5&>(arg5_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
Arg3 arg3_;
|
||||
Arg4 arg4_;
|
||||
Arg5 arg5_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4, typename Arg5>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1,
|
||||
typename Arg2, typename Arg3, typename Arg4, typename Arg5>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
inline binder5<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4, Arg5>
|
||||
bind_handler(ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1,
|
||||
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
|
||||
{
|
||||
return binder5<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4, Arg5>(0,
|
||||
ASIO_MOVE_CAST(Handler)(handler), arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
class move_binder1
|
||||
{
|
||||
public:
|
||||
move_binder1(int, ASIO_MOVE_ARG(Handler) handler,
|
||||
ASIO_MOVE_ARG(Arg1) arg1)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(arg1))
|
||||
{
|
||||
}
|
||||
|
||||
move_binder1(move_binder1&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_))
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(ASIO_MOVE_CAST(Arg1)(arg1_));
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
move_binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
move_binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline bool asio_handler_is_continuation(
|
||||
move_binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1>
|
||||
inline void asio_handler_invoke(ASIO_MOVE_ARG(Function) function,
|
||||
move_binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
ASIO_MOVE_CAST(Function)(function), this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
class move_binder2
|
||||
{
|
||||
public:
|
||||
move_binder2(int, ASIO_MOVE_ARG(Handler) handler,
|
||||
const Arg1& arg1, ASIO_MOVE_ARG(Arg2) arg2)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(ASIO_MOVE_CAST(Arg2)(arg2))
|
||||
{
|
||||
}
|
||||
|
||||
move_binder2(move_binder2&& other)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
|
||||
arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_))
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
ASIO_MOVE_CAST(Arg2)(arg2_));
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
move_binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
move_binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline bool asio_handler_is_continuation(
|
||||
move_binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_invoke(ASIO_MOVE_ARG(Function) function,
|
||||
move_binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
ASIO_MOVE_CAST(Function)(function), this_handler->handler_);
|
||||
}
|
||||
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename Handler, typename Arg1, typename Allocator>
|
||||
struct associated_allocator<detail::binder1<Handler, Arg1>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<Handler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::binder1<Handler, Arg1>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Allocator>
|
||||
struct associated_allocator<detail::binder2<Handler, Arg1, Arg2>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<Handler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::binder2<Handler, Arg1, Arg2>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Executor>
|
||||
struct associated_executor<detail::binder1<Handler, Arg1>, Executor>
|
||||
{
|
||||
typedef typename associated_executor<Handler, Executor>::type type;
|
||||
|
||||
static type get(const detail::binder1<Handler, Arg1>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<Handler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Executor>
|
||||
struct associated_executor<detail::binder2<Handler, Arg1, Arg2>, Executor>
|
||||
{
|
||||
typedef typename associated_executor<Handler, Executor>::type type;
|
||||
|
||||
static type get(const detail::binder2<Handler, Arg1, Arg2>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<Handler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
|
||||
template <typename Handler, typename Arg1, typename Allocator>
|
||||
struct associated_allocator<detail::move_binder1<Handler, Arg1>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<Handler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::move_binder1<Handler, Arg1>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::move_binder2<Handler, Arg1, Arg2>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<Handler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::move_binder2<Handler, Arg1, Arg2>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Executor>
|
||||
struct associated_executor<detail::move_binder1<Handler, Arg1>, Executor>
|
||||
{
|
||||
typedef typename associated_executor<Handler, Executor>::type type;
|
||||
|
||||
static type get(const detail::move_binder1<Handler, Arg1>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<Handler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Executor>
|
||||
struct associated_executor<detail::move_binder2<Handler, Arg1, Arg2>, Executor>
|
||||
{
|
||||
typedef typename associated_executor<Handler, Executor>::type type;
|
||||
|
||||
static type get(const detail::move_binder2<Handler, Arg1, Arg2>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<Handler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BIND_HANDLER_HPP
|
@ -0,0 +1,66 @@
|
||||
//
|
||||
// detail/buffer_resize_guard.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_DETAIL_BUFFER_RESIZE_GUARD_HPP
|
||||
#define ASIO_DETAIL_BUFFER_RESIZE_GUARD_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/limits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// Helper class to manage buffer resizing in an exception safe way.
|
||||
template <typename Buffer>
|
||||
class buffer_resize_guard
|
||||
{
|
||||
public:
|
||||
// Constructor.
|
||||
buffer_resize_guard(Buffer& buffer)
|
||||
: buffer_(buffer),
|
||||
old_size_(buffer.size())
|
||||
{
|
||||
}
|
||||
|
||||
// Destructor rolls back the buffer resize unless commit was called.
|
||||
~buffer_resize_guard()
|
||||
{
|
||||
if (old_size_ != (std::numeric_limits<size_t>::max)())
|
||||
{
|
||||
buffer_.resize(old_size_);
|
||||
}
|
||||
}
|
||||
|
||||
// Commit the resize transaction.
|
||||
void commit()
|
||||
{
|
||||
old_size_ = (std::numeric_limits<size_t>::max)();
|
||||
}
|
||||
|
||||
private:
|
||||
// The buffer being managed.
|
||||
Buffer& buffer_;
|
||||
|
||||
// The size of the buffer at the time the guard was constructed.
|
||||
size_t old_size_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
|
@ -0,0 +1,544 @@
|
||||
//
|
||||
// detail/buffer_sequence_adapter.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_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
|
||||
#define ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/array_fwd.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class buffer_sequence_adapter_base
|
||||
{
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
public:
|
||||
// The maximum number of buffers to support in a single operation.
|
||||
enum { max_buffers = 1 };
|
||||
|
||||
protected:
|
||||
typedef Windows::Storage::Streams::IBuffer^ native_buffer_type;
|
||||
|
||||
ASIO_DECL static void init_native_buffer(
|
||||
native_buffer_type& buf,
|
||||
const asio::mutable_buffer& buffer);
|
||||
|
||||
ASIO_DECL static void init_native_buffer(
|
||||
native_buffer_type& buf,
|
||||
const asio::const_buffer& buffer);
|
||||
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
public:
|
||||
// The maximum number of buffers to support in a single operation.
|
||||
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
|
||||
|
||||
protected:
|
||||
typedef WSABUF native_buffer_type;
|
||||
|
||||
static void init_native_buffer(WSABUF& buf,
|
||||
const asio::mutable_buffer& buffer)
|
||||
{
|
||||
buf.buf = static_cast<char*>(buffer.data());
|
||||
buf.len = static_cast<ULONG>(buffer.size());
|
||||
}
|
||||
|
||||
static void init_native_buffer(WSABUF& buf,
|
||||
const asio::const_buffer& buffer)
|
||||
{
|
||||
buf.buf = const_cast<char*>(static_cast<const char*>(buffer.data()));
|
||||
buf.len = static_cast<ULONG>(buffer.size());
|
||||
}
|
||||
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
public:
|
||||
// The maximum number of buffers to support in a single operation.
|
||||
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
|
||||
|
||||
protected:
|
||||
typedef iovec native_buffer_type;
|
||||
|
||||
static void init_iov_base(void*& base, void* addr)
|
||||
{
|
||||
base = addr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void init_iov_base(T& base, void* addr)
|
||||
{
|
||||
base = static_cast<T>(addr);
|
||||
}
|
||||
|
||||
static void init_native_buffer(iovec& iov,
|
||||
const asio::mutable_buffer& buffer)
|
||||
{
|
||||
init_iov_base(iov.iov_base, buffer.data());
|
||||
iov.iov_len = buffer.size();
|
||||
}
|
||||
|
||||
static void init_native_buffer(iovec& iov,
|
||||
const asio::const_buffer& buffer)
|
||||
{
|
||||
init_iov_base(iov.iov_base, const_cast<void*>(buffer.data()));
|
||||
iov.iov_len = buffer.size();
|
||||
}
|
||||
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
};
|
||||
|
||||
// Helper class to translate buffers into the native buffer representation.
|
||||
template <typename Buffer, typename Buffers>
|
||||
class buffer_sequence_adapter
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(const Buffers& buffer_sequence)
|
||||
: count_(0), total_buffer_size_(0)
|
||||
{
|
||||
buffer_sequence_adapter::init(
|
||||
asio::buffer_sequence_begin(buffer_sequence),
|
||||
asio::buffer_sequence_end(buffer_sequence));
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return count_;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const Buffers& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence_adapter::all_empty(
|
||||
asio::buffer_sequence_begin(buffer_sequence),
|
||||
asio::buffer_sequence_end(buffer_sequence));
|
||||
}
|
||||
|
||||
static void validate(const Buffers& buffer_sequence)
|
||||
{
|
||||
buffer_sequence_adapter::validate(
|
||||
asio::buffer_sequence_begin(buffer_sequence),
|
||||
asio::buffer_sequence_end(buffer_sequence));
|
||||
}
|
||||
|
||||
static Buffer first(const Buffers& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence_adapter::first(
|
||||
asio::buffer_sequence_begin(buffer_sequence),
|
||||
asio::buffer_sequence_end(buffer_sequence));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Iterator>
|
||||
void init(Iterator begin, Iterator end)
|
||||
{
|
||||
Iterator iter = begin;
|
||||
for (; iter != end && count_ < max_buffers; ++iter, ++count_)
|
||||
{
|
||||
Buffer buffer(*iter);
|
||||
init_native_buffer(buffers_[count_], buffer);
|
||||
total_buffer_size_ += buffer.size();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
static bool all_empty(Iterator begin, Iterator end)
|
||||
{
|
||||
Iterator iter = begin;
|
||||
std::size_t i = 0;
|
||||
for (; iter != end && i < max_buffers; ++iter, ++i)
|
||||
if (Buffer(*iter).size() > 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
static void validate(Iterator begin, Iterator end)
|
||||
{
|
||||
Iterator iter = begin;
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
Buffer buffer(*iter);
|
||||
buffer.data();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
static Buffer first(Iterator begin, Iterator end)
|
||||
{
|
||||
Iterator iter = begin;
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
Buffer buffer(*iter);
|
||||
if (buffer.size() != 0)
|
||||
return buffer;
|
||||
}
|
||||
return Buffer();
|
||||
}
|
||||
|
||||
native_buffer_type buffers_[max_buffers];
|
||||
std::size_t count_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
template <typename Buffer>
|
||||
class buffer_sequence_adapter<Buffer, asio::mutable_buffer>
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const asio::mutable_buffer& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||
total_buffer_size_ = buffer_sequence.size();
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return &buffer_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const asio::mutable_buffer& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence.size() == 0;
|
||||
}
|
||||
|
||||
static void validate(const asio::mutable_buffer& buffer_sequence)
|
||||
{
|
||||
buffer_sequence.data();
|
||||
}
|
||||
|
||||
static Buffer first(const asio::mutable_buffer& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffer_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
template <typename Buffer>
|
||||
class buffer_sequence_adapter<Buffer, asio::const_buffer>
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const asio::const_buffer& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||
total_buffer_size_ = buffer_sequence.size();
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return &buffer_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const asio::const_buffer& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence.size() == 0;
|
||||
}
|
||||
|
||||
static void validate(const asio::const_buffer& buffer_sequence)
|
||||
{
|
||||
buffer_sequence.data();
|
||||
}
|
||||
|
||||
static Buffer first(const asio::const_buffer& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffer_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Buffer>
|
||||
class buffer_sequence_adapter<Buffer, asio::mutable_buffers_1>
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||
total_buffer_size_ = buffer_sequence.size();
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return &buffer_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence.size() == 0;
|
||||
}
|
||||
|
||||
static void validate(const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
buffer_sequence.data();
|
||||
}
|
||||
|
||||
static Buffer first(const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffer_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
template <typename Buffer>
|
||||
class buffer_sequence_adapter<Buffer, asio::const_buffers_1>
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||
total_buffer_size_ = buffer_sequence.size();
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return &buffer_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence.size() == 0;
|
||||
}
|
||||
|
||||
static void validate(const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
buffer_sequence.data();
|
||||
}
|
||||
|
||||
static Buffer first(const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffer_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Buffer, typename Elem>
|
||||
class buffer_sequence_adapter<Buffer, boost::array<Elem, 2> >
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
||||
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
||||
total_buffer_size_ = buffer_sequence[0].size() + buffer_sequence[1].size();
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence[0].size() == 0 && buffer_sequence[1].size() == 0;
|
||||
}
|
||||
|
||||
static void validate(const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
buffer_sequence[0].data();
|
||||
buffer_sequence[1].data();
|
||||
}
|
||||
|
||||
static Buffer first(const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence[0].size() != 0
|
||||
? buffer_sequence[0] : buffer_sequence[1]);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffers_[2];
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
template <typename Buffer, typename Elem>
|
||||
class buffer_sequence_adapter<Buffer, std::array<Elem, 2> >
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
||||
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
||||
total_buffer_size_ = buffer_sequence[0].size() + buffer_sequence[1].size();
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::size_t total_size() const
|
||||
{
|
||||
return total_buffer_size_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return buffer_sequence[0].size() == 0 && buffer_sequence[1].size() == 0;
|
||||
}
|
||||
|
||||
static void validate(const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
buffer_sequence[0].data();
|
||||
buffer_sequence[1].data();
|
||||
}
|
||||
|
||||
static Buffer first(const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence[0].size() != 0
|
||||
? buffer_sequence[0] : buffer_sequence[1]);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffers_[2];
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# include "asio/detail/impl/buffer_sequence_adapter.ipp"
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#endif // ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
|
@ -0,0 +1,126 @@
|
||||
//
|
||||
// detail/buffered_stream_storage.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_DETAIL_BUFFERED_STREAM_STORAGE_HPP
|
||||
#define ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/assert.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class buffered_stream_storage
|
||||
{
|
||||
public:
|
||||
// The type of the bytes stored in the buffer.
|
||||
typedef unsigned char byte_type;
|
||||
|
||||
// The type used for offsets into the buffer.
|
||||
typedef std::size_t size_type;
|
||||
|
||||
// Constructor.
|
||||
explicit buffered_stream_storage(std::size_t buffer_capacity)
|
||||
: begin_offset_(0),
|
||||
end_offset_(0),
|
||||
buffer_(buffer_capacity)
|
||||
{
|
||||
}
|
||||
|
||||
/// Clear the buffer.
|
||||
void clear()
|
||||
{
|
||||
begin_offset_ = 0;
|
||||
end_offset_ = 0;
|
||||
}
|
||||
|
||||
// Return a pointer to the beginning of the unread data.
|
||||
mutable_buffer data()
|
||||
{
|
||||
return asio::buffer(buffer_) + begin_offset_;
|
||||
}
|
||||
|
||||
// Return a pointer to the beginning of the unread data.
|
||||
const_buffer data() const
|
||||
{
|
||||
return asio::buffer(buffer_) + begin_offset_;
|
||||
}
|
||||
|
||||
// Is there no unread data in the buffer.
|
||||
bool empty() const
|
||||
{
|
||||
return begin_offset_ == end_offset_;
|
||||
}
|
||||
|
||||
// Return the amount of unread data the is in the buffer.
|
||||
size_type size() const
|
||||
{
|
||||
return end_offset_ - begin_offset_;
|
||||
}
|
||||
|
||||
// Resize the buffer to the specified length.
|
||||
void resize(size_type length)
|
||||
{
|
||||
ASIO_ASSERT(length <= capacity());
|
||||
if (begin_offset_ + length <= capacity())
|
||||
{
|
||||
end_offset_ = begin_offset_ + length;
|
||||
}
|
||||
else
|
||||
{
|
||||
using namespace std; // For memmove.
|
||||
memmove(&buffer_[0], &buffer_[0] + begin_offset_, size());
|
||||
end_offset_ = length;
|
||||
begin_offset_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the maximum size for data in the buffer.
|
||||
size_type capacity() const
|
||||
{
|
||||
return buffer_.size();
|
||||
}
|
||||
|
||||
// Consume multiple bytes from the beginning of the buffer.
|
||||
void consume(size_type count)
|
||||
{
|
||||
ASIO_ASSERT(begin_offset_ + count <= end_offset_);
|
||||
begin_offset_ += count;
|
||||
if (empty())
|
||||
clear();
|
||||
}
|
||||
|
||||
private:
|
||||
// The offset to the beginning of the unread data.
|
||||
size_type begin_offset_;
|
||||
|
||||
// The offset to the end of the unread data.
|
||||
size_type end_offset_;
|
||||
|
||||
// The data in the buffer.
|
||||
std::vector<byte_type> buffer_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
|
@ -0,0 +1,125 @@
|
||||
//
|
||||
// detail/call_stack.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_DETAIL_CALL_STACK_HPP
|
||||
#define ASIO_DETAIL_CALL_STACK_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/noncopyable.hpp"
|
||||
#include "asio/detail/tss_ptr.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// Helper class to determine whether or not the current thread is inside an
|
||||
// invocation of io_context::run() for a specified io_context object.
|
||||
template <typename Key, typename Value = unsigned char>
|
||||
class call_stack
|
||||
{
|
||||
public:
|
||||
// Context class automatically pushes the key/value pair on to the stack.
|
||||
class context
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
// Push the key on to the stack.
|
||||
explicit context(Key* k)
|
||||
: key_(k),
|
||||
next_(call_stack<Key, Value>::top_)
|
||||
{
|
||||
value_ = reinterpret_cast<unsigned char*>(this);
|
||||
call_stack<Key, Value>::top_ = this;
|
||||
}
|
||||
|
||||
// Push the key/value pair on to the stack.
|
||||
context(Key* k, Value& v)
|
||||
: key_(k),
|
||||
value_(&v),
|
||||
next_(call_stack<Key, Value>::top_)
|
||||
{
|
||||
call_stack<Key, Value>::top_ = this;
|
||||
}
|
||||
|
||||
// Pop the key/value pair from the stack.
|
||||
~context()
|
||||
{
|
||||
call_stack<Key, Value>::top_ = next_;
|
||||
}
|
||||
|
||||
// Find the next context with the same key.
|
||||
Value* next_by_key() const
|
||||
{
|
||||
context* elem = next_;
|
||||
while (elem)
|
||||
{
|
||||
if (elem->key_ == key_)
|
||||
return elem->value_;
|
||||
elem = elem->next_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class call_stack<Key, Value>;
|
||||
|
||||
// The key associated with the context.
|
||||
Key* key_;
|
||||
|
||||
// The value associated with the context.
|
||||
Value* value_;
|
||||
|
||||
// The next element in the stack.
|
||||
context* next_;
|
||||
};
|
||||
|
||||
friend class context;
|
||||
|
||||
// Determine whether the specified owner is on the stack. Returns address of
|
||||
// key if present, 0 otherwise.
|
||||
static Value* contains(Key* k)
|
||||
{
|
||||
context* elem = top_;
|
||||
while (elem)
|
||||
{
|
||||
if (elem->key_ == k)
|
||||
return elem->value_;
|
||||
elem = elem->next_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Obtain the value at the top of the stack.
|
||||
static Value* top()
|
||||
{
|
||||
context* elem = top_;
|
||||
return elem ? elem->value_ : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// The top of the stack of calls for the current thread.
|
||||
static tss_ptr<context> top_;
|
||||
};
|
||||
|
||||
template <typename Key, typename Value>
|
||||
tss_ptr<typename call_stack<Key, Value>::context>
|
||||
call_stack<Key, Value>::top_;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_CALL_STACK_HPP
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user