Skip to content

Commit

Permalink
support setting service buffer size.
Browse files Browse the repository at this point in the history
  • Loading branch information
flpanbin committed Oct 29, 2024
1 parent 40e79c7 commit 47d993c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 4 additions & 0 deletions man/ttyd.1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions man/ttyd.man.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ ttyd 1 "September 2016" ttyd "User Manual"
-A, --ssl-ca <ca path>
SSL CA file path for client certificate verification

-f, --serv_buffer_size <buffer size>
Maximum chunk of file that can be sent at once

-d, --debug <level>
Set log level (default: 7)

Expand Down
14 changes: 13 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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] = "";
Expand Down Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47d993c

Please sign in to comment.