work commit

imagine getting paid to write this thing teehee ~
This commit is contained in:
reemo 2023-12-26 11:06:13 -06:00
parent c07a007731
commit 0066350ffc
3 changed files with 35 additions and 3 deletions

View file

@ -75,11 +75,35 @@ int main(int argc, char** argv) {
sprintf(buf, "1\tMisuzu\t%s", _G.session); sprintf(buf, "1\tMisuzu\t%s", _G.session);
wsock_send_str(sock, buf); wsock_send_str(sock, buf);
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
FD_SET(sock->sock, &fds);
struct timeval tout;
tout.tv_sec = 5;
tout.tv_usec = 0;
int buf_at = 0;
for(;;) { for(;;) {
printf("**** pinged ****\n");
wsock_ping(sock, NULL);
int sel = select(sock->sock + 1, &fds, NULL, NULL, &tout);
if(sel > 0) {
if(FD_ISSET(0, &fds)) {
buf_at += fread(buf + buf_at, 1, sizeof(buf) - buf_at, 0);
buf[buf_at] = '\0';
printf("%s\n", buf);
}
if(FD_ISSET(sock->sock, &fds)) {
wsock_recv(sock, &get); wsock_recv(sock, &get);
printf("%s\n", get); printf("%s\n", get);
free(get); free(get);
} }
}
}
initscr(); initscr();
raw(); noecho(); raw(); noecho();

View file

@ -494,6 +494,13 @@ int wsock_send_str(wsock_t* ws, char* body) {
return wsock_send_raw(ws, WS_TEXT, body, strlen(body)); return wsock_send_raw(ws, WS_TEXT, body, strlen(body));
} }
int wsock_ping(wsock_t* ws, char* msg) {
if(msg == NULL)
return wsock_send_raw(ws, WS_PING, NULL, 0);
else
return wsock_send_raw(ws, WS_PING, msg, strlen(msg));
}
int wsock_is_open(wsock_t* ws) { int wsock_is_open(wsock_t* ws) {
return ws->sock >= 0; return ws->sock >= 0;
} }

View file

@ -123,6 +123,7 @@ int wsock_recv(wsock_t*, char**);
int wsock_send_raw(wsock_t*, int, char*, uint64_t); int wsock_send_raw(wsock_t*, int, char*, uint64_t);
int wsock_send(wsock_t*, char*, int); int wsock_send(wsock_t*, char*, int);
int wsock_send_str(wsock_t*, char*); int wsock_send_str(wsock_t*, char*);
int wsock_ping(wsock_t*, char*);
int wsock_is_open(wsock_t*); int wsock_is_open(wsock_t*);
void wsock_close(wsock_t*); void wsock_close(wsock_t*);