From a924420b9399dd52c7a730604a15953c82509bb3 Mon Sep 17 00:00:00 2001 From: obrain17 <42682043+obrain17@users.noreply.github.com> Date: Sat, 29 Jun 2019 17:43:43 +0200 Subject: [PATCH 1/7] Fix Issue that connect() did not work with DNS Add additional code to "bool AsyncClient::connect(const char* host, uint16_t port)" and "static void _handle_async_event(lwip_event_packet_t * e)". Async Service task and queue had not yet been started and "LWIP_TCP_DNS" had no handler defined, so "_tcp_dns_found" called by "dns_gethostbyname" ran into an error. --- src/AsyncTCP.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index a614736..453fa82 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -161,6 +161,9 @@ static void _handle_async_event(lwip_event_packet_t * e){ } else if(e->event == LWIP_TCP_ACCEPT){ //ets_printf("A: 0x%08x 0x%08x\n", e->arg, e->accept.client); AsyncServer::_s_accepted(e->arg, e->accept.client); + } else if(e->event == LWIP_TCP_DNS){ + //ets_printf("D: 0x%08x %s = %s\n", e->arg, e->dns.name, ipaddr_ntoa(&e->dns.addr)); + AsyncClient::_s_dns_found(e->dns.name, &e->dns.addr, e->arg); } free((void*)(e)); } @@ -674,6 +677,13 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){ bool AsyncClient::connect(const char* host, uint16_t port){ ip_addr_t addr; + + if(!_start_async_task()){ + Serial.println("failed to start task"); + log_e("failed to start task"); + return false; + } + err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_tcp_dns_found, this); if(err == ERR_OK) { return connect(IPAddress(addr.u_addr.ip4.addr), port); From 6937856e04bcde94dc162008413108ee1fae1637 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sun, 1 Sep 2019 20:15:47 +0300 Subject: [PATCH 2/7] Update Travis build script (even if there are no examples) --- .gitignore | 2 + .travis.yml | 22 +++--- travis/build.py | 131 --------------------------------- travis/build.sh | 187 ++++++++++++++++++++++++++++++++++++++++++++--- travis/common.sh | 39 ---------- 5 files changed, 193 insertions(+), 188 deletions(-) create mode 100644 .gitignore delete mode 100755 travis/build.py delete mode 100755 travis/common.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/.travis.yml b/.travis.yml index 762f4db..020b430 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,21 @@ sudo: false - -language: python -python: - - "2.7" - +language: bash os: - linux -dist: - - xenial +git: + depth: false -script: - - bash $TRAVIS_BUILD_DIR/travis/build.sh +stages: + - build + +jobs: + include: + + - name: "Build Examples" + if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) + stage: build + script: bash $TRAVIS_BUILD_DIR/travis/build.sh notifications: email: diff --git a/travis/build.py b/travis/build.py deleted file mode 100755 index a106f3d..0000000 --- a/travis/build.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# build.py — build a sketch using arduino-builder -# -# Wrapper script around arduino-builder which accepts some ESP8266-specific -# options and translates them into FQBN -# -# Copyright © 2016 Ivan Grokhotkov -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# - - -from __future__ import print_function -import sys -import os -import argparse -import subprocess -import tempfile -import shutil - -def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args): - cmd = ide_path + '/arduino-builder ' - cmd += '-compile -logger=human ' - cmd += '-build-path "' + tmp_dir + '" ' - cmd += '-tools "' + ide_path + '/tools-builder" ' - if args.library_path: - for lib_dir in args.library_path: - cmd += '-libraries "' + lib_dir + '" ' - cmd += '-hardware "' + ide_path + '/hardware" ' - if args.hardware_dir: - for hw_dir in args.hardware_dir: - cmd += '-hardware "' + hw_dir + '" ' - else: - cmd += '-hardware "' + hardware_dir + '" ' - # Debug=Serial,DebugLevel=Core____ - cmd += '-fqbn=espressif:esp32:{board_name}:' \ - 'FlashFreq={flash_freq},' \ - 'PartitionScheme=huge_app,' \ - 'UploadSpeed=921600'.format(**vars(args)) - cmd += ' ' - cmd += '-ide-version=10607 ' - cmd += '-warnings={warnings} '.format(**vars(args)) - if args.verbose: - cmd += '-verbose ' - cmd += sketch - - if args.verbose: - print('Building: ' + cmd, file=f) - - cmds = cmd.split(' ') - p = subprocess.Popen(cmds, stdout=f, stderr=subprocess.STDOUT) - p.wait() - return p.returncode - -def parse_args(): - parser = argparse.ArgumentParser(description='Sketch build helper') - parser.add_argument('-v', '--verbose', help='Enable verbose output', - action='store_true') - parser.add_argument('-i', '--ide_path', help='Arduino IDE path') - parser.add_argument('-p', '--build_path', help='Build directory') - parser.add_argument('-l', '--library_path', help='Additional library path', - action='append') - parser.add_argument('-d', '--hardware_dir', help='Additional hardware path', - action='append') - parser.add_argument('-b', '--board_name', help='Board name', default='esp32') - parser.add_argument('-w', '--warnings', help='Compilation warnings level', - default='none', choices=['none', 'all', 'more']) - parser.add_argument('-o', '--output_binary', help='File name for output binary') - parser.add_argument('-k', '--keep', action='store_true', - help='Don\'t delete temporary build directory') - parser.add_argument('--flash_freq', help='Flash frequency', default=40, - type=int, choices=[40, 80]) - parser.add_argument('sketch_path', help='Sketch file path') - return parser.parse_args() - -def main(): - args = parse_args() - - ide_path = args.ide_path - if not ide_path: - ide_path = os.environ.get('ARDUINO_IDE_PATH') - if not ide_path: - print("Please specify Arduino IDE path via --ide_path option" - "or ARDUINO_IDE_PATH environment variable.", file=sys.stderr) - return 2 - - sketch_path = args.sketch_path - tmp_dir = args.build_path - created_tmp_dir = False - if not tmp_dir: - tmp_dir = tempfile.mkdtemp() - created_tmp_dir = True - - tools_dir = os.path.dirname(os.path.realpath(__file__)) + '/../tools' - # this is not the correct hardware folder to add. - hardware_dir = ide_path + '/hardware' - - output_name = tmp_dir + '/' + os.path.basename(sketch_path) + '.bin' - if args.verbose: - print("Sketch: ", sketch_path) - print("Build dir: ", tmp_dir) - print("Output: ", output_name) - - if args.verbose: - f = sys.stdout - else: - f = open(tmp_dir + '/build.log', 'w') - - res = compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args) - if res != 0: - return res - - if args.output_binary is not None: - shutil.copy(output_name, args.output_binary) - - if created_tmp_dir and not args.keep: - shutil.rmtree(tmp_dir, ignore_errors=True) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/travis/build.sh b/travis/build.sh index 8bfd0de..5b98306 100644 --- a/travis/build.sh +++ b/travis/build.sh @@ -1,14 +1,37 @@ #!/bin/bash -echo -e "travis_fold:start:sketch_test_env_prepare" -pip install pyserial +CHUNK_INDEX=$1 +CHUNKS_CNT=$2 +if [ "$#" -lt 2 ]; then + echo "Building all sketches" + CHUNK_INDEX=0 + CHUNKS_CNT=1 +fi +if [ "$CHUNKS_CNT" -le 0 ]; then + echo "Chunks count must be positive number" + exit 1 +fi +if [ "$CHUNK_INDEX" -ge "$CHUNKS_CNT" ]; then + echo "Chunk index must be less than chunks count" + exit 1 +fi + +echo -e "travis_fold:start:prep_arduino_ide" +# Install Arduino IDE wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz tar xf arduino.tar.xz mv arduino-nightly $HOME/arduino_ide mkdir -p $HOME/Arduino/libraries +mkdir -p $HOME/Arduino/hardware +echo -e "travis_fold:end:prep_arduino_ide" + +echo -e "travis_fold:start:sketch_test_env_prepare" cd $HOME/Arduino/libraries cp -rf $TRAVIS_BUILD_DIR AsyncTCP -cd $HOME/arduino_ide/hardware +PLATFORM_EXAMPLES=$TRAVIS_BUILD_DIR/examples + +cd $HOME/Arduino/hardware +pip install pyserial mkdir espressif cd espressif git clone https://github.com/espressif/arduino-esp32.git esp32 @@ -16,12 +39,158 @@ cd esp32 git submodule update --init --recursive cd tools python get.py -cd $TRAVIS_BUILD_DIR -export PATH="$HOME/arduino_ide:$HOME/arduino_ide/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin:$PATH" -source travis/common.sh +PLATFORM_FQBN="espressif:esp32:esp32" +PLATFORM_SIZE_BIN=$HOME/Arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-size echo -e "travis_fold:end:sketch_test_env_prepare" -echo -e "travis_fold:start:sketch_test" -build_sketches $HOME/arduino_ide $HOME/Arduino/libraries/AsyncTCP/examples "-l $HOME/Arduino/libraries" +cd $TRAVIS_BUILD_DIR + +ARDUINO_IDE_PATH=$HOME/arduino_ide +ARDUINO_USR_PATH=$HOME/Arduino +ARDUINO_BUILD_DIR=$HOME/build.tmp +ARDUINO_CACHE_DIR=$HOME/cache.tmp +ARDUINO_BUILD_CMD="$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 -hardware \"$ARDUINO_IDE_PATH/hardware\" -hardware \"$ARDUINO_USR_PATH/hardware\" -tools \"$ARDUINO_IDE_PATH/tools-builder\" -built-in-libraries \"$ARDUINO_IDE_PATH/libraries\" -libraries \"$ARDUINO_USR_PATH/libraries\" -fqbn=$PLATFORM_FQBN -warnings=\"all\" -build-cache \"$ARDUINO_CACHE_DIR\" -build-path \"$ARDUINO_BUILD_DIR\" -verbose" + +function print_size_info() +{ + elf_file=$1 + + if [ -z "$elf_file" ]; then + printf "sketch iram0.text flash.text flash.rodata dram0.data dram0.bss dram flash\n" + return 0 + fi + + elf_name=$(basename $elf_file) + sketch_name="${elf_name%.*}" + declare -A segments + while read -a tokens; do + seg=${tokens[0]} + seg=${seg//./} + size=${tokens[1]} + addr=${tokens[2]} + if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then + segments[$seg]=$size + fi + done < <($PLATFORM_SIZE_BIN --format=sysv $elf_file) + + total_ram=$((${segments[dram0data]} + ${segments[dram0bss]})) + total_flash=$((${segments[iram0text]} + ${segments[flashtext]} + ${segments[dram0data]} + ${segments[flashrodata]})) + printf "%-32s %-8d %-8d %-8d %-8d %-8d %-8d %-8d\n" $sketch_name ${segments[iram0text]} ${segments[flashtext]} ${segments[flashrodata]} ${segments[dram0data]} ${segments[dram0bss]} $total_ram $total_flash + return 0 +} + +function build_sketch() +{ + local sketch=$1 + echo -e "\n------------ Building $sketch ------------\n"; + rm -rf $ARDUINO_BUILD_DIR/* + time ($ARDUINO_BUILD_CMD $sketch >build.log) + local result=$? + if [ $result -ne 0 ]; then + echo "Build failed ($1)" + echo "Build log:" + cat build.log + return $result + fi + rm build.log + return 0 +} + +function count_sketches() +{ + local sketches=$(find $PLATFORM_EXAMPLES -name *.ino) + local sketchnum=0 + rm -rf sketches.txt + for sketch in $sketches; do + local sketchdir=$(dirname $sketch) + local sketchdirname=$(basename $sketchdir) + local sketchname=$(basename $sketch) + if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then + continue + fi + echo $sketch >> sketches.txt + sketchnum=$(($sketchnum + 1)) + done + return $sketchnum +} + +function build_sketches() +{ + mkdir -p $ARDUINO_BUILD_DIR + mkdir -p $ARDUINO_CACHE_DIR + mkdir -p $ARDUINO_USR_PATH/libraries + mkdir -p $ARDUINO_USR_PATH/hardware + + local chunk_idex=$1 + local chunks_num=$2 + count_sketches + local sketchcount=$? + local sketches=$(cat sketches.txt) + + local chunk_size=$(( $sketchcount / $chunks_num )) + local all_chunks=$(( $chunks_num * $chunk_size )) + if [ "$all_chunks" -lt "$sketchcount" ]; then + chunk_size=$(( $chunk_size + 1 )) + fi + + local start_index=$(( $chunk_idex * $chunk_size )) + if [ "$sketchcount" -le "$start_index" ]; then + echo "Skipping job" + return 0 + fi + + local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) + if [ "$end_index" -gt "$sketchcount" ]; then + end_index=$sketchcount + fi + + local start_num=$(( $start_index + 1 )) + #echo -e "Sketches: \n$sketches\n" + echo "Found $sketchcount Sketches"; + echo "Chunk Count : $chunks_num" + echo "Chunk Size : $chunk_size" + echo "Start Sketch: $start_num" + echo "End Sketch : $end_index" + + local sketchnum=0 + print_size_info >size.log + for sketch in $sketches; do + local sketchdir=$(dirname $sketch) + local sketchdirname=$(basename $sketchdir) + local sketchname=$(basename $sketch) + if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then + #echo "Skipping $sketch, beacause it is not the main sketch file"; + continue + fi; + if [[ -f "$sketchdir/.test.skip" ]]; then + #echo "Skipping $sketch marked"; + continue + fi + sketchnum=$(($sketchnum + 1)) + if [ "$sketchnum" -le "$start_index" ]; then + #echo "Skipping $sketch index low" + continue + fi + if [ "$sketchnum" -gt "$end_index" ]; then + #echo "Skipping $sketch index high" + continue + fi + build_sketch $sketch + local result=$? + if [ $result -ne 0 ]; then + return $result + fi + print_size_info $ARDUINO_BUILD_DIR/*.elf >>size.log + done + return 0 +} + +echo -e "travis_fold:start:test_arduino_ide" +# Build Examples +build_sketches $CHUNK_INDEX $CHUNKS_CNT if [ $? -ne 0 ]; then exit 1; fi -echo -e "travis_fold:end:sketch_test" +echo -e "travis_fold:end:test_arduino_ide" + +echo -e "travis_fold:start:size_report" +cat size.log +echo -e "travis_fold:end:size_report" diff --git a/travis/common.sh b/travis/common.sh deleted file mode 100755 index d299b4f..0000000 --- a/travis/common.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -function build_sketches() -{ - #set +e - local arduino=$1 - local srcpath=$2 - local build_arg=$3 - local build_dir=build.tmp - mkdir -p $build_dir - local build_cmd="python travis/build.py -b esp32 -k -p $PWD/$build_dir $build_arg " - local sketches=$(find $srcpath -name *.ino) - export ARDUINO_IDE_PATH=$arduino - for sketch in $sketches; do - rm -rf $build_dir/* - local sketchdir=$(dirname $sketch) - local sketchdirname=$(basename $sketchdir) - local sketchname=$(basename $sketch) - if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then - echo "Skipping $sketch, beacause it is not the main sketch file"; - continue - fi; - if [[ -f "$sketchdir/.test.skip" ]]; then - echo -e "\n ------------ Skipping $sketch ------------ \n"; - continue - fi - echo -e "\n ------------ Building $sketch ------------ \n"; - time ($build_cmd $sketch >$build_dir/build.log) - local result=$? - if [ $result -ne 0 ]; then - echo "Build failed ($1)" - echo "Build log:" - cat $build_dir/build.log - return $result - fi - rm $build_dir/build.log - done - #set -e -} From 861b3aa8a0d4845d336d4ee68239fa691b51cc14 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 21 Sep 2019 15:03:35 +0300 Subject: [PATCH 3/7] Update build scripts --- .travis.yml | 11 ++++++++--- travis/build-pio.sh | 40 ++++++++++++++++++++++++++++++++++++++++ travis/build.sh | 17 ++++++++++++++--- 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 travis/build-pio.sh diff --git a/.travis.yml b/.travis.yml index 020b430..bc36dba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ sudo: false -language: bash +language: python os: - linux @@ -12,11 +12,16 @@ stages: jobs: include: - - name: "Build Examples" + - name: "Arduino Build" if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) stage: build script: bash $TRAVIS_BUILD_DIR/travis/build.sh + - name: "PlatformIO Build" + if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) + stage: build + script: bash $TRAVIS_BUILD_DIR/travis/build-pio.sh + notifications: email: on_success: change @@ -26,4 +31,4 @@ notifications: - https://webhooks.gitter.im/e/60e65d0c78ea0a920347 on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always - on_start: never # options: [always|never|change] default: always + on_start: false # default: false diff --git a/travis/build-pio.sh b/travis/build-pio.sh new file mode 100644 index 0000000..083b473 --- /dev/null +++ b/travis/build-pio.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +echo -e "travis_fold:start:install_pio" +pip install -U platformio +if [ $? -ne 0 ]; then exit 1; fi +echo -e "travis_fold:end:install_pio" + +echo -e "travis_fold:start:install_lib" +python -m platformio lib --storage-dir $TRAVIS_BUILD_DIR install +if [ $? -ne 0 ]; then exit 1; fi +echo -e "travis_fold:end:install_lib" + +echo -e "travis_fold:start:test_pio" +if [ -d "$TRAVIS_BUILD_DIR/examples" ]; then + for EXAMPLE in $TRAVIS_BUILD_DIR/examples/*/*.ino; do + python -m platformio ci $EXAMPLE -l '.' -b esp32dev + if [ $? -ne 0 ]; then exit 1; fi + done +fi +echo -e "travis_fold:end:test_pio" + +echo -e "travis_fold:start:install_json" +python -m platformio lib -g install https://github.com/bblanchon/ArduinoJson.git +if [ $? -ne 0 ]; then exit 1; fi +echo -e "travis_fold:end:install_json" + +cd $HOME/ +echo -e "travis_fold:start:install_web_server" +git clone https://github.com/me-no-dev/ESPAsyncWebServer +if [ $? -ne 0 ]; then exit 1; fi +python -m platformio lib --storage-dir $HOME/ESPAsyncWebServer install +if [ $? -ne 0 ]; then exit 1; fi +echo -e "travis_fold:end:install_web_server" + +echo -e "travis_fold:start:test_web_server" +for EXAMPLE in $HOME/ESPAsyncWebServer/examples/*/*.ino; do + python -m platformio ci $EXAMPLE -l $TRAVIS_BUILD_DIR -l $HOME/ESPAsyncWebServer -b esp32dev + if [ $? -ne 0 ]; then exit 1; fi +done +echo -e "travis_fold:end:test_web_server" diff --git a/travis/build.sh b/travis/build.sh index 5b98306..4992310 100644 --- a/travis/build.sh +++ b/travis/build.sh @@ -30,6 +30,10 @@ cd $HOME/Arduino/libraries cp -rf $TRAVIS_BUILD_DIR AsyncTCP PLATFORM_EXAMPLES=$TRAVIS_BUILD_DIR/examples +git clone https://github.com/me-no-dev/ESPAsyncWebServer +git clone https://github.com/bblanchon/ArduinoJson +LIB_EXAMPLES=$HOME/Arduino/libraries/ESPAsyncWebServer/examples + cd $HOME/Arduino/hardware pip install pyserial mkdir espressif @@ -98,9 +102,12 @@ function build_sketch() function count_sketches() { - local sketches=$(find $PLATFORM_EXAMPLES -name *.ino) + local path=$1 + if [ ! -d "$path" ]; then + return 0 + fi + local sketches=$(find $path -name *.ino) local sketchnum=0 - rm -rf sketches.txt for sketch in $sketches; do local sketchdir=$(dirname $sketch) local sketchdirname=$(basename $sketchdir) @@ -123,8 +130,12 @@ function build_sketches() local chunk_idex=$1 local chunks_num=$2 - count_sketches + rm -rf sketches.txt + count_sketches $PLATFORM_EXAMPLES local sketchcount=$? + count_sketches $LIB_EXAMPLES + local libsketchcount=$? + sketchcount=$(($sketchcount + $libsketchcount)) local sketches=$(cat sketches.txt) local chunk_size=$(( $sketchcount / $chunks_num )) From c5ca5aee4e668de3e4410e8698b73d40b9663fb9 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Sat, 21 Sep 2019 15:05:52 +0300 Subject: [PATCH 4/7] Enable Github CI --- .github/workflows/main.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0ca72d5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: Async TCP CI + +on: + push: + branches: + - master + - release/* + pull_request: + +jobs: + + build-arduino: + name: Build Arduino + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Build Tests + env: + TRAVIS_BUILD_DIR: ${{ github.workspace }} + run: bash $TRAVIS_BUILD_DIR/travis/build.sh + + build-pio: + name: Build PlatformIO + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Install Python Wheel + run: pip install wheel + - name: Build Tests + env: + TRAVIS_BUILD_DIR: ${{ github.workspace }} + run: bash $TRAVIS_BUILD_DIR/travis/build-pio.sh From c1dcba41d10ca80649eb6ed8cb7d914ae331c6c3 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 21 Sep 2019 15:09:58 +0300 Subject: [PATCH 5/7] Trigger travis also --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 023849b..00f3d72 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Async TCP Library for ESP32 Arduino [![Join the chat at https://gitter.im/me-no-dev/ESPAsyncWebServer](https://badges.gitter.im/me-no-dev/ESPAsyncWebServer.svg)](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/me-no-dev/AsyncTCP.svg?branch=master)](https://travis-ci.org/me-no-dev/AsyncTCP) + This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP32 MCUs. This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) From f8e97b49305bb3387252b447bed117e84df8eb7d Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 21 Sep 2019 15:45:17 +0300 Subject: [PATCH 6/7] Create stale.yml --- .github/stale.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/stale.yml diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..ce7a8e3 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,31 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +daysUntilStale: 60 +daysUntilClose: 14 +limitPerRun: 30 +staleLabel: stale +exemptLabels: + - pinned + - security + - "to be implemented" + - "for reference" + - "move to PR" + - "enhancement" + +only: issues +onlyLabels: [] +exemptProjects: false +exemptMilestones: false +exemptAssignees: false + +markComment: > + [STALE_SET] This issue has been automatically marked as stale because it has not had + recent activity. It will be closed in 14 days if no further activity occurs. Thank you + for your contributions. + +unmarkComment: > + [STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. + +closeComment: > + [STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. + From 911414ee98a5c6093a4316e26f9b4eb12e36e78a Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 22 Sep 2019 17:59:53 +0100 Subject: [PATCH 7/7] Revert "try to catch some edge cases between LwIP and Async tasks" and fix in a completely different way. --- src/AsyncTCP.cpp | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index 453fa82..353feee 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -78,6 +78,7 @@ typedef struct { static xQueueHandle _async_queue; static TaskHandle_t _async_service_task_handle = NULL; +static tcp_pcb * pcb_recently_closed = NULL; static inline bool _init_async_event_queue(){ if(!_async_queue){ @@ -327,7 +328,6 @@ static int8_t _tcp_accept(void * arg, AsyncClient * client) { typedef struct { struct tcpip_api_call_data call; tcp_pcb * pcb; - AsyncClient * client; int8_t err; union { struct { @@ -352,19 +352,19 @@ typedef struct { static err_t _tcp_output_api(struct tcpip_api_call_data *api_call_msg){ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg; msg->err = ERR_CONN; - if(msg->client && msg->client->pcb() == msg->pcb){ + if(msg->pcb != pcb_recently_closed) { msg->err = tcp_output(msg->pcb); } + pcb_recently_closed = NULL; return msg->err; } -static esp_err_t _tcp_output(tcp_pcb * pcb, AsyncClient * client) { +static esp_err_t _tcp_output(tcp_pcb * pcb) { if(!pcb){ return ERR_CONN; } tcp_api_call_t msg; msg.pcb = pcb; - msg.client = client; tcpip_api_call(_tcp_output_api, (struct tcpip_api_call_data*)&msg); return msg.err; } @@ -372,19 +372,19 @@ static esp_err_t _tcp_output(tcp_pcb * pcb, AsyncClient * client) { static err_t _tcp_write_api(struct tcpip_api_call_data *api_call_msg){ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg; msg->err = ERR_CONN; - if(msg->client && msg->client->pcb() == msg->pcb){ + if(msg->pcb != pcb_recently_closed) { msg->err = tcp_write(msg->pcb, msg->write.data, msg->write.size, msg->write.apiflags); } + pcb_recently_closed = NULL; return msg->err; } -static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_t apiflags, AsyncClient * client) { +static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_t apiflags) { if(!pcb){ return ERR_CONN; } tcp_api_call_t msg; msg.pcb = pcb; - msg.client = client; msg.write.data = data; msg.write.size = size; msg.write.apiflags = apiflags; @@ -395,20 +395,20 @@ static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_ static err_t _tcp_recved_api(struct tcpip_api_call_data *api_call_msg){ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg; msg->err = ERR_CONN; - if(msg->client && msg->client->pcb() == msg->pcb){ + if(msg->pcb != pcb_recently_closed) { msg->err = 0; tcp_recved(msg->pcb, msg->received); } + pcb_recently_closed = NULL; return msg->err; } -static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len, AsyncClient * client) { +static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len) { if(!pcb){ return ERR_CONN; } tcp_api_call_t msg; msg.pcb = pcb; - msg.client = client; msg.received = len; tcpip_api_call(_tcp_recved_api, (struct tcpip_api_call_data*)&msg); return msg.err; @@ -417,19 +417,19 @@ static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len, AsyncClient * client) { static err_t _tcp_close_api(struct tcpip_api_call_data *api_call_msg){ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg; msg->err = ERR_CONN; - if(!msg->client || msg->client->pcb() == msg->pcb){ + if(msg->pcb != pcb_recently_closed) { msg->err = tcp_close(msg->pcb); } + pcb_recently_closed = NULL; return msg->err; } -static esp_err_t _tcp_close(tcp_pcb * pcb, AsyncClient * client) { +static esp_err_t _tcp_close(tcp_pcb * pcb) { if(!pcb){ return ERR_CONN; } tcp_api_call_t msg; msg.pcb = pcb; - msg.client = client; tcpip_api_call(_tcp_close_api, (struct tcpip_api_call_data*)&msg); return msg.err; } @@ -437,19 +437,19 @@ static esp_err_t _tcp_close(tcp_pcb * pcb, AsyncClient * client) { static err_t _tcp_abort_api(struct tcpip_api_call_data *api_call_msg){ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg; msg->err = ERR_CONN; - if(!msg->client || msg->client->pcb() == msg->pcb){ + if(msg->pcb != pcb_recently_closed) { tcp_abort(msg->pcb); } + pcb_recently_closed = NULL; return msg->err; } -static esp_err_t _tcp_abort(tcp_pcb * pcb, AsyncClient * client) { +static esp_err_t _tcp_abort(tcp_pcb * pcb) { if(!pcb){ return ERR_CONN; } tcp_api_call_t msg; msg.pcb = pcb; - msg.client = client; tcpip_api_call(_tcp_abort_api, (struct tcpip_api_call_data*)&msg); return msg.err; } @@ -697,14 +697,14 @@ bool AsyncClient::connect(const char* host, uint16_t port){ void AsyncClient::close(bool now){ if(_pcb){ - _tcp_recved(_pcb, _rx_ack_len, this); + _tcp_recved(_pcb, _rx_ack_len); } _close(); } int8_t AsyncClient::abort(){ if(_pcb) { - _tcp_abort(_pcb, this); + _tcp_abort(_pcb); _pcb = NULL; } return ERR_ABRT; @@ -727,7 +727,7 @@ size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) { } size_t will_send = (room < size) ? room : size; int8_t err = ERR_OK; - err = _tcp_write(_pcb, data, will_send, apiflags, this); + err = _tcp_write(_pcb, data, will_send, apiflags); if(err != ERR_OK) { return 0; } @@ -736,7 +736,7 @@ size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) { bool AsyncClient::send(){ int8_t err = ERR_OK; - err = _tcp_output(_pcb, this); + err = _tcp_output(_pcb); if(err == ERR_OK){ _pcb_busy = true; _pcb_sent_at = millis(); @@ -749,7 +749,7 @@ size_t AsyncClient::ack(size_t len){ if(len > _rx_ack_len) len = _rx_ack_len; if(len){ - _tcp_recved(_pcb, len, this); + _tcp_recved(_pcb, len); } _rx_ack_len -= len; return len; @@ -759,7 +759,7 @@ void AsyncClient::ackPacket(struct pbuf * pb){ if(!pb){ return; } - _tcp_recved(_pcb, pb->len, this); + _tcp_recved(_pcb, pb->len); pbuf_free(pb); } @@ -778,7 +778,7 @@ int8_t AsyncClient::_close(){ tcp_err(_pcb, NULL); tcp_poll(_pcb, NULL, 0); _tcp_clear_events(this); - err = _tcp_close(_pcb, this); + err = _tcp_close(_pcb); if(err != ERR_OK) { err = abort(); } @@ -840,6 +840,7 @@ int8_t AsyncClient::_lwip_fin(tcp_pcb* pcb, int8_t err) { if(tcp_close(_pcb) != ERR_OK) { tcp_abort(_pcb); } + pcb_recently_closed = _pcb; _pcb = NULL; return ERR_OK; } @@ -880,7 +881,7 @@ int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) { if(!_ack_pcb) { _rx_ack_len += b->len; } else if(_pcb) { - _tcp_recved(_pcb, b->len, this); + _tcp_recved(_pcb, b->len); } pbuf_free(b); } @@ -1227,7 +1228,7 @@ void AsyncServer::begin(){ err = _tcp_bind(_pcb, &local_addr, _port); if (err != ERR_OK) { - _tcp_close(_pcb, NULL); + _tcp_close(_pcb); log_e("bind error: %d", err); return; } @@ -1246,7 +1247,7 @@ void AsyncServer::end(){ if(_pcb){ tcp_arg(_pcb, NULL); tcp_accept(_pcb, NULL); - _tcp_abort(_pcb, NULL); + _tcp_abort(_pcb); _pcb = NULL; } }