From 8e63937351edfd2e0ad1af5f384df6879860aac8 Mon Sep 17 00:00:00 2001 From: bin Date: Mon, 28 Oct 2024 13:59:49 +0800 Subject: [PATCH 1/5] add test code --- src/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 39f40e993..37525e122 100644 --- a/src/server.c +++ b/src/server.c @@ -350,7 +350,7 @@ int main(int argc, char **argv) { print_help(); return 0; case 'v': - printf("ttyd version %s\n", TTYD_VERSION); + printf("ttyd version 666 %s\n", TTYD_VERSION); return 0; case 'd': debug_level = parse_int("debug", optarg); From 29209531a647b28ee4e3f88ec911677c62dee9d8 Mon Sep 17 00:00:00 2001 From: bin Date: Mon, 28 Oct 2024 14:21:22 +0800 Subject: [PATCH 2/5] update version to 1.7.8 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eab7c785..cfb56d3cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12.0) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -project(ttyd VERSION 1.7.7 LANGUAGES C) +project(ttyd VERSION 1.7.8 LANGUAGES C) set(TTYD_VERSION "${PROJECT_VERSION}") From 432bc3e6435e6d6c6665bff8db9661f3a475a518 Mon Sep 17 00:00:00 2001 From: bin Date: Mon, 28 Oct 2024 13:59:49 +0800 Subject: [PATCH 3/5] support setting service buffer size. --- README.md | 1 + man/ttyd.1 | 4 ++++ man/ttyd.man.md | 3 +++ src/server.c | 14 +++++++++++++- src/server.h | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 847933230..f4042617c 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ OPTIONS: -d, --debug Set log level (default: 7) -v, --version Print the version and exit -h, --help Print this text and exit + -f, --serv_buffer_size Maximum chunk of file that can be sent at once ``` Read the example usage on the [wiki](https://github.com/tsl0922/ttyd/wiki/Example-Usage). diff --git a/man/ttyd.1 b/man/ttyd.1 index 826ea5f18..76ad9e7c7 100644 --- a/man/ttyd.1 +++ b/man/ttyd.1 @@ -141,6 +141,10 @@ Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows -A, --ssl-ca SSL CA file path for client certificate verification +.PP +-f, --serv_buffer_size + Maximum chunk of file that can be sent at once + .PP -d, --debug Set log level (default: 7) diff --git a/man/ttyd.man.md b/man/ttyd.man.md index 98497cb90..66eaf25ba 100644 --- a/man/ttyd.man.md +++ b/man/ttyd.man.md @@ -98,6 +98,9 @@ ttyd 1 "September 2016" ttyd "User Manual" -A, --ssl-ca SSL CA file path for client certificate verification + -f, --serv_buffer_size + Maximum chunk of file that can be sent at once + -d, --debug Set log level (default: 7) diff --git a/src/server.c b/src/server.c index 37525e122..2fb05cf78 100644 --- a/src/server.c +++ b/src/server.c @@ -82,8 +82,9 @@ static const struct option options[] = {{"port", required_argument, NULL, 'p'}, {"debug", required_argument, NULL, 'd'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, + {"serv_buffer_size", required_argument, NULL, 'f'}, {NULL, 0, 0, 0}}; -static const char *opt_string = "p:i:U:c:H:u:g:s:w:I:b:P:6aSC:K:A:Wt:T:Om:oqBd:vh"; +static const char *opt_string = "p:i:U:c:H:u:g:s:w:I:b:f:P:6aSC:K:A:Wt:T:Om:oqBd:vh"; static void print_help() { // clang-format off @@ -113,6 +114,7 @@ static void print_help() { " -B, --browser Open terminal with the default system browser\n" " -I, --index Custom index.html path\n" " -b, --base-path Expected base path for requests coming from a reverse proxy (eg: /mounted/here, max length: 128)\n" + " -f, --serv_buffer_size Maximum chunk of file that can be sent at once (eg: --service_buffer_size 4096 indicates 4KB)\n" #if LWS_LIBRARY_VERSION_NUMBER >= 4000000 " -P, --ping-interval Websocket ping interval(sec) (default: 5)\n" #endif @@ -155,6 +157,7 @@ static void print_config() { if (server->exit_no_conn) lwsl_notice(" exit_no_conn: true\n"); if (server->index != NULL) lwsl_notice(" custom index.html: %s\n", server->index); if (server->cwd != NULL) lwsl_notice(" working directory: %s\n", server->cwd); + if (server->serv_buffer_size != 0) lwsl_notice(" Service buffer size: %d bytes\n", server->serv_buffer_size); if (!server->writable) lwsl_notice("The --writable option is not set, will start in readonly mode"); } @@ -327,6 +330,7 @@ int main(int argc, char **argv) { #endif info.max_http_header_data = 65535; + int debug_level = LLL_ERR | LLL_WARN | LLL_NOTICE; char iface[128] = ""; char socket_owner[128] = ""; @@ -383,6 +387,14 @@ int main(int argc, char **argv) { return -1; } break; + case 'f': + info.pt_serv_buf_size = parse_int("serv_buffer_size", optarg); + if (info.pt_serv_buf_size < 0) { + fprintf(stderr, "ttyd: invalid service buffer size: %s\n", optarg); + return -1; + } + server->serv_buffer_size = info.pt_serv_buf_size; + break; case 'i': strncpy(iface, optarg, sizeof(iface) - 1); iface[sizeof(iface) - 1] = '\0'; diff --git a/src/server.h b/src/server.h index e13d63271..fcd82ccbc 100644 --- a/src/server.h +++ b/src/server.h @@ -63,6 +63,7 @@ typedef struct { struct server { int client_count; // client count + int serv_buffer_size; // service buffer size char *prefs_json; // client preferences char *credential; // encoded basic auth credential char *auth_header; // header name used for auth proxy From cabb635a33a5e5a9fd8d4d3d65909cc30c7d7e43 Mon Sep 17 00:00:00 2001 From: bin Date: Wed, 30 Oct 2024 17:20:27 +0800 Subject: [PATCH 4/5] bump version to 1.7.9 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfb56d3cb..4c4060a6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12.0) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -project(ttyd VERSION 1.7.8 LANGUAGES C) +project(ttyd VERSION 1.7.9 LANGUAGES C) set(TTYD_VERSION "${PROJECT_VERSION}") From 67de02bb436f9f9c80f78dccc76bec1a134fe0a6 Mon Sep 17 00:00:00 2001 From: bin Date: Wed, 30 Oct 2024 19:42:01 +0800 Subject: [PATCH 5/5] bump version to 1.7.8 --- CMakeLists.txt | 2 +- src/server.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c4060a6c..cfb56d3cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12.0) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -project(ttyd VERSION 1.7.9 LANGUAGES C) +project(ttyd VERSION 1.7.8 LANGUAGES C) set(TTYD_VERSION "${PROJECT_VERSION}") diff --git a/src/server.c b/src/server.c index 2fb05cf78..c9e2fa967 100644 --- a/src/server.c +++ b/src/server.c @@ -354,7 +354,7 @@ int main(int argc, char **argv) { print_help(); return 0; case 'v': - printf("ttyd version 666 %s\n", TTYD_VERSION); + printf("ttyd version %s\n", TTYD_VERSION); return 0; case 'd': debug_level = parse_int("debug", optarg);