commit 1470eab31452d2fab50bc4965320dab7892b2ef3 from: Omar Polo date: Tue Jul 27 08:41:42 2021 UTC fix bufferevent tls I/O on libevent2 on libevent2 we need to wrap evbuffer_add with evbuffer_freeze/evbuffer_unfreeze. Not sure exactly why, probably because we're doing some evbuffer_enable/disable/enable-again. Retain compatibility with the custom libevent1 in base on OpenBSD. commit - 4b435a4c4739dd67d3bc01e6b106969aaec431fe commit + 1470eab31452d2fab50bc4965320dab7892b2ef3 blob - 8b206a283d35811665b2746568819d0e900f694a blob + fe3986726839aa4acc7348a550215fc3d21423d5 --- compat.h +++ compat.h @@ -26,6 +26,21 @@ #include #include +#if HAVE_EVENT2 +# include +# include +# include +# include +# include +# include +# include +# include +#else +# include +# define evbuffer_freeze(a, b) /* nop */ +# define evbuffer_unfreeze(a, b) /* nop */ +#endif + #ifdef HAVE_QUEUE_H # include #else blob - 1ce2e137610fed82acd579fb91d15a1d9c59c0a9 blob + 2f11d8c301b3c0d0919551f3c356150037cef3ef --- configure.ac +++ configure.ac @@ -1,5 +1,6 @@ AC_INIT([telescope], [0.4.1-dev], [telescope@omarpolo.com], [telescope], [gemini://telescope.omarpolo.com]) AC_CONFIG_LIBOBJ_DIR(compat) +AC_CANONICAL_HOST AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) AC_PROG_CC_C99 AC_USE_SYSTEM_EXTENSIONS @@ -54,9 +55,19 @@ AC_CHECK_LIB(tls, tls_init, [], [ AC_MSG_ERROR([requires libtls]) ]) -AC_CHECK_LIB(event, event_init, [], [ - AC_MSG_ERROR([requires libevent]) -]) +case "$host_os" in + *openbsd*) + AC_CHECK_LIB([event], [event_init], [], + [AC_MSG_ERROR([requires libevent])]) + ;; + *) + PKG_CHECK_MODULES([libevent2], [libevent_core >= 2], [ + AC_DEFINE([HAVE_EVENT2], 1, [1 if using event2]) + CFLAGS="$libevent2_CFLAGS $CFLAGS" + LIBS="$libevent2_LIBS $LIBS" + ], [AC_MSG_ERROR([requires libevent])]) + ;; +esac AC_CHECK_LIB(util, imsg_init, [], [ AC_LIBOBJ(imsg) blob - 3ecdbf56350b04d3746fe0bc220158cda280467e blob + b75f88940adb4ad75a48fe23dcfda700b9cb517c --- net.c +++ net.c @@ -378,6 +378,7 @@ net_tls_readcb(int fd, short event, void *d) char buf[IBUF_READ_SIZE]; int what = EVBUFFER_READ; int howmuch = IBUF_READ_SIZE; + int res; ssize_t ret; size_t len; @@ -404,7 +405,10 @@ net_tls_readcb(int fd, short event, void *d) goto err; } - if (evbuffer_add(bufev->input, buf, len) == -1) { + evbuffer_unfreeze(bufev->input, 0); + res = evbuffer_add(bufev->input, buf, len); + evbuffer_freeze(bufev->input, 0); + if (res == -1) { what |= EVBUFFER_ERROR; goto err; } blob - b557a96f53d24ed8af96b580b6cd797fea965893 blob + 7c4ee68d7d4edd32bfa32690932f387072b825f8 --- telescope.h +++ telescope.h @@ -21,7 +21,6 @@ #include "compat.h" #include "phos/phos.h" -#include #include #define MIN(a, b) ((a) < (b) ? (a) : (b))