return lws_write(wsi, p, (size_t)n, LWS_WRITE_BINARY);
}
-static bool parse_window_size(struct pss_tty *pss, int *cols, int *rows) {
+static bool parse_window_size(struct pss_tty *pss, uint16_t *cols, uint16_t *rows) {
char json[pss->len];
strncpy(json, pss->buffer + 1, pss->len - 1);
json[pss->len - 1] = '\0';
lwsl_err("columns field not exists, json: %s\n", json);
return false;
}
- *cols = json_object_get_int(o);
+ *cols = (uint16_t) json_object_get_int(o);
if (!json_object_object_get_ex(obj, "rows", &o)) {
lwsl_err("rows field not exists, json: %s\n", json);
return false;
}
- *rows = json_object_get_int(o);
+ *rows = (uint16_t) json_object_get_int(o);
json_object_put(obj);
return true;
}
break;
case RESIZE_TERMINAL: {
- int cols, rows;
+ uint16_t cols, rows;
if (parse_window_size(pss, &cols, &rows)) {
- if (pty_resize(pss->process, rows, cols) < 0) {
- lwsl_err("pty_resize: %d (%s)\n", errno, strerror(errno));
- }
+ pty_resize(pss->process, cols, rows);
}
} break;
case PAUSE:
return uv_write(req, (uv_stream_t *) io->in, &b, 1, write_cb);
}
-int pty_resize(pty_process *process, int width, int height) {
+bool pty_resize(pty_process *process, uint16_t width, uint16_t height) {
#ifdef _WIN32
- COORD size = { height, width };
- return pResizePseudoConsole(process->pty, size) == S_OK ? 0 : -1;
+ COORD size = { (int16_t) width, (int16_t) height };
+ return pResizePseudoConsole(process->pty, size) == S_OK;
#else
- struct winsize size;
- size.ws_col = (unsigned short) height;
- size.ws_row = (unsigned short) width;
- size.ws_xpixel = 0;
- size.ws_ypixel = 0;
- return ioctl(process->pty, TIOCSWINSZ, &size);
+ struct winsize size = { height, width, 0, 0 };
+ return ioctl(process->pty, TIOCSWINSZ, &size) == 0;
#endif
}
-int pty_close(pty_process *process, int sig) {
+bool pty_close(pty_process *process, int sig) {
process->killed = true;
#ifdef _WIN32
- return TerminateProcess(process->handle, 1) ? 0 : 1;
+ return TerminateProcess(process->handle, 1) != 0;
#else
- return uv_kill(-process->pid, sig);
+ return uv_kill(-process->pid, sig) == 0;
#endif
}
goto cleanup;
}
- process->pid = GetProcessId(pi.hProcess);
+ process->pid = pi.dwProcessId;
process->handle = pi.hProcess;
process->exit_cb = exit_cb;
#define TTYD_PTY_H
#include <stdbool.h>
+#include <stdint.h>
#include <uv.h>
#ifdef _WIN32
void pty_pause(pty_process *process);
void pty_resume(pty_process *process);
int pty_write(pty_process *process, pty_buf_t *buf);
-int pty_resize(pty_process *process, int width, int height);
-int pty_close(pty_process *process, int sig);
+bool pty_resize(pty_process *process, uint16_t width, uint16_t height);
+bool pty_close(pty_process *process, int sig);
#endif // TTYD_PTY_H