dispatcher: implement bzip2 listener
#ifdef HAVE_GZIP
#include <zlib.h>
#endif
+#ifdef HAVE_BZIP2
+#include <bzlib.h>
+#endif
enum conntype {
LISTENER,
@@ -111,7 +114,7 @@ sockclose(void *strm)
}
#ifdef HAVE_GZIP
-/* gzip swapped socket */
+/* gzip wrapped socket */
static inline ssize_t
gzipread(void *strm, void *buf, size_t sze)
{
@@ -125,6 +128,22 @@ gzipclose(void *strm)
}
#endif
+#ifdef HAVE_BZIP2
+/* bzip2 wrapped socket */
+static inline ssize_t
+bzipread(void *strm, void *buf, size_t sze)
+{
+ return (ssize_t)BZ2_bzread((BZFILE *)strm, buf, (int)sze);
+}
+
+static inline int
+bzipclose(void *strm)
+{
+ BZ2_bzclose((BZFILE *)strm);
+ return 0;
+}
+#endif
+
/**
* Helper function to try and be helpful to the user. If errno
* indicates no new fds could be made, checks what the current max open
@@ -329,6 +348,13 @@ dispatch_addconnection(int sock, listener *lsnr)
connections[c].strmread = &gzipread;
connections[c].strmclose = &gzipclose;
}
+#endif
+#ifdef HAVE_BZIP2
+ else if (lsnr->transport == W_BZIP2) {
+ connections[c].strm = BZ2_bzdopen(sock, "r");
+ connections[c].strmread = &bzipread;
+ connections[c].strmclose = &bzipclose;
+ }
#endif
connections[c].buflen = 0;
connections[c].needmore = 0;
