continue;
}
memset(client->pty_buffer, 0, sizeof(client->pty_buffer));
- client->pty_len = read(pty, client->pty_buffer, sizeof(client->pty_buffer));
+ client->pty_len = read(pty, client->pty_buffer + LWS_PRE + 1, BUF_SIZE);
client->state = STATE_READY;
pthread_mutex_unlock(&client->mutex);
break;
void *user, void *in, size_t len) {
struct tty_client *client = (struct tty_client *) user;
char buf[256];
+ size_t n = 0;
switch (reason) {
case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
return -1;
}
- {
- size_t n = (size_t) client->pty_len + 1;
- unsigned char message[LWS_PRE + n];
- unsigned char *p = &message[LWS_PRE];
- *p = OUTPUT;
- memcpy(p + 1, client->pty_buffer, client->pty_len);
- client->state = STATE_DONE;
-
- if (lws_write(wsi, p, n, LWS_WRITE_BINARY) < n) {
- lwsl_err("write data to WS\n");
- }
+ client->pty_buffer[LWS_PRE] = OUTPUT;
+ n = (size_t) (client->pty_len + 1);
+ if (lws_write(wsi, (unsigned char *) client->pty_buffer + LWS_PRE, n, LWS_WRITE_BINARY) < n) {
+ lwsl_err("write data to WS\n");
}
+ client->state = STATE_DONE;
break;
case LWS_CALLBACK_RECEIVE: