Port to MinGW
This commit is contained in:
parent
4ec44cea54
commit
b0bd0942bf
7 changed files with 60 additions and 19 deletions
|
@ -187,13 +187,23 @@ if (EVHTP_DISABLE_SSL)
|
|||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEVHTP_DISABLE_SSL")
|
||||
endif()
|
||||
|
||||
find_library (LIB_DL dl)
|
||||
set (SYS_LIBS ${LIB_DL})
|
||||
|
||||
if (NOT APPLE)
|
||||
find_library (LIB_RT rt)
|
||||
set (SYS_LIBS ${SYS_LIBS} ${LIB_RT})
|
||||
endif()
|
||||
|
||||
IF (WIN32)
|
||||
ADD_DEFINITIONS(-DWIN32)
|
||||
ADD_DEFINITIONS(-march=i486)
|
||||
find_library (LIB_WS32 ws2_32)
|
||||
set (SYS_LIBS ${SYS_LIBS} ${LIB_WS32})
|
||||
ELSE ()
|
||||
find_library (LIB_DL dl)
|
||||
set (SYS_LIBS ${LIB_DL})
|
||||
|
||||
if (NOT APPLE)
|
||||
find_library (LIB_RT rt)
|
||||
set (SYS_LIBS ${SYS_LIBS} ${LIB_RT})
|
||||
endif()
|
||||
|
||||
ENDIF (WIN32)
|
||||
|
||||
if (EVHTP_BUILD_SHARED)
|
||||
add_library(libevhtpShared SHARED ${LIBEVHTP_SOURCES} ${ONIG_SOURCES})
|
||||
|
@ -241,3 +251,8 @@ endif()
|
|||
install (FILES evhtp.h DESTINATION include)
|
||||
install (FILES htparse/htparse.h DESTINATION include)
|
||||
install (FILES evthr/evthr.h DESTINATION include)
|
||||
|
||||
IF (WIN32)
|
||||
install (FILES compat/sys/queue.h DESTINATION include/sys)
|
||||
install (FILES oniguruma/onigposix.h DESTINATION include)
|
||||
ENDIF (WIN32)
|
||||
|
|
|
@ -91,3 +91,10 @@ This example uses redis, mainly because most people who have asked me "is evhtp
|
|||
thread-safe" were attempting to *other things* before sending a response to a
|
||||
request. And on more than one occasion, those *other things* were communicating
|
||||
with redis.
|
||||
|
||||
|
||||
## For Windows MinGW
|
||||
|
||||
cmake -G "MinGW Makefiles" -DCMAKE_INCLUDE_PATH=/mingw/include -DCMAKE_LIBRARY_PATH=/mingw/lib -DCMAKE_INSTALL_PREFIX=/mingw .
|
||||
|
||||
mingw32-make.exe
|
||||
|
|
30
evhtp.c
30
evhtp.c
|
@ -6,13 +6,20 @@
|
|||
#include <signal.h>
|
||||
#include <strings.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/socket.h>
|
||||
#ifndef WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#define WINVER 0x0501
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#ifndef NO_SYS_UN
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <sys/tree.h>
|
||||
|
||||
#include "evhtp.h"
|
||||
|
@ -33,7 +40,7 @@ static int _evhtp_request_parser_headers_start(htparser * p);
|
|||
|
||||
static void _evhtp_connection_readcb(evbev_t * bev, void * arg);
|
||||
|
||||
static evhtp_connection_t * _evhtp_connection_new(evhtp_t * htp, int sock, evhtp_type type);
|
||||
static evhtp_connection_t * _evhtp_connection_new(evhtp_t * htp, evutil_socket_t sock, evhtp_type type);
|
||||
|
||||
static evhtp_uri_t * _evhtp_uri_new(void);
|
||||
static void _evhtp_uri_free(evhtp_uri_t * uri);
|
||||
|
@ -1339,8 +1346,11 @@ _evhtp_create_reply(evhtp_request_t * request, evhtp_res code) {
|
|||
if (!evhtp_header_find(request->headers_out, "Content-Length")) {
|
||||
char lstr[128];
|
||||
int sres;
|
||||
|
||||
#ifndef WIN32
|
||||
sres = snprintf(lstr, sizeof(lstr), "%zu",
|
||||
#else
|
||||
sres = snprintf(lstr, sizeof(lstr), "%u",
|
||||
#endif
|
||||
evbuffer_get_length(request->buffer_out));
|
||||
|
||||
if (sres >= sizeof(lstr) || sres < 0) {
|
||||
|
@ -1674,7 +1684,7 @@ _evhtp_default_request_cb(evhtp_request_t * request, void * arg) {
|
|||
}
|
||||
|
||||
static evhtp_connection_t *
|
||||
_evhtp_connection_new(evhtp_t * htp, int sock, evhtp_type type) {
|
||||
_evhtp_connection_new(evhtp_t * htp, evutil_socket_t sock, evhtp_type type) {
|
||||
evhtp_connection_t * connection;
|
||||
htp_type ptype;
|
||||
|
||||
|
@ -1800,7 +1810,11 @@ _evhtp_accept_cb(evserv_t * serv, int fd, struct sockaddr * s, int sl, void * ar
|
|||
#ifndef EVHTP_DISABLE_EVTHR
|
||||
static unsigned long
|
||||
_evhtp_ssl_get_thread_id(void) {
|
||||
#ifndef WIN32
|
||||
return (unsigned long)pthread_self();
|
||||
#else
|
||||
return (unsigned long)(pthread_self().p);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2681,7 +2695,9 @@ evhtp_unbind_socket(evhtp_t * htp) {
|
|||
|
||||
int
|
||||
evhtp_bind_sockaddr(evhtp_t * htp, struct sockaddr * sa, size_t sin_len, int backlog) {
|
||||
#ifndef WIN32
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
htp->server = evconnlistener_new_bind(htp->evbase, _evhtp_accept_cb, (void *)htp,
|
||||
LEV_OPT_THREADSAFE | LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE,
|
||||
|
|
2
evhtp.h
2
evhtp.h
|
@ -426,7 +426,7 @@ struct evhtp_connection_s {
|
|||
struct sockaddr * saddr;
|
||||
struct timeval recv_timeo; /**< conn read timeouts (overrides global) */
|
||||
struct timeval send_timeo; /**< conn write timeouts (overrides global) */
|
||||
int sock;
|
||||
evutil_socket_t sock;
|
||||
uint8_t error;
|
||||
uint8_t owner; /**< set to 1 if this structure owns the bufferevent */
|
||||
uint8_t vhost_via_sni; /**< set to 1 if the vhost was found via SSL SNI */
|
||||
|
|
|
@ -7,9 +7,12 @@
|
|||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifndef WIN32
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/queue.h>
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
@ -89,7 +92,7 @@ evthr_set_max_backlog(evthr_t * evthr, int max) {
|
|||
}
|
||||
|
||||
static void
|
||||
_evthr_read_cmd(int sock, short __unused__ which, void * args) {
|
||||
_evthr_read_cmd(evutil_socket_t sock, short __unused__ which, void * args) {
|
||||
evthr_t * thread;
|
||||
evthr_cmd_t cmd;
|
||||
ssize_t recvd;
|
||||
|
@ -264,7 +267,7 @@ evthr_new(evthr_init_cb init_cb, void * args) {
|
|||
evthr_t * thread;
|
||||
int fds[2];
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
|
||||
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
2
test.c
2
test.c
|
@ -30,7 +30,7 @@ struct pauser {
|
|||
|
||||
/* pause testing */
|
||||
static void
|
||||
resume_request_timer(int sock, short which, void * arg) {
|
||||
resume_request_timer(evutil_socket_t sock, short which, void * arg) {
|
||||
struct pauser * pause = (struct pauser *)arg;
|
||||
|
||||
printf("resume_request_timer(%p) timer_ev = %p\n", pause->request->conn, pause->timer_ev);
|
||||
|
|
|
@ -112,10 +112,10 @@ main(int argc, char ** argv) {
|
|||
#endif
|
||||
|
||||
evhtp_use_threads(evhtp, init_thread_cb, 8, NULL);
|
||||
|
||||
#ifndef WIN32
|
||||
ev_sigterm = evsignal_new(evbase, SIGTERM, sigterm_cb, evbase);
|
||||
evsignal_add(ev_sigterm, NULL);
|
||||
|
||||
#endif
|
||||
evhtp_bind_socket(evhtp, "0.0.0.0", 8081, 1024);
|
||||
event_base_loop(evbase, 0);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue