diff options
author | Test_User <hax@andrewyu.org> | 2023-08-25 17:36:07 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2023-08-25 17:36:07 -0400 |
commit | 8fb7f0bc0d3300637c2db8499efbf193ffebf28f (patch) | |
tree | 11867c21110d03d04a54e94ce3c6e06920749581 /network.h | |
parent | 39cd7bb66c466ac504db3676ea196ee24540ab2c (diff) | |
download | c_coupserv-8fb7f0bc0d3300637c2db8499efbf193ffebf28f.tar.gz c_coupserv-8fb7f0bc0d3300637c2db8499efbf193ffebf28f.zip |
No more TLS
Diffstat (limited to 'network.h')
-rw-r--r-- | network.h | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -31,6 +31,9 @@ #include <netinet/in.h> #include <pthread.h> #include <limits.h> +#include <errno.h> + +#include <stdio.h> #include "types.h" #include "table.h" @@ -87,6 +90,8 @@ extern struct table user_list; extern pthread_mutex_t send_lock; +extern int server_fd; + extern int client_fd; extern int client_listen_fd; extern struct string client_nick; @@ -112,6 +117,32 @@ extern ssize_t SENDCLIENT(struct string msg); #define SENDCLIENT(x) write(client_fd, x.data, x.len) #endif +#if LOGALL +extern ssize_t SEND(struct string msg); +#else +#define SEND(x) write(server_fd, x.data, x.len) +#endif + +inline size_t RECV(char *buf, size_t buflen, char *timeout) { + ssize_t len; + do { + len = recv(server_fd, buf, buflen, 0); + } while (len == -1 && errno == EINTR); + + if (len == -1) + fprintf(stderr, "errno: %d\n", errno); + + if (len == -1) + *timeout = (errno == EAGAIN || errno == EWOULDBLOCK); + else + *timeout = 0; + + if (len < 0) + return 0; + else + return (size_t)len; +} + extern int privmsg(struct string source, struct string target, size_t num_message_parts, struct string message[num_message_parts]); extern int add_local_client(struct string uid, struct string nick_arg, struct string vhost_arg, struct string ident_arg, struct string realname_arg, time_t timestamp, char fake_cert); extern int remove_user(struct string uid, struct string reason); |