From 89ac3679822287ecf67d32e50005fc7de99d8beb Mon Sep 17 00:00:00 2001 From: Tobias Girstmair Date: Sat, 27 Apr 2024 12:43:40 +0200 Subject: [PATCH] implement TLS_WANT_POLL{IN,OUT} we always listen for POLLIN events, so we don't need to explicitly check for it. not sure if this implementation is correct. modeled after https://github.com/openbsd/src/blob/master/usr.bin/nc/netcat.c --- ircpipe.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ircpipe.c b/ircpipe.c index 89be7ea..61a0ea3 100644 --- a/ircpipe.c +++ b/ircpipe.c @@ -222,6 +222,7 @@ int irc_poll(const sock_t sock, const int infd, const int outfd) { if (fds[IRC].revents & POLLIN) { n = READ(sock, buf, BUFSIZ); if (n == 0) return -1; /* server closed connection */ + fds[IRC].events = POLLIN | (n==TLS_WANT_POLLOUT?POLLOUT:0); write(outfd, buf, n); irc_answer(sock, buf, NO_CMD); /* update last-msg-rcvd here */ @@ -229,8 +230,14 @@ int irc_poll(const sock_t sock, const int infd, const int outfd) { if (fds[CLI].revents & POLLIN) { n = read(infd, buf, BUFSIZ); if (n == 0) return 0; /* we closed connection */ - WRITE(sock, buf, n); + n = WRITE(sock, buf, n); + fds[IRC].events = POLLIN | (n==TLS_WANT_POLLOUT?POLLOUT:0); } + if (fds[IRC].revents & POLLOUT) { /* needed for TLS only */ + n = WRITE(sock, buf, n); + fds[IRC].events = POLLIN | (n==TLS_WANT_POLLOUT?POLLOUT:0); + } + /* TODO: if read/write on either irc or cli returns -1 and errno is EAGAIN or EINTR, retry. otherwise, return with error */ /* send ping here */ /* -- 2.39.3