commit af9b96a013ee85729431044a30b2b8944c844670 from: Omar Polo date: Tue Jul 27 18:36:29 2021 UTC fix bufferevent tls I/O on libevent2 port of telescope commit 1470eab31452d2fab50bc4965320dab7892b2ef3 original commit message: > 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. commit - b16313508c7b4527c1422490c852781eadd59db8 commit + af9b96a013ee85729431044a30b2b8944c844670 blob - 2a597fe2fa46d79a76c546f5a2a62cfb13b48081 blob + eb4ddeb427f608fe75f1dfd2522a8ce16cd4eb52 --- compat.h +++ compat.h @@ -28,6 +28,21 @@ #define ATTR_DEAD __attribute__((noreturn)) +#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 - 24e46208501b85221f5311120defe4c6c003ae98 blob + 36e3015aa62479385c3db94cfae227eee4695fae --- configure.ac +++ configure.ac @@ -1,10 +1,13 @@ AC_INIT([kamid], [0.1], [kamid@omarpolo.com], [kamid], [gemini://kamid.omarpolo.com]) AC_CONFIG_LIBOBJ_DIR(compat) +AC_CANONICAL_HOST AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) AC_PROG_CC AC_USE_SYSTEM_EXTENSIONS AC_PROG_YACC +PKG_PROG_PKG_CONFIG + # Some functions can be in libbsd. Thanks to lldpb for the inspiration :) AC_ARG_WITH([libbsd], AS_HELP_STRING([--with-libbsd], [Use libbsd @<:@default=auto@:>@]), @@ -99,9 +102,15 @@ AC_CHECK_LIB(tls, tls_init, [], [ AC_MSG_ERROR([requires libtls]) ]) -AC_CHECK_LIB(event, event_init, [], [ - AC_MSG_ERROR([requires libevent]) -]) +AS_CASE([$host_os], + [*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])])]) AC_CHECK_LIB(util, imsg_init, [], [ AC_LIBOBJ(imsg) blob - f3879b8a29c0d8518efde405bc6ee9a8b9cfd726 blob + e48f3c87ed66bcaea9e5a4baad4d6d9575f425dc --- kamid.h +++ kamid.h @@ -19,7 +19,6 @@ #include "compat.h" -#include #include #include #include blob - 8cb7468d5dd547a2c6ed4125341f38cc40f479b4 blob + e5357e9f01878461221fc4ec50a79c7fc00f7d2a --- kamirepl.c +++ kamirepl.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include blob - 6cef1a88ffb45a708d00e8e170743aa19eff55f0 blob + 448a30005ad02587f71182494b6051d60a744763 --- listener.c +++ listener.c @@ -748,6 +748,7 @@ client_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; @@ -774,7 +775,10 @@ client_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; }