diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-06-19 18:50:55 +0200 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-06-19 18:51:12 +0200 |
commit | 9720c7efddf2d7595c9a0b021bc5fc6327c22bcf (patch) | |
tree | 0c64d493c2a053638607f34793797a1c15893b75 /include | |
parent | 6490c179e7f789a9efb876fa0bdfc195dc374dc5 (diff) |
client: send hi to server
Signed-off-by: Lizzy Fleckenstein <lizzy@vlhl.dev>
Diffstat (limited to 'include')
-rw-r--r-- | include/net.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/include/net.h b/include/net.h index fcb12a4..ce2eb02 100644 --- a/include/net.h +++ b/include/net.h @@ -5,13 +5,16 @@ #ifndef NET_H #define NET_H +#include <stdio.h> #include <stdint.h> #include <stdbool.h> #include <stddef.h> +#include <stdlib.h> #include <poll.h> #include <fcntl.h> - #include "str.h" +#include "ser.h" +#include "content.h" #define SET_NONBLOCK(X) fcntl((X), F_SETFL, fcntl((X), F_GETFL, 0) | O_NONBLOCK) @@ -23,6 +26,7 @@ typedef uint32_t pkt_header; typedef struct { int socket; bool disco; + str *name; struct { bool header; size_t len; @@ -37,12 +41,20 @@ typedef struct { } out; } peer; -void invalid_pkt(str from, str pkt); +#define SEND_PKT(CONN, TYPE, ...) \ + { strbuf pkt = NILSBUF; \ + ser_pkt_type(&pkt, TYPE); \ + __VA_ARGS__ \ + if (!peer_send(&(CONN), pkt.data, pkt.len)) \ + fprintf(stderr, "failed to send " #TYPE " to %*s\n", PSTR(*(CONN).name)); \ + free(pkt.data); } + +void invalid_pkt(peer *p, str pkt); int socket_create(const char *host, const char *port, bool server); int socket_accept(int accept_fd); -void peer_init(peer *p, int socket); +void peer_init(peer *p, int socket, str *name); void peer_free(peer *p); struct pollfd peer_prepare(peer *p); str peer_recv(peer *p, struct pollfd pfd); |