Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lag with lws 3.2, based on ttyd upstream fix #21

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ char initial_cmds[] = {
SET_PREFERENCES
};

int
send_initial_message(struct lws *wsi, int index) {
static void stagger_callback(lws_sorted_usec_list_t *sul) {
struct tty_client *client = lws_container_of(sul, struct tty_client, sul_stagger);

lws_callback_on_writable(client->wsi);
lws_sul_schedule(context, 0, sul, stagger_callback, 10);
}

int send_initial_message(struct lws *wsi, int index) {
unsigned char message[LWS_PRE + 1 + 4096];
unsigned char *p = &message[LWS_PRE];
char buffer[128];
Expand Down Expand Up @@ -149,6 +155,8 @@ void tty_client_destroy(struct tty_client *client) {
if (client->buffer != NULL)
free(client->buffer);

lws_sul_schedule(context, 0, &client->sul_stagger, NULL, LWS_SET_TIMER_USEC_CANCEL);

// remove from client list
tty_client_remove(client);
}
Expand Down Expand Up @@ -301,6 +309,8 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
// check if there are more fragmented messages
if (lws_remaining_packet_payload(wsi) > 0 || !lws_is_final_fragment(wsi)) {
return 0;
} else {
lws_sul_schedule(context, 0, &client->sul_stagger, stagger_callback, 10);
}

switch (command) {
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ int main(int argc, char **argv) {
while(!force_exit) {
lws_service(context, 0);
process_watch();
usleep(5000);
usleep(1000);
}

printf("[+] exiting\n");
Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ struct tty_client {
ssize_t pty_len;

LIST_ENTRY(tty_client) list;

lws_sorted_usec_list_t sul_stagger;
};

struct pss_http {
Expand Down