work commit
imagine getting paid to write this thing teehee ~
This commit is contained in:
parent
c07a007731
commit
0066350ffc
3 changed files with 35 additions and 3 deletions
24
src/main.c
24
src/main.c
|
@ -75,11 +75,35 @@ int main(int argc, char** argv) {
|
|||
sprintf(buf, "1\tMisuzu\t%s", _G.session);
|
||||
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(;;) {
|
||||
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);
|
||||
printf("%s\n", get);
|
||||
free(get);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initscr();
|
||||
raw(); noecho();
|
||||
|
|
|
@ -494,6 +494,13 @@ int wsock_send_str(wsock_t* ws, char* 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) {
|
||||
return ws->sock >= 0;
|
||||
}
|
||||
|
|
|
@ -123,6 +123,7 @@ int wsock_recv(wsock_t*, char**);
|
|||
int wsock_send_raw(wsock_t*, int, char*, uint64_t);
|
||||
int wsock_send(wsock_t*, char*, int);
|
||||
int wsock_send_str(wsock_t*, char*);
|
||||
int wsock_ping(wsock_t*, char*);
|
||||
|
||||
int wsock_is_open(wsock_t*);
|
||||
void wsock_close(wsock_t*);
|
||||
|
|
Loading…
Reference in a new issue