mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
68120d9b00
C reserves all identifiers beginning with an underscore for system use. But we had been mangling our autoconf identifiers with the prefix "_EVENT_" to avoid conflict with other programs. Instead, we will now use the prefix "EVENT__". With any luck, the double-underscore will still hint "here be dragons" to anybody tempted to think that event-config.h is a stable api. This is an automatically generated patch. The script that produced it was made by running this script over config.h.in: ===== #!/usr/bin/perl -w # Run this on config.h.in use strict; my %macros = (); while (<>) { if (/^# *undef +([A-Za-z0-9_]+)/) { $macros{$1} = 1; } } print "#!/usr/bin/perl -w -i -p\n\n"; for my $k (sort keys %macros) { print "s/(?<![A-Za-z0-9_])_EVENT_$k(?![A-Za-z0-9_])/EVENT__$k/g;\n"; } == And the script that it generated was then run over all .c and .h files: #!/usr/bin/perl -w -i -p s/(?<![A-Za-z0-9_])_EVENT_DISABLE_DEBUG_MODE(?![A-Za-z0-9_])/EVENT__DISABLE_DEBUG_MODE/g; s/(?<![A-Za-z0-9_])_EVENT_DISABLE_MM_REPLACEMENT(?![A-Za-z0-9_])/EVENT__DISABLE_MM_REPLACEMENT/g; s/(?<![A-Za-z0-9_])_EVENT_DISABLE_THREAD_SUPPORT(?![A-Za-z0-9_])/EVENT__DISABLE_THREAD_SUPPORT/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_ACCEPT4(?![A-Za-z0-9_])/EVENT__HAVE_ACCEPT4/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_ARC4RANDOM(?![A-Za-z0-9_])/EVENT__HAVE_ARC4RANDOM/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_ARC4RANDOM_BUF(?![A-Za-z0-9_])/EVENT__HAVE_ARC4RANDOM_BUF/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_ARPA_INET_H(?![A-Za-z0-9_])/EVENT__HAVE_ARPA_INET_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_CLOCK_GETTIME(?![A-Za-z0-9_])/EVENT__HAVE_CLOCK_GETTIME/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_DECL_CTL_KERN(?![A-Za-z0-9_])/EVENT__HAVE_DECL_CTL_KERN/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_DECL_KERN_ARND(?![A-Za-z0-9_])/EVENT__HAVE_DECL_KERN_ARND/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_DECL_KERN_RANDOM(?![A-Za-z0-9_])/EVENT__HAVE_DECL_KERN_RANDOM/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_DECL_RANDOM_UUID(?![A-Za-z0-9_])/EVENT__HAVE_DECL_RANDOM_UUID/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_DEVPOLL(?![A-Za-z0-9_])/EVENT__HAVE_DEVPOLL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_DLFCN_H(?![A-Za-z0-9_])/EVENT__HAVE_DLFCN_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_EPOLL(?![A-Za-z0-9_])/EVENT__HAVE_EPOLL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_EPOLL_CREATE1(?![A-Za-z0-9_])/EVENT__HAVE_EPOLL_CREATE1/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_EPOLL_CTL(?![A-Za-z0-9_])/EVENT__HAVE_EPOLL_CTL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_EVENTFD(?![A-Za-z0-9_])/EVENT__HAVE_EVENTFD/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_EVENT_PORTS(?![A-Za-z0-9_])/EVENT__HAVE_EVENT_PORTS/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_FCNTL(?![A-Za-z0-9_])/EVENT__HAVE_FCNTL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_FCNTL_H(?![A-Za-z0-9_])/EVENT__HAVE_FCNTL_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_FD_MASK(?![A-Za-z0-9_])/EVENT__HAVE_FD_MASK/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETADDRINFO(?![A-Za-z0-9_])/EVENT__HAVE_GETADDRINFO/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETEGID(?![A-Za-z0-9_])/EVENT__HAVE_GETEGID/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETEUID(?![A-Za-z0-9_])/EVENT__HAVE_GETEUID/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETHOSTBYNAME_R(?![A-Za-z0-9_])/EVENT__HAVE_GETHOSTBYNAME_R/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETHOSTBYNAME_R_3_ARG(?![A-Za-z0-9_])/EVENT__HAVE_GETHOSTBYNAME_R_3_ARG/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETHOSTBYNAME_R_5_ARG(?![A-Za-z0-9_])/EVENT__HAVE_GETHOSTBYNAME_R_5_ARG/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETHOSTBYNAME_R_6_ARG(?![A-Za-z0-9_])/EVENT__HAVE_GETHOSTBYNAME_R_6_ARG/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETIFADDRS(?![A-Za-z0-9_])/EVENT__HAVE_GETIFADDRS/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETNAMEINFO(?![A-Za-z0-9_])/EVENT__HAVE_GETNAMEINFO/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETPROTOBYNUMBER(?![A-Za-z0-9_])/EVENT__HAVE_GETPROTOBYNUMBER/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETSERVBYNAME(?![A-Za-z0-9_])/EVENT__HAVE_GETSERVBYNAME/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_GETTIMEOFDAY(?![A-Za-z0-9_])/EVENT__HAVE_GETTIMEOFDAY/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_IFADDRS_H(?![A-Za-z0-9_])/EVENT__HAVE_IFADDRS_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_INET_ATON(?![A-Za-z0-9_])/EVENT__HAVE_INET_ATON/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_INET_NTOP(?![A-Za-z0-9_])/EVENT__HAVE_INET_NTOP/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_INET_PTON(?![A-Za-z0-9_])/EVENT__HAVE_INET_PTON/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_INTTYPES_H(?![A-Za-z0-9_])/EVENT__HAVE_INTTYPES_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_ISSETUGID(?![A-Za-z0-9_])/EVENT__HAVE_ISSETUGID/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_KQUEUE(?![A-Za-z0-9_])/EVENT__HAVE_KQUEUE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_LIBZ(?![A-Za-z0-9_])/EVENT__HAVE_LIBZ/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_MEMORY_H(?![A-Za-z0-9_])/EVENT__HAVE_MEMORY_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_MMAP(?![A-Za-z0-9_])/EVENT__HAVE_MMAP/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_NANOSLEEP(?![A-Za-z0-9_])/EVENT__HAVE_NANOSLEEP/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_NETDB_H(?![A-Za-z0-9_])/EVENT__HAVE_NETDB_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_NETINET_IN6_H(?![A-Za-z0-9_])/EVENT__HAVE_NETINET_IN6_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_NETINET_IN_H(?![A-Za-z0-9_])/EVENT__HAVE_NETINET_IN_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_NETINET_TCP_H(?![A-Za-z0-9_])/EVENT__HAVE_NETINET_TCP_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_OPENSSL(?![A-Za-z0-9_])/EVENT__HAVE_OPENSSL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PIPE(?![A-Za-z0-9_])/EVENT__HAVE_PIPE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PIPE2(?![A-Za-z0-9_])/EVENT__HAVE_PIPE2/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_POLL(?![A-Za-z0-9_])/EVENT__HAVE_POLL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_POLL_H(?![A-Za-z0-9_])/EVENT__HAVE_POLL_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PORT_CREATE(?![A-Za-z0-9_])/EVENT__HAVE_PORT_CREATE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PORT_H(?![A-Za-z0-9_])/EVENT__HAVE_PORT_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PTHREAD(?![A-Za-z0-9_])/EVENT__HAVE_PTHREAD/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PTHREADS(?![A-Za-z0-9_])/EVENT__HAVE_PTHREADS/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_PUTENV(?![A-Za-z0-9_])/EVENT__HAVE_PUTENV/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SA_FAMILY_T(?![A-Za-z0-9_])/EVENT__HAVE_SA_FAMILY_T/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SELECT(?![A-Za-z0-9_])/EVENT__HAVE_SELECT/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SENDFILE(?![A-Za-z0-9_])/EVENT__HAVE_SENDFILE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SETENV(?![A-Za-z0-9_])/EVENT__HAVE_SETENV/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SETFD(?![A-Za-z0-9_])/EVENT__HAVE_SETFD/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SETRLIMIT(?![A-Za-z0-9_])/EVENT__HAVE_SETRLIMIT/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SIGACTION(?![A-Za-z0-9_])/EVENT__HAVE_SIGACTION/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SIGNAL(?![A-Za-z0-9_])/EVENT__HAVE_SIGNAL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SPLICE(?![A-Za-z0-9_])/EVENT__HAVE_SPLICE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STDARG_H(?![A-Za-z0-9_])/EVENT__HAVE_STDARG_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STDDEF_H(?![A-Za-z0-9_])/EVENT__HAVE_STDDEF_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STDINT_H(?![A-Za-z0-9_])/EVENT__HAVE_STDINT_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STDLIB_H(?![A-Za-z0-9_])/EVENT__HAVE_STDLIB_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRINGS_H(?![A-Za-z0-9_])/EVENT__HAVE_STRINGS_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRING_H(?![A-Za-z0-9_])/EVENT__HAVE_STRING_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRLCPY(?![A-Za-z0-9_])/EVENT__HAVE_STRLCPY/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRSEP(?![A-Za-z0-9_])/EVENT__HAVE_STRSEP/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRTOK_R(?![A-Za-z0-9_])/EVENT__HAVE_STRTOK_R/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRTOLL(?![A-Za-z0-9_])/EVENT__HAVE_STRTOLL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_ADDRINFO(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_ADDRINFO/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_IN6_ADDR(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_IN6_ADDR/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_IN6_ADDR_S6_ADDR16(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_IN6_ADDR_S6_ADDR32(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_SOCKADDR_IN6(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_SOCKADDR_IN6/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_SOCKADDR_IN_SIN_LEN(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_SOCKADDR_STORAGE(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_SOCKADDR_STORAGE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY(?![A-Za-z0-9_])/EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYSCTL(?![A-Za-z0-9_])/EVENT__HAVE_SYSCTL/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_DEVPOLL_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_DEVPOLL_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_EPOLL_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_EPOLL_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_EVENTFD_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_EVENTFD_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_EVENT_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_EVENT_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_IOCTL_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_IOCTL_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_MMAN_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_MMAN_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_PARAM_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_PARAM_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_QUEUE_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_QUEUE_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_RESOURCE_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_RESOURCE_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_SELECT_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_SELECT_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_SENDFILE_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_SENDFILE_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_SOCKET_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_SOCKET_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_STAT_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_STAT_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_SYSCTL_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_SYSCTL_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_TIME_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_TIME_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_TYPES_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_TYPES_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_UIO_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_UIO_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_SYS_WAIT_H(?![A-Za-z0-9_])/EVENT__HAVE_SYS_WAIT_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_TAILQFOREACH(?![A-Za-z0-9_])/EVENT__HAVE_TAILQFOREACH/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_TIMERADD(?![A-Za-z0-9_])/EVENT__HAVE_TIMERADD/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_TIMERCLEAR(?![A-Za-z0-9_])/EVENT__HAVE_TIMERCLEAR/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_TIMERCMP(?![A-Za-z0-9_])/EVENT__HAVE_TIMERCMP/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_TIMERISSET(?![A-Za-z0-9_])/EVENT__HAVE_TIMERISSET/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UINT16_T(?![A-Za-z0-9_])/EVENT__HAVE_UINT16_T/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UINT32_T(?![A-Za-z0-9_])/EVENT__HAVE_UINT32_T/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UINT64_T(?![A-Za-z0-9_])/EVENT__HAVE_UINT64_T/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UINT8_T(?![A-Za-z0-9_])/EVENT__HAVE_UINT8_T/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UINTPTR_T(?![A-Za-z0-9_])/EVENT__HAVE_UINTPTR_T/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UNISTD_H(?![A-Za-z0-9_])/EVENT__HAVE_UNISTD_H/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_UNSETENV(?![A-Za-z0-9_])/EVENT__HAVE_UNSETENV/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_USLEEP(?![A-Za-z0-9_])/EVENT__HAVE_USLEEP/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_VASPRINTF(?![A-Za-z0-9_])/EVENT__HAVE_VASPRINTF/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_WORKING_KQUEUE(?![A-Za-z0-9_])/EVENT__HAVE_WORKING_KQUEUE/g; s/(?<![A-Za-z0-9_])_EVENT_HAVE_ZLIB_H(?![A-Za-z0-9_])/EVENT__HAVE_ZLIB_H/g; s/(?<![A-Za-z0-9_])_EVENT_LT_OBJDIR(?![A-Za-z0-9_])/EVENT__LT_OBJDIR/g; s/(?<![A-Za-z0-9_])_EVENT_NO_MINUS_C_MINUS_O(?![A-Za-z0-9_])/EVENT__NO_MINUS_C_MINUS_O/g; s/(?<![A-Za-z0-9_])_EVENT_NUMERIC_VERSION(?![A-Za-z0-9_])/EVENT__NUMERIC_VERSION/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE(?![A-Za-z0-9_])/EVENT__PACKAGE/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE_BUGREPORT(?![A-Za-z0-9_])/EVENT__PACKAGE_BUGREPORT/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE_NAME(?![A-Za-z0-9_])/EVENT__PACKAGE_NAME/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE_STRING(?![A-Za-z0-9_])/EVENT__PACKAGE_STRING/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE_TARNAME(?![A-Za-z0-9_])/EVENT__PACKAGE_TARNAME/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE_URL(?![A-Za-z0-9_])/EVENT__PACKAGE_URL/g; s/(?<![A-Za-z0-9_])_EVENT_PACKAGE_VERSION(?![A-Za-z0-9_])/EVENT__PACKAGE_VERSION/g; s/(?<![A-Za-z0-9_])_EVENT_PTHREAD_CREATE_JOINABLE(?![A-Za-z0-9_])/EVENT__PTHREAD_CREATE_JOINABLE/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_INT(?![A-Za-z0-9_])/EVENT__SIZEOF_INT/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_LONG(?![A-Za-z0-9_])/EVENT__SIZEOF_LONG/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_LONG_LONG(?![A-Za-z0-9_])/EVENT__SIZEOF_LONG_LONG/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_OFF_T(?![A-Za-z0-9_])/EVENT__SIZEOF_OFF_T/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_PTHREAD_T(?![A-Za-z0-9_])/EVENT__SIZEOF_PTHREAD_T/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_SHORT(?![A-Za-z0-9_])/EVENT__SIZEOF_SHORT/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_SIZE_T(?![A-Za-z0-9_])/EVENT__SIZEOF_SIZE_T/g; s/(?<![A-Za-z0-9_])_EVENT_SIZEOF_VOID_P(?![A-Za-z0-9_])/EVENT__SIZEOF_VOID_P/g; s/(?<![A-Za-z0-9_])_EVENT_STDC_HEADERS(?![A-Za-z0-9_])/EVENT__STDC_HEADERS/g; s/(?<![A-Za-z0-9_])_EVENT_TIME_WITH_SYS_TIME(?![A-Za-z0-9_])/EVENT__TIME_WITH_SYS_TIME/g; s/(?<![A-Za-z0-9_])_EVENT_VERSION(?![A-Za-z0-9_])/EVENT__VERSION/g; s/(?<![A-Za-z0-9_])_EVENT__ALL_SOURCE(?![A-Za-z0-9_])/EVENT___ALL_SOURCE/g; s/(?<![A-Za-z0-9_])_EVENT__FILE_OFFSET_BITS(?![A-Za-z0-9_])/EVENT___FILE_OFFSET_BITS/g; s/(?<![A-Za-z0-9_])_EVENT__GNU_SOURCE(?![A-Za-z0-9_])/EVENT___GNU_SOURCE/g; s/(?<![A-Za-z0-9_])_EVENT__LARGE_FILES(?![A-Za-z0-9_])/EVENT___LARGE_FILES/g; s/(?<![A-Za-z0-9_])_EVENT__MINIX(?![A-Za-z0-9_])/EVENT___MINIX/g; s/(?<![A-Za-z0-9_])_EVENT__POSIX_1_SOURCE(?![A-Za-z0-9_])/EVENT___POSIX_1_SOURCE/g; s/(?<![A-Za-z0-9_])_EVENT__POSIX_PTHREAD_SEMANTICS(?![A-Za-z0-9_])/EVENT___POSIX_PTHREAD_SEMANTICS/g; s/(?<![A-Za-z0-9_])_EVENT__POSIX_SOURCE(?![A-Za-z0-9_])/EVENT___POSIX_SOURCE/g; s/(?<![A-Za-z0-9_])_EVENT__TANDEM_SOURCE(?![A-Za-z0-9_])/EVENT___TANDEM_SOURCE/g; s/(?<![A-Za-z0-9_])_EVENT___EXTENSIONS__(?![A-Za-z0-9_])/EVENT____EXTENSIONS__/g; s/(?<![A-Za-z0-9_])_EVENT___func__(?![A-Za-z0-9_])/EVENT____func__/g; s/(?<![A-Za-z0-9_])_EVENT_const(?![A-Za-z0-9_])/EVENT__const/g; s/(?<![A-Za-z0-9_])_EVENT_inline(?![A-Za-z0-9_])/EVENT__inline/g; s/(?<![A-Za-z0-9_])_EVENT_pid_t(?![A-Za-z0-9_])/EVENT__pid_t/g; s/(?<![A-Za-z0-9_])_EVENT_size_t(?![A-Za-z0-9_])/EVENT__size_t/g; s/(?<![A-Za-z0-9_])_EVENT_socklen_t(?![A-Za-z0-9_])/EVENT__socklen_t/g; s/(?<![A-Za-z0-9_])_EVENT_ssize_t(?![A-Za-z0-9_])/EVENT__ssize_t/g;
514 lines
15 KiB
C
514 lines
15 KiB
C
/*
|
|
* Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
|
|
* Copyright (c) 2002-2006 Niels Provos <provos@citi.umich.edu>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include "evconfig-private.h"
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "event2/event-config.h"
|
|
|
|
#ifdef EVENT__HAVE_SYS_TIME_H
|
|
#include <sys/time.h>
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#ifdef EVENT__HAVE_STDARG_H
|
|
#include <stdarg.h>
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#endif
|
|
|
|
#include "event2/util.h"
|
|
#include "event2/bufferevent.h"
|
|
#include "event2/buffer.h"
|
|
#include "event2/bufferevent_struct.h"
|
|
#include "event2/event.h"
|
|
#include "log-internal.h"
|
|
#include "mm-internal.h"
|
|
#include "bufferevent-internal.h"
|
|
#include "util-internal.h"
|
|
|
|
/* prototypes */
|
|
static int be_filter_enable(struct bufferevent *, short);
|
|
static int be_filter_disable(struct bufferevent *, short);
|
|
static void be_filter_destruct(struct bufferevent *);
|
|
|
|
static void be_filter_readcb(struct bufferevent *, void *);
|
|
static void be_filter_writecb(struct bufferevent *, void *);
|
|
static void be_filter_eventcb(struct bufferevent *, short, void *);
|
|
static int be_filter_flush(struct bufferevent *bufev,
|
|
short iotype, enum bufferevent_flush_mode mode);
|
|
static int be_filter_ctrl(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *);
|
|
|
|
static void bufferevent_filtered_outbuf_cb(struct evbuffer *buf,
|
|
const struct evbuffer_cb_info *info, void *arg);
|
|
|
|
struct bufferevent_filtered {
|
|
struct bufferevent_private bev;
|
|
|
|
/** The bufferevent that we read/write filtered data from/to. */
|
|
struct bufferevent *underlying;
|
|
/** A callback on our outbuf to notice when somebody adds data */
|
|
struct evbuffer_cb_entry *outbuf_cb;
|
|
/** True iff we have received an EOF callback from the underlying
|
|
* bufferevent. */
|
|
unsigned got_eof;
|
|
|
|
/** Function to free context when we're done. */
|
|
void (*free_context)(void *);
|
|
/** Input filter */
|
|
bufferevent_filter_cb process_in;
|
|
/** Output filter */
|
|
bufferevent_filter_cb process_out;
|
|
/** User-supplied argument to the filters. */
|
|
void *context;
|
|
};
|
|
|
|
const struct bufferevent_ops bufferevent_ops_filter = {
|
|
"filter",
|
|
evutil_offsetof(struct bufferevent_filtered, bev.bev),
|
|
be_filter_enable,
|
|
be_filter_disable,
|
|
be_filter_destruct,
|
|
_bufferevent_generic_adj_timeouts,
|
|
be_filter_flush,
|
|
be_filter_ctrl,
|
|
};
|
|
|
|
/* Given a bufferevent that's really the bev filter of a bufferevent_filtered,
|
|
* return that bufferevent_filtered. Returns NULL otherwise.*/
|
|
static inline struct bufferevent_filtered *
|
|
upcast(struct bufferevent *bev)
|
|
{
|
|
struct bufferevent_filtered *bev_f;
|
|
if (bev->be_ops != &bufferevent_ops_filter)
|
|
return NULL;
|
|
bev_f = (void*)( ((char*)bev) -
|
|
evutil_offsetof(struct bufferevent_filtered, bev.bev));
|
|
EVUTIL_ASSERT(bev_f->bev.bev.be_ops == &bufferevent_ops_filter);
|
|
return bev_f;
|
|
}
|
|
|
|
#define downcast(bev_f) (&(bev_f)->bev.bev)
|
|
|
|
/** Return 1 iff bevf's underlying bufferevent's output buffer is at or
|
|
* over its high watermark such that we should not write to it in a given
|
|
* flush mode. */
|
|
static int
|
|
be_underlying_writebuf_full(struct bufferevent_filtered *bevf,
|
|
enum bufferevent_flush_mode state)
|
|
{
|
|
struct bufferevent *u = bevf->underlying;
|
|
return state == BEV_NORMAL &&
|
|
u->wm_write.high &&
|
|
evbuffer_get_length(u->output) >= u->wm_write.high;
|
|
}
|
|
|
|
/** Return 1 if our input buffer is at or over its high watermark such that we
|
|
* should not write to it in a given flush mode. */
|
|
static int
|
|
be_readbuf_full(struct bufferevent_filtered *bevf,
|
|
enum bufferevent_flush_mode state)
|
|
{
|
|
struct bufferevent *bufev = downcast(bevf);
|
|
return state == BEV_NORMAL &&
|
|
bufev->wm_read.high &&
|
|
evbuffer_get_length(bufev->input) >= bufev->wm_read.high;
|
|
}
|
|
|
|
|
|
/* Filter to use when we're created with a NULL filter. */
|
|
static enum bufferevent_filter_result
|
|
be_null_filter(struct evbuffer *src, struct evbuffer *dst, ev_ssize_t lim,
|
|
enum bufferevent_flush_mode state, void *ctx)
|
|
{
|
|
(void)state;
|
|
if (evbuffer_remove_buffer(src, dst, lim) == 0)
|
|
return BEV_OK;
|
|
else
|
|
return BEV_ERROR;
|
|
}
|
|
|
|
struct bufferevent *
|
|
bufferevent_filter_new(struct bufferevent *underlying,
|
|
bufferevent_filter_cb input_filter,
|
|
bufferevent_filter_cb output_filter,
|
|
int options,
|
|
void (*free_context)(void *),
|
|
void *ctx)
|
|
{
|
|
struct bufferevent_filtered *bufev_f;
|
|
int tmp_options = options & ~BEV_OPT_THREADSAFE;
|
|
|
|
if (!underlying)
|
|
return NULL;
|
|
|
|
if (!input_filter)
|
|
input_filter = be_null_filter;
|
|
if (!output_filter)
|
|
output_filter = be_null_filter;
|
|
|
|
bufev_f = mm_calloc(1, sizeof(struct bufferevent_filtered));
|
|
if (!bufev_f)
|
|
return NULL;
|
|
|
|
if (bufferevent_init_common(&bufev_f->bev, underlying->ev_base,
|
|
&bufferevent_ops_filter, tmp_options) < 0) {
|
|
mm_free(bufev_f);
|
|
return NULL;
|
|
}
|
|
if (options & BEV_OPT_THREADSAFE) {
|
|
bufferevent_enable_locking(downcast(bufev_f), NULL);
|
|
}
|
|
|
|
bufev_f->underlying = underlying;
|
|
|
|
bufev_f->process_in = input_filter;
|
|
bufev_f->process_out = output_filter;
|
|
bufev_f->free_context = free_context;
|
|
bufev_f->context = ctx;
|
|
|
|
bufferevent_setcb(bufev_f->underlying,
|
|
be_filter_readcb, be_filter_writecb, be_filter_eventcb, bufev_f);
|
|
|
|
bufev_f->outbuf_cb = evbuffer_add_cb(downcast(bufev_f)->output,
|
|
bufferevent_filtered_outbuf_cb, bufev_f);
|
|
|
|
_bufferevent_init_generic_timeout_cbs(downcast(bufev_f));
|
|
bufferevent_incref(underlying);
|
|
|
|
bufferevent_enable(underlying, EV_READ|EV_WRITE);
|
|
bufferevent_suspend_read(underlying, BEV_SUSPEND_FILT_READ);
|
|
|
|
return downcast(bufev_f);
|
|
}
|
|
|
|
static void
|
|
be_filter_destruct(struct bufferevent *bev)
|
|
{
|
|
struct bufferevent_filtered *bevf = upcast(bev);
|
|
EVUTIL_ASSERT(bevf);
|
|
if (bevf->free_context)
|
|
bevf->free_context(bevf->context);
|
|
|
|
if (bevf->bev.options & BEV_OPT_CLOSE_ON_FREE) {
|
|
/* Yes, there is also a decref in bufferevent_decref.
|
|
* That decref corresponds to the incref when we set
|
|
* underlying for the first time. This decref is an
|
|
* extra one to remove the last reference.
|
|
*/
|
|
if (BEV_UPCAST(bevf->underlying)->refcnt < 2) {
|
|
event_warnx("BEV_OPT_CLOSE_ON_FREE set on an "
|
|
"bufferevent with too few references");
|
|
} else {
|
|
bufferevent_free(bevf->underlying);
|
|
}
|
|
} else {
|
|
if (bevf->underlying) {
|
|
if (bevf->underlying->errorcb == be_filter_eventcb)
|
|
bufferevent_setcb(bevf->underlying,
|
|
NULL, NULL, NULL, NULL);
|
|
bufferevent_unsuspend_read(bevf->underlying,
|
|
BEV_SUSPEND_FILT_READ);
|
|
}
|
|
}
|
|
|
|
_bufferevent_del_generic_timeout_cbs(bev);
|
|
}
|
|
|
|
static int
|
|
be_filter_enable(struct bufferevent *bev, short event)
|
|
{
|
|
struct bufferevent_filtered *bevf = upcast(bev);
|
|
if (event & EV_WRITE)
|
|
BEV_RESET_GENERIC_WRITE_TIMEOUT(bev);
|
|
|
|
if (event & EV_READ) {
|
|
BEV_RESET_GENERIC_READ_TIMEOUT(bev);
|
|
bufferevent_unsuspend_read(bevf->underlying,
|
|
BEV_SUSPEND_FILT_READ);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
be_filter_disable(struct bufferevent *bev, short event)
|
|
{
|
|
struct bufferevent_filtered *bevf = upcast(bev);
|
|
if (event & EV_WRITE)
|
|
BEV_DEL_GENERIC_WRITE_TIMEOUT(bev);
|
|
if (event & EV_READ) {
|
|
BEV_DEL_GENERIC_READ_TIMEOUT(bev);
|
|
bufferevent_suspend_read(bevf->underlying,
|
|
BEV_SUSPEND_FILT_READ);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static enum bufferevent_filter_result
|
|
be_filter_process_input(struct bufferevent_filtered *bevf,
|
|
enum bufferevent_flush_mode state,
|
|
int *processed_out)
|
|
{
|
|
enum bufferevent_filter_result res;
|
|
struct bufferevent *bev = downcast(bevf);
|
|
|
|
if (state == BEV_NORMAL) {
|
|
/* If we're in 'normal' mode, don't urge data on the filter
|
|
* unless we're reading data and under our high-water mark.*/
|
|
if (!(bev->enabled & EV_READ) ||
|
|
be_readbuf_full(bevf, state))
|
|
return BEV_OK;
|
|
}
|
|
|
|
do {
|
|
ev_ssize_t limit = -1;
|
|
if (state == BEV_NORMAL && bev->wm_read.high)
|
|
limit = bev->wm_read.high -
|
|
evbuffer_get_length(bev->input);
|
|
|
|
res = bevf->process_in(bevf->underlying->input,
|
|
bev->input, limit, state, bevf->context);
|
|
|
|
if (res == BEV_OK)
|
|
*processed_out = 1;
|
|
} while (res == BEV_OK &&
|
|
(bev->enabled & EV_READ) &&
|
|
evbuffer_get_length(bevf->underlying->input) &&
|
|
!be_readbuf_full(bevf, state));
|
|
|
|
if (*processed_out)
|
|
BEV_RESET_GENERIC_READ_TIMEOUT(bev);
|
|
|
|
return res;
|
|
}
|
|
|
|
|
|
static enum bufferevent_filter_result
|
|
be_filter_process_output(struct bufferevent_filtered *bevf,
|
|
enum bufferevent_flush_mode state,
|
|
int *processed_out)
|
|
{
|
|
/* Requires references and lock: might call writecb */
|
|
enum bufferevent_filter_result res = BEV_OK;
|
|
struct bufferevent *bufev = downcast(bevf);
|
|
int again = 0;
|
|
|
|
if (state == BEV_NORMAL) {
|
|
/* If we're in 'normal' mode, don't urge data on the
|
|
* filter unless we're writing data, and the underlying
|
|
* bufferevent is accepting data, and we have data to
|
|
* give the filter. If we're in 'flush' or 'finish',
|
|
* call the filter no matter what. */
|
|
if (!(bufev->enabled & EV_WRITE) ||
|
|
be_underlying_writebuf_full(bevf, state) ||
|
|
!evbuffer_get_length(bufev->output))
|
|
return BEV_OK;
|
|
}
|
|
|
|
/* disable the callback that calls this function
|
|
when the user adds to the output buffer. */
|
|
evbuffer_cb_set_flags(bufev->output, bevf->outbuf_cb, 0);
|
|
|
|
do {
|
|
int processed = 0;
|
|
again = 0;
|
|
|
|
do {
|
|
ev_ssize_t limit = -1;
|
|
if (state == BEV_NORMAL &&
|
|
bevf->underlying->wm_write.high)
|
|
limit = bevf->underlying->wm_write.high -
|
|
evbuffer_get_length(bevf->underlying->output);
|
|
|
|
res = bevf->process_out(downcast(bevf)->output,
|
|
bevf->underlying->output,
|
|
limit,
|
|
state,
|
|
bevf->context);
|
|
|
|
if (res == BEV_OK)
|
|
processed = *processed_out = 1;
|
|
} while (/* Stop if the filter wasn't successful...*/
|
|
res == BEV_OK &&
|
|
/* Or if we aren't writing any more. */
|
|
(bufev->enabled & EV_WRITE) &&
|
|
/* Of if we have nothing more to write and we are
|
|
* not flushing. */
|
|
evbuffer_get_length(bufev->output) &&
|
|
/* Or if we have filled the underlying output buffer. */
|
|
!be_underlying_writebuf_full(bevf,state));
|
|
|
|
if (processed &&
|
|
evbuffer_get_length(bufev->output) <= bufev->wm_write.low) {
|
|
/* call the write callback.*/
|
|
_bufferevent_run_writecb(bufev);
|
|
|
|
if (res == BEV_OK &&
|
|
(bufev->enabled & EV_WRITE) &&
|
|
evbuffer_get_length(bufev->output) &&
|
|
!be_underlying_writebuf_full(bevf, state)) {
|
|
again = 1;
|
|
}
|
|
}
|
|
} while (again);
|
|
|
|
/* reenable the outbuf_cb */
|
|
evbuffer_cb_set_flags(bufev->output,bevf->outbuf_cb,
|
|
EVBUFFER_CB_ENABLED);
|
|
|
|
if (*processed_out)
|
|
BEV_RESET_GENERIC_WRITE_TIMEOUT(bufev);
|
|
|
|
return res;
|
|
}
|
|
|
|
/* Called when the size of our outbuf changes. */
|
|
static void
|
|
bufferevent_filtered_outbuf_cb(struct evbuffer *buf,
|
|
const struct evbuffer_cb_info *cbinfo, void *arg)
|
|
{
|
|
struct bufferevent_filtered *bevf = arg;
|
|
struct bufferevent *bev = downcast(bevf);
|
|
|
|
if (cbinfo->n_added) {
|
|
int processed_any = 0;
|
|
/* Somebody added more data to the output buffer. Try to
|
|
* process it, if we should. */
|
|
_bufferevent_incref_and_lock(bev);
|
|
be_filter_process_output(bevf, BEV_NORMAL, &processed_any);
|
|
_bufferevent_decref_and_unlock(bev);
|
|
}
|
|
}
|
|
|
|
/* Called when the underlying socket has read. */
|
|
static void
|
|
be_filter_readcb(struct bufferevent *underlying, void *_me)
|
|
{
|
|
struct bufferevent_filtered *bevf = _me;
|
|
enum bufferevent_filter_result res;
|
|
enum bufferevent_flush_mode state;
|
|
struct bufferevent *bufev = downcast(bevf);
|
|
int processed_any = 0;
|
|
|
|
_bufferevent_incref_and_lock(bufev);
|
|
|
|
if (bevf->got_eof)
|
|
state = BEV_FINISHED;
|
|
else
|
|
state = BEV_NORMAL;
|
|
|
|
/* XXXX use return value */
|
|
res = be_filter_process_input(bevf, state, &processed_any);
|
|
(void)res;
|
|
|
|
/* XXX This should be in process_input, not here. There are
|
|
* other places that can call process-input, and they should
|
|
* force readcb calls as needed. */
|
|
if (processed_any &&
|
|
evbuffer_get_length(bufev->input) >= bufev->wm_read.low)
|
|
_bufferevent_run_readcb(bufev);
|
|
|
|
_bufferevent_decref_and_unlock(bufev);
|
|
}
|
|
|
|
/* Called when the underlying socket has drained enough that we can write to
|
|
it. */
|
|
static void
|
|
be_filter_writecb(struct bufferevent *underlying, void *_me)
|
|
{
|
|
struct bufferevent_filtered *bevf = _me;
|
|
struct bufferevent *bev = downcast(bevf);
|
|
int processed_any = 0;
|
|
|
|
_bufferevent_incref_and_lock(bev);
|
|
be_filter_process_output(bevf, BEV_NORMAL, &processed_any);
|
|
_bufferevent_decref_and_unlock(bev);
|
|
}
|
|
|
|
/* Called when the underlying socket has given us an error */
|
|
static void
|
|
be_filter_eventcb(struct bufferevent *underlying, short what, void *_me)
|
|
{
|
|
struct bufferevent_filtered *bevf = _me;
|
|
struct bufferevent *bev = downcast(bevf);
|
|
|
|
_bufferevent_incref_and_lock(bev);
|
|
/* All we can really to is tell our own eventcb. */
|
|
_bufferevent_run_eventcb(bev, what);
|
|
_bufferevent_decref_and_unlock(bev);
|
|
}
|
|
|
|
static int
|
|
be_filter_flush(struct bufferevent *bufev,
|
|
short iotype, enum bufferevent_flush_mode mode)
|
|
{
|
|
struct bufferevent_filtered *bevf = upcast(bufev);
|
|
int processed_any = 0;
|
|
EVUTIL_ASSERT(bevf);
|
|
|
|
_bufferevent_incref_and_lock(bufev);
|
|
|
|
if (iotype & EV_READ) {
|
|
be_filter_process_input(bevf, mode, &processed_any);
|
|
}
|
|
if (iotype & EV_WRITE) {
|
|
be_filter_process_output(bevf, mode, &processed_any);
|
|
}
|
|
/* XXX check the return value? */
|
|
/* XXX does this want to recursively call lower-level flushes? */
|
|
bufferevent_flush(bevf->underlying, iotype, mode);
|
|
|
|
_bufferevent_decref_and_unlock(bufev);
|
|
|
|
return processed_any;
|
|
}
|
|
|
|
static int
|
|
be_filter_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op,
|
|
union bufferevent_ctrl_data *data)
|
|
{
|
|
struct bufferevent_filtered *bevf;
|
|
switch (op) {
|
|
case BEV_CTRL_GET_UNDERLYING:
|
|
bevf = upcast(bev);
|
|
data->ptr = bevf->underlying;
|
|
return 0;
|
|
case BEV_CTRL_GET_FD:
|
|
case BEV_CTRL_SET_FD:
|
|
case BEV_CTRL_CANCEL_ALL:
|
|
default:
|
|
return -1;
|
|
}
|
|
}
|