mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 12:28:19 -04:00
r16731@catbus: nickm | 2007-11-25 16:52:53 -0500
Replace all fds on non-unix-specific APIs with evutil_socket_t, which is int on unix and intptr_t on win32. svn:r552
This commit is contained in:
parent
cbf9cfdf45
commit
1120f04f3e
@ -12,6 +12,8 @@ Changes in current version:
|
|||||||
o The kqueue implementation now restores original signal handlers correctly when its signal events are removed.
|
o The kqueue implementation now restores original signal handlers correctly when its signal events are removed.
|
||||||
o Check return value of event_add in signal.c
|
o Check return value of event_add in signal.c
|
||||||
o Add a more powerful evbuffer_readln as a replacement for evbuffer_readline. The new function handles more newline styles, and is more useful with buffers that may contain a nul characters.
|
o Add a more powerful evbuffer_readln as a replacement for evbuffer_readline. The new function handles more newline styles, and is more useful with buffers that may contain a nul characters.
|
||||||
|
o Do not mangle socket handles on 64-bit windows.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Changes in 1.4.0:
|
Changes in 1.4.0:
|
||||||
|
4
buffer.c
4
buffer.c
@ -399,7 +399,7 @@ evbuffer_drain(struct evbuffer *buf, size_t len)
|
|||||||
#define EVBUFFER_MAX_READ 4096
|
#define EVBUFFER_MAX_READ 4096
|
||||||
|
|
||||||
int
|
int
|
||||||
evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
|
evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||||
{
|
{
|
||||||
u_char *p;
|
u_char *p;
|
||||||
size_t oldoff = buf->off;
|
size_t oldoff = buf->off;
|
||||||
@ -457,7 +457,7 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
evbuffer_write(struct evbuffer *buffer, int fd)
|
evbuffer_write(struct evbuffer *buffer, evutil_socket_t fd)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ bufferevent_read_pressure_cb(struct evbuffer *buf, size_t old, size_t now,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bufferevent_readcb(int fd, short event, void *arg)
|
bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
|
||||||
{
|
{
|
||||||
struct bufferevent *bufev = arg;
|
struct bufferevent *bufev = arg;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@ -155,7 +155,7 @@ bufferevent_readcb(int fd, short event, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bufferevent_writecb(int fd, short event, void *arg)
|
bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
|
||||||
{
|
{
|
||||||
struct bufferevent *bufev = arg;
|
struct bufferevent *bufev = arg;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@ -225,7 +225,7 @@ bufferevent_writecb(int fd, short event, void *arg)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct bufferevent *
|
struct bufferevent *
|
||||||
bufferevent_new(int fd, evbuffercb readcb, evbuffercb writecb,
|
bufferevent_new(evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb,
|
||||||
everrorcb errorcb, void *cbarg)
|
everrorcb errorcb, void *cbarg)
|
||||||
{
|
{
|
||||||
struct bufferevent *bufev;
|
struct bufferevent *bufev;
|
||||||
|
18
evdns.c
18
evdns.c
@ -216,7 +216,7 @@ struct reply {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct nameserver {
|
struct nameserver {
|
||||||
int socket; /* a connected UDP socket */
|
evutil_socket_t socket; /* a connected UDP socket */
|
||||||
u32 address;
|
u32 address;
|
||||||
int failed_times; /* number of times which we have given this server a chance */
|
int failed_times; /* number of times which we have given this server a chance */
|
||||||
int timedout; /* number of times in a row a request has timed out */
|
int timedout; /* number of times in a row a request has timed out */
|
||||||
@ -237,7 +237,7 @@ static struct nameserver *server_head = NULL;
|
|||||||
/* Represents a local port where we're listening for DNS requests. Right now, */
|
/* Represents a local port where we're listening for DNS requests. Right now, */
|
||||||
/* only UDP is supported. */
|
/* only UDP is supported. */
|
||||||
struct evdns_server_port {
|
struct evdns_server_port {
|
||||||
int socket; /* socket we use to read queries and write replies. */
|
evutil_socket_t socket; /* socket we use to read queries and write replies. */
|
||||||
int refcnt; /* reference count. */
|
int refcnt; /* reference count. */
|
||||||
char choked; /* Are we currently blocked from writing? */
|
char choked; /* Are we currently blocked from writing? */
|
||||||
char closing; /* Are we trying to close this port, pending writes? */
|
char closing; /* Are we trying to close this port, pending writes? */
|
||||||
@ -325,7 +325,7 @@ static const int global_nameserver_timeouts_length = sizeof(global_nameserver_ti
|
|||||||
|
|
||||||
static struct nameserver *nameserver_pick(void);
|
static struct nameserver *nameserver_pick(void);
|
||||||
static void evdns_request_insert(struct request *req, struct request **head);
|
static void evdns_request_insert(struct request *req, struct request **head);
|
||||||
static void nameserver_ready_callback(int fd, short events, void *arg);
|
static void nameserver_ready_callback(evutil_socket_t fd, short events, void *arg);
|
||||||
static int evdns_transmit(void);
|
static int evdns_transmit(void);
|
||||||
static int evdns_request_transmit(struct request *req);
|
static int evdns_request_transmit(struct request *req);
|
||||||
static void nameserver_send_probe(struct nameserver *const ns);
|
static void nameserver_send_probe(struct nameserver *const ns);
|
||||||
@ -340,13 +340,13 @@ static void request_submit(struct request *const req);
|
|||||||
static int server_request_free(struct server_request *req);
|
static int server_request_free(struct server_request *req);
|
||||||
static void server_request_free_answers(struct server_request *req);
|
static void server_request_free_answers(struct server_request *req);
|
||||||
static void server_port_free(struct evdns_server_port *port);
|
static void server_port_free(struct evdns_server_port *port);
|
||||||
static void server_port_ready_callback(int fd, short events, void *arg);
|
static void server_port_ready_callback(evutil_socket_t fd, short events, void *arg);
|
||||||
|
|
||||||
static int strtoint(const char *const str);
|
static int strtoint(const char *const str);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
static int
|
static int
|
||||||
last_error(int sock)
|
last_error(evutil_socket_t sock)
|
||||||
{
|
{
|
||||||
int optval, optvallen=sizeof(optval);
|
int optval, optvallen=sizeof(optval);
|
||||||
int err = WSAGetLastError();
|
int err = WSAGetLastError();
|
||||||
@ -458,7 +458,7 @@ request_find_from_trans_id(u16 trans_id) {
|
|||||||
/* a libevent callback function which is called when a nameserver */
|
/* a libevent callback function which is called when a nameserver */
|
||||||
/* has gone down and we want to test if it has came back to life yet */
|
/* has gone down and we want to test if it has came back to life yet */
|
||||||
static void
|
static void
|
||||||
nameserver_prod_callback(int fd, short events, void *arg) {
|
nameserver_prod_callback(evutil_socket_t fd, short events, void *arg) {
|
||||||
struct nameserver *const ns = (struct nameserver *) arg;
|
struct nameserver *const ns = (struct nameserver *) arg;
|
||||||
(void)fd;
|
(void)fd;
|
||||||
(void)events;
|
(void)events;
|
||||||
@ -1237,7 +1237,7 @@ nameserver_write_waiting(struct nameserver *ns, char waiting) {
|
|||||||
/* a callback function. Called by libevent when the kernel says that */
|
/* a callback function. Called by libevent when the kernel says that */
|
||||||
/* a nameserver socket is ready for writing or reading */
|
/* a nameserver socket is ready for writing or reading */
|
||||||
static void
|
static void
|
||||||
nameserver_ready_callback(int fd, short events, void *arg) {
|
nameserver_ready_callback(evutil_socket_t fd, short events, void *arg) {
|
||||||
struct nameserver *ns = (struct nameserver *) arg;
|
struct nameserver *ns = (struct nameserver *) arg;
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
|
||||||
@ -1255,7 +1255,7 @@ nameserver_ready_callback(int fd, short events, void *arg) {
|
|||||||
/* a callback function. Called by libevent when the kernel says that */
|
/* a callback function. Called by libevent when the kernel says that */
|
||||||
/* a server socket is ready for writing or reading. */
|
/* a server socket is ready for writing or reading. */
|
||||||
static void
|
static void
|
||||||
server_port_ready_callback(int fd, short events, void *arg) {
|
server_port_ready_callback(evutil_socket_t fd, short events, void *arg) {
|
||||||
struct evdns_server_port *port = (struct evdns_server_port *) arg;
|
struct evdns_server_port *port = (struct evdns_server_port *) arg;
|
||||||
(void) fd;
|
(void) fd;
|
||||||
|
|
||||||
@ -1852,7 +1852,7 @@ evdns_server_request_get_requesting_addr(struct evdns_server_request *_req, stru
|
|||||||
/* this is a libevent callback function which is called when a request */
|
/* this is a libevent callback function which is called when a request */
|
||||||
/* has timed out. */
|
/* has timed out. */
|
||||||
static void
|
static void
|
||||||
evdns_request_timeout_callback(int fd, short events, void *arg) {
|
evdns_request_timeout_callback(evutil_socket_t fd, short events, void *arg) {
|
||||||
struct request *const req = (struct request *) arg;
|
struct request *const req = (struct request *) arg;
|
||||||
(void) fd;
|
(void) fd;
|
||||||
(void) events;
|
(void) events;
|
||||||
|
20
event.c
20
event.c
@ -381,7 +381,7 @@ event_base_dispatch(struct event_base *event_base)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
event_loopexit_cb(int fd, short what, void *arg)
|
event_loopexit_cb(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct event_base *base = arg;
|
struct event_base *base = arg;
|
||||||
base->event_gotterm = 1;
|
base->event_gotterm = 1;
|
||||||
@ -513,14 +513,14 @@ event_base_loop(struct event_base *base, int flags)
|
|||||||
struct event_once {
|
struct event_once {
|
||||||
struct event ev;
|
struct event ev;
|
||||||
|
|
||||||
void (*cb)(int, short, void *);
|
void (*cb)(evutil_socket_t, short, void *);
|
||||||
void *arg;
|
void *arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* One-time callback, it deletes itself */
|
/* One-time callback, it deletes itself */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
event_once_cb(int fd, short events, void *arg)
|
event_once_cb(evutil_socket_t fd, short events, void *arg)
|
||||||
{
|
{
|
||||||
struct event_once *eonce = arg;
|
struct event_once *eonce = arg;
|
||||||
|
|
||||||
@ -530,16 +530,18 @@ event_once_cb(int fd, short events, void *arg)
|
|||||||
|
|
||||||
/* not threadsafe, event scheduled once. */
|
/* not threadsafe, event scheduled once. */
|
||||||
int
|
int
|
||||||
event_once(int fd, short events,
|
event_once(evutil_socket_t fd, short events,
|
||||||
void (*callback)(int, short, void *), void *arg, struct timeval *tv)
|
void (*callback)(evutil_socket_t, short, void *),
|
||||||
|
void *arg, struct timeval *tv)
|
||||||
{
|
{
|
||||||
return event_base_once(current_base, fd, events, callback, arg, tv);
|
return event_base_once(current_base, fd, events, callback, arg, tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Schedules an event once */
|
/* Schedules an event once */
|
||||||
int
|
int
|
||||||
event_base_once(struct event_base *base, int fd, short events,
|
event_base_once(struct event_base *base, evutil_socket_t fd, short events,
|
||||||
void (*callback)(int, short, void *), void *arg, struct timeval *tv)
|
void (*callback)(evutil_socket_t, short, void *),
|
||||||
|
void *arg, struct timeval *tv)
|
||||||
{
|
{
|
||||||
struct event_once *eonce;
|
struct event_once *eonce;
|
||||||
struct timeval etv;
|
struct timeval etv;
|
||||||
@ -584,8 +586,8 @@ event_base_once(struct event_base *base, int fd, short events,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
event_set(struct event *ev, int fd, short events,
|
event_set(struct event *ev, evutil_socket_t fd, short events,
|
||||||
void (*callback)(int, short, void *), void *arg)
|
void (*callback)(evutil_socket_t, short, void *), void *arg)
|
||||||
{
|
{
|
||||||
/* Take the current base - caller needs to set the real base later */
|
/* Take the current base - caller needs to set the real base later */
|
||||||
ev->ev_base = current_base;
|
ev->ev_base = current_base;
|
||||||
|
23
event.h
23
event.h
@ -217,7 +217,7 @@ struct event {
|
|||||||
|
|
||||||
struct event_base *ev_base;
|
struct event_base *ev_base;
|
||||||
|
|
||||||
int ev_fd;
|
evutil_socket_t ev_fd;
|
||||||
short ev_events;
|
short ev_events;
|
||||||
short ev_ncalls;
|
short ev_ncalls;
|
||||||
short *ev_pncalls; /* Allows deletes in callback */
|
short *ev_pncalls; /* Allows deletes in callback */
|
||||||
@ -226,7 +226,7 @@ struct event {
|
|||||||
|
|
||||||
int ev_pri; /* smaller numbers are higher priority */
|
int ev_pri; /* smaller numbers are higher priority */
|
||||||
|
|
||||||
void (*ev_callback)(int, short, void *arg);
|
void (*ev_callback)(evutil_socket_t, short, void *arg);
|
||||||
void *ev_arg;
|
void *ev_arg;
|
||||||
|
|
||||||
int ev_res; /* result passed to event callback */
|
int ev_res; /* result passed to event callback */
|
||||||
@ -528,7 +528,7 @@ int event_base_loopbreak(struct event_base *);
|
|||||||
@see event_add(), event_del(), event_once()
|
@see event_add(), event_del(), event_once()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void event_set(struct event *, int, short, void (*)(int, short, void *), void *);
|
void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Schedule a one-time event to occur.
|
Schedule a one-time event to occur.
|
||||||
@ -548,7 +548,7 @@ void event_set(struct event *, int, short, void (*)(int, short, void *), void *)
|
|||||||
@see event_set()
|
@see event_set()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
int event_once(int, short, void (*)(int, short, void *), void *, struct timeval *);
|
int event_once(evutil_socket_t , short, void (*)(evutil_socket_t, short, void *), void *, struct timeval *);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -569,7 +569,7 @@ int event_once(int, short, void (*)(int, short, void *), void *, struct timeval
|
|||||||
@return 0 if successful, or -1 if an error occurred
|
@return 0 if successful, or -1 if an error occurred
|
||||||
@see event_once()
|
@see event_once()
|
||||||
*/
|
*/
|
||||||
int event_base_once(struct event_base *, int, short, void (*)(int, short, void *), void *, struct timeval *);
|
int event_base_once(struct event_base *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *, struct timeval *);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -606,6 +606,13 @@ int event_add(struct event *, struct timeval *);
|
|||||||
*/
|
*/
|
||||||
int event_del(struct event *);
|
int event_del(struct event *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Make an event active.
|
||||||
|
|
||||||
|
@param ev an event to make active.
|
||||||
|
@param res a set of flags to pass to the event's callback.
|
||||||
|
@param ncalls
|
||||||
|
**/
|
||||||
void event_active(struct event *, int, short);
|
void event_active(struct event *, int, short);
|
||||||
|
|
||||||
|
|
||||||
@ -789,7 +796,7 @@ struct bufferevent {
|
|||||||
error occurred
|
error occurred
|
||||||
@see bufferevent_base_set(), bufferevent_free()
|
@see bufferevent_base_set(), bufferevent_free()
|
||||||
*/
|
*/
|
||||||
struct bufferevent *bufferevent_new(int fd,
|
struct bufferevent *bufferevent_new(evutil_socket_t fd,
|
||||||
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
|
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
|
||||||
|
|
||||||
|
|
||||||
@ -1042,7 +1049,7 @@ void evbuffer_drain(struct evbuffer *, size_t);
|
|||||||
@return the number of bytes written, or -1 if an error occurred
|
@return the number of bytes written, or -1 if an error occurred
|
||||||
@see evbuffer_read()
|
@see evbuffer_read()
|
||||||
*/
|
*/
|
||||||
int evbuffer_write(struct evbuffer *, int);
|
int evbuffer_write(struct evbuffer *, evutil_socket_t);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1054,7 +1061,7 @@ int evbuffer_write(struct evbuffer *, int);
|
|||||||
@return the number of bytes read, or -1 if an error occurred
|
@return the number of bytes read, or -1 if an error occurred
|
||||||
@see evbuffer_write()
|
@see evbuffer_write()
|
||||||
*/
|
*/
|
||||||
int evbuffer_read(struct evbuffer *, int, int);
|
int evbuffer_read(struct evbuffer *, evutil_socket_t, int);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
2
evhttp.h
2
evhttp.h
@ -80,7 +80,7 @@ struct evhttp *evhttp_new(struct event_base *base);
|
|||||||
*
|
*
|
||||||
* @param address a string containing the IP address to listen(2) on
|
* @param address a string containing the IP address to listen(2) on
|
||||||
* @param port the port number to listen on
|
* @param port the port number to listen on
|
||||||
* @return a newly allocated evhttp struct
|
* @return 0 on success, -1 on failure.
|
||||||
* @see evhttp_free()
|
* @see evhttp_free()
|
||||||
*/
|
*/
|
||||||
int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port);
|
int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port);
|
||||||
|
4
evrpc.c
4
evrpc.c
@ -479,7 +479,7 @@ evrpc_pool_set_timeout(struct evrpc_pool *pool, int timeout_in_secs)
|
|||||||
|
|
||||||
|
|
||||||
static void evrpc_reply_done(struct evhttp_request *, void *);
|
static void evrpc_reply_done(struct evhttp_request *, void *);
|
||||||
static void evrpc_request_timeout(int, short, void *);
|
static void evrpc_request_timeout(evutil_socket_t, short, void *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finds a connection object associated with the pool that is currently
|
* Finds a connection object associated with the pool that is currently
|
||||||
@ -643,7 +643,7 @@ evrpc_pool_schedule(struct evrpc_pool *pool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
evrpc_request_timeout(int fd, short what, void *arg)
|
evrpc_request_timeout(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evrpc_request_wrapper *ctx = arg;
|
struct evrpc_request_wrapper *ctx = arg;
|
||||||
struct evhttp_connection *evcon = ctx->evcon;
|
struct evhttp_connection *evcon = ctx->evcon;
|
||||||
|
@ -27,12 +27,16 @@
|
|||||||
#ifndef _EVSIGNAL_H_
|
#ifndef _EVSIGNAL_H_
|
||||||
#define _EVSIGNAL_H_
|
#define _EVSIGNAL_H_
|
||||||
|
|
||||||
|
#ifndef evutil_socket_t
|
||||||
|
#include "evutil.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*ev_sighandler_t)(int);
|
typedef void (*ev_sighandler_t)(int);
|
||||||
|
|
||||||
struct evsignal_info {
|
struct evsignal_info {
|
||||||
struct event_list signalqueue;
|
struct event_list signalqueue;
|
||||||
struct event ev_signal;
|
struct event ev_signal;
|
||||||
int ev_signal_pair[2];
|
evutil_socket_t ev_signal_pair[2];
|
||||||
int ev_signal_added;
|
int ev_signal_added;
|
||||||
volatile sig_atomic_t evsignal_caught;
|
volatile sig_atomic_t evsignal_caught;
|
||||||
sig_atomic_t evsigcaught[NSIG];
|
sig_atomic_t evsigcaught[NSIG];
|
||||||
|
10
evutil.c
10
evutil.c
@ -52,7 +52,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
evutil_socketpair(int family, int type, int protocol, int fd[2])
|
evutil_socketpair(int family, int type, int protocol, evutil_socket_t fd[2])
|
||||||
{
|
{
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
return socketpair(family, type, protocol, fd);
|
return socketpair(family, type, protocol, fd);
|
||||||
@ -64,9 +64,9 @@ evutil_socketpair(int family, int type, int protocol, int fd[2])
|
|||||||
* for now, and really, when localhost is down sometimes, we
|
* for now, and really, when localhost is down sometimes, we
|
||||||
* have other problems too.
|
* have other problems too.
|
||||||
*/
|
*/
|
||||||
int listener = -1;
|
evutil_socket_t listener = -1;
|
||||||
int connector = -1;
|
evutil_socket_t connector = -1;
|
||||||
int acceptor = -1;
|
evutil_socket_t acceptor = -1;
|
||||||
struct sockaddr_in listen_addr;
|
struct sockaddr_in listen_addr;
|
||||||
struct sockaddr_in connect_addr;
|
struct sockaddr_in connect_addr;
|
||||||
int size;
|
int size;
|
||||||
@ -150,7 +150,7 @@ evutil_socketpair(int family, int type, int protocol, int fd[2])
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
evutil_make_socket_nonblocking(int fd)
|
evutil_make_socket_nonblocking(evutil_socket_t fd)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
{
|
{
|
||||||
|
38
evutil.h
38
evutil.h
@ -43,8 +43,29 @@ extern "C" {
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int evutil_socketpair(int d, int type, int protocol, int sv[2]);
|
#ifdef _EVENT_HAVE_STDINT_H
|
||||||
int evutil_make_socket_nonblocking(int sock);
|
#include <stdint.h>
|
||||||
|
#define ev_uint64_t uint64_t
|
||||||
|
#define ev_uint32_t uint32_t
|
||||||
|
#define ev_uint16_t uint16_t
|
||||||
|
#define ev_uint8_t uint8_t
|
||||||
|
#elif defined(WIN32)
|
||||||
|
#define ev_uint64_t __uint64_t
|
||||||
|
#define ev_uint32_t unsigned int
|
||||||
|
#define ev_uint16_t unsigned short
|
||||||
|
#define ev_uint8_t unsigned char
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/** Type to hold the output of "socket()" or "accept()". On Windows, this is
|
||||||
|
* an intptr_t; elsewhere, it is an int. */
|
||||||
|
#define evutil_socket_t intptr_t
|
||||||
|
#else
|
||||||
|
#define evutil_socket_t int
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int evutil_socketpair(int d, int type, int protocol, evutil_socket_t sv[2]);
|
||||||
|
int evutil_make_socket_nonblocking(evutil_socket_t sock);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define EVUTIL_CLOSESOCKET(s) closesocket(s)
|
#define EVUTIL_CLOSESOCKET(s) closesocket(s)
|
||||||
#else
|
#else
|
||||||
@ -109,19 +130,6 @@ int evutil_make_socket_nonblocking(int sock);
|
|||||||
#define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
#define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _EVENT_HAVE_STDINT_H
|
|
||||||
#include <stdint.h>
|
|
||||||
#define ev_uint64_t uint64_t
|
|
||||||
#define ev_uint32_t uint32_t
|
|
||||||
#define ev_uint16_t uint16_t
|
|
||||||
#define ev_uint8_t uint8_t
|
|
||||||
#elif defined(WIN32)
|
|
||||||
#define ev_uint64_t __uint64_t
|
|
||||||
#define ev_uint32_t unsigned int
|
|
||||||
#define ev_uint16_t unsigned short
|
|
||||||
#define ev_uint8_t unsigned char
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,7 +41,7 @@ struct evhttp_connection {
|
|||||||
/* we use tailq only if they were created for an http server */
|
/* we use tailq only if they were created for an http server */
|
||||||
TAILQ_ENTRY(evhttp_connection) (next);
|
TAILQ_ENTRY(evhttp_connection) (next);
|
||||||
|
|
||||||
int fd;
|
evutil_socket_t fd;
|
||||||
struct event ev;
|
struct event ev;
|
||||||
struct event close_ev;
|
struct event close_ev;
|
||||||
struct evbuffer *input_buffer;
|
struct evbuffer *input_buffer;
|
||||||
@ -113,14 +113,14 @@ int evhttp_connection_connect(struct evhttp_connection *);
|
|||||||
void evhttp_connection_fail(struct evhttp_connection *,
|
void evhttp_connection_fail(struct evhttp_connection *,
|
||||||
enum evhttp_connection_error error);
|
enum evhttp_connection_error error);
|
||||||
|
|
||||||
void evhttp_get_request(struct evhttp *, int, struct sockaddr *, socklen_t);
|
void evhttp_get_request(struct evhttp *, evutil_socket_t, struct sockaddr *, socklen_t);
|
||||||
|
|
||||||
int evhttp_hostportfile(char *, char **, u_short *, char **);
|
int evhttp_hostportfile(char *, char **, u_short *, char **);
|
||||||
|
|
||||||
int evhttp_parse_lines(struct evhttp_request *, struct evbuffer*);
|
int evhttp_parse_lines(struct evhttp_request *, struct evbuffer*);
|
||||||
|
|
||||||
void evhttp_start_read(struct evhttp_connection *);
|
void evhttp_start_read(struct evhttp_connection *);
|
||||||
void evhttp_read_header(int, short, void *);
|
void evhttp_read_header(evutil_socket_t, short, void *);
|
||||||
void evhttp_make_header(struct evhttp_connection *, struct evhttp_request *);
|
void evhttp_make_header(struct evhttp_connection *, struct evhttp_request *);
|
||||||
|
|
||||||
void evhttp_write_buffer(struct evhttp_connection *,
|
void evhttp_write_buffer(struct evhttp_connection *,
|
||||||
|
46
http.c
46
http.c
@ -151,9 +151,9 @@ fake_freeaddrinfo(struct addrinfo *ai)
|
|||||||
|
|
||||||
extern int debug;
|
extern int debug;
|
||||||
|
|
||||||
static int socket_connect(int fd, const char *address, unsigned short port);
|
static int socket_connect(evutil_socket_t kefd, const char *address, unsigned short port);
|
||||||
static int bind_socket_ai(struct addrinfo *);
|
static evutil_socket_t bind_socket_ai(struct addrinfo *);
|
||||||
static int bind_socket(const char *, u_short);
|
static evutil_socket_t bind_socket(const char *, u_short);
|
||||||
static void name_from_addr(struct sockaddr *, socklen_t, char **, char **);
|
static void name_from_addr(struct sockaddr *, socklen_t, char **, char **);
|
||||||
static int evhttp_associate_new_request_with_connection(
|
static int evhttp_associate_new_request_with_connection(
|
||||||
struct evhttp_connection *evcon);
|
struct evhttp_connection *evcon);
|
||||||
@ -163,8 +163,8 @@ static void evhttp_connection_stop_detectclose(
|
|||||||
struct evhttp_connection *evcon);
|
struct evhttp_connection *evcon);
|
||||||
static void evhttp_request_dispatch(struct evhttp_connection* evcon);
|
static void evhttp_request_dispatch(struct evhttp_connection* evcon);
|
||||||
|
|
||||||
void evhttp_read(int, short, void *);
|
void evhttp_read(evutil_socket_t, short, void *);
|
||||||
void evhttp_write(int, short, void *);
|
void evhttp_write(evutil_socket_t, short, void *);
|
||||||
|
|
||||||
#ifndef HAVE_STRSEP
|
#ifndef HAVE_STRSEP
|
||||||
/* strsep replacement for platforms that lack it. Only works if
|
/* strsep replacement for platforms that lack it. Only works if
|
||||||
@ -585,7 +585,7 @@ evhttp_connection_fail(struct evhttp_connection *evcon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_write(int fd, short what, void *arg)
|
evhttp_write(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
int n;
|
int n;
|
||||||
@ -771,7 +771,7 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_read(int fd, short what, void *arg)
|
evhttp_read(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
||||||
@ -916,7 +916,7 @@ evhttp_connection_reset(struct evhttp_connection *evcon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
evhttp_detect_close_cb(int fd, short what, void *arg)
|
evhttp_detect_close_cb(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
evhttp_connection_reset(evcon);
|
evhttp_connection_reset(evcon);
|
||||||
@ -943,7 +943,7 @@ evhttp_connection_stop_detectclose(struct evhttp_connection *evcon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
evhttp_connection_retry(int fd, short what, void *arg)
|
evhttp_connection_retry(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
|
|
||||||
@ -956,7 +956,7 @@ evhttp_connection_retry(int fd, short what, void *arg)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
evhttp_connectioncb(int fd, short what, void *arg)
|
evhttp_connectioncb(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
int error;
|
int error;
|
||||||
@ -1349,7 +1349,7 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_read_header(int fd, short what, void *arg)
|
evhttp_read_header(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
||||||
@ -1960,12 +1960,12 @@ evhttp_handle_request(struct evhttp_request *req, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
accept_socket(int fd, short what, void *arg)
|
accept_socket(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp *http = arg;
|
struct evhttp *http = arg;
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
socklen_t addrlen = sizeof(ss);
|
socklen_t addrlen = sizeof(ss);
|
||||||
int nfd;
|
evutil_socket_t nfd;
|
||||||
|
|
||||||
if ((nfd = accept(fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
|
if ((nfd = accept(fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
|
||||||
event_warn("%s: bad accept", __func__);
|
event_warn("%s: bad accept", __func__);
|
||||||
@ -1981,7 +1981,7 @@ int
|
|||||||
evhttp_bind_socket(struct evhttp *http, const char *address, u_short port)
|
evhttp_bind_socket(struct evhttp *http, const char *address, u_short port)
|
||||||
{
|
{
|
||||||
struct event *ev = &http->bind_ev;
|
struct event *ev = &http->bind_ev;
|
||||||
int fd;
|
evutil_socket_t fd;
|
||||||
|
|
||||||
if ((fd = bind_socket(address, port)) == -1)
|
if ((fd = bind_socket(address, port)) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -2052,7 +2052,7 @@ evhttp_free(struct evhttp* http)
|
|||||||
{
|
{
|
||||||
struct evhttp_cb *http_cb;
|
struct evhttp_cb *http_cb;
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
int fd = http->bind_ev.ev_fd;
|
evutil_socket_t fd = http->bind_ev.ev_fd;
|
||||||
|
|
||||||
/* Remove the accepting part */
|
/* Remove the accepting part */
|
||||||
event_del(&http->bind_ev);
|
event_del(&http->bind_ev);
|
||||||
@ -2223,7 +2223,7 @@ evhttp_request_uri(struct evhttp_request *req) {
|
|||||||
static struct evhttp_connection*
|
static struct evhttp_connection*
|
||||||
evhttp_get_request_connection(
|
evhttp_get_request_connection(
|
||||||
struct evhttp* http,
|
struct evhttp* http,
|
||||||
int fd, struct sockaddr *sa, socklen_t salen)
|
evutil_socket_t fd, struct sockaddr *sa, socklen_t salen)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
char *hostname, *portname;
|
char *hostname, *portname;
|
||||||
@ -2272,7 +2272,7 @@ evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_get_request(struct evhttp *http, int fd,
|
evhttp_get_request(struct evhttp *http, evutil_socket_t fd,
|
||||||
struct sockaddr *sa, socklen_t salen)
|
struct sockaddr *sa, socklen_t salen)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
@ -2355,11 +2355,13 @@ name_from_addr(struct sockaddr *sa, socklen_t salen,
|
|||||||
|
|
||||||
/* Either connect or bind */
|
/* Either connect or bind */
|
||||||
|
|
||||||
static int
|
static evutil_socket_t
|
||||||
bind_socket_ai(struct addrinfo *ai)
|
bind_socket_ai(struct addrinfo *ai)
|
||||||
{
|
{
|
||||||
struct linger linger;
|
struct linger linger;
|
||||||
int fd, on = 1, r;
|
evutil_socket_t fd;
|
||||||
|
|
||||||
|
int on = 1, r;
|
||||||
int serrno;
|
int serrno;
|
||||||
|
|
||||||
/* Create listen socket */
|
/* Create listen socket */
|
||||||
@ -2436,10 +2438,10 @@ make_addrinfo(const char *address, u_short port)
|
|||||||
return (aitop);
|
return (aitop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static evutil_socket_t
|
||||||
bind_socket(const char *address, u_short port)
|
bind_socket(const char *address, u_short port)
|
||||||
{
|
{
|
||||||
int fd;
|
evutil_socket_t fd;
|
||||||
struct addrinfo *aitop = make_addrinfo(address, port);
|
struct addrinfo *aitop = make_addrinfo(address, port);
|
||||||
|
|
||||||
if (aitop == NULL)
|
if (aitop == NULL)
|
||||||
@ -2457,7 +2459,7 @@ bind_socket(const char *address, u_short port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
socket_connect(int fd, const char *address, unsigned short port)
|
socket_connect(evutil_socket_t fd, const char *address, unsigned short port)
|
||||||
{
|
{
|
||||||
struct addrinfo *ai = make_addrinfo(address, port);
|
struct addrinfo *ai = make_addrinfo(address, port);
|
||||||
int res = -1;
|
int res = -1;
|
||||||
|
4
signal.c
4
signal.c
@ -59,8 +59,8 @@
|
|||||||
|
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "event-internal.h"
|
#include "event-internal.h"
|
||||||
#include "evsignal.h"
|
|
||||||
#include "evutil.h"
|
#include "evutil.h"
|
||||||
|
#include "evsignal.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
struct event_base *evsignal_base = NULL;
|
struct event_base *evsignal_base = NULL;
|
||||||
@ -69,7 +69,7 @@ static void evsignal_handler(int sig);
|
|||||||
|
|
||||||
/* Callback for when the signal handler write a byte to our signaling socket */
|
/* Callback for when the signal handler write a byte to our signaling socket */
|
||||||
static void
|
static void
|
||||||
evsignal_cb(int fd, short what, void *arg)
|
evsignal_cb(evutil_socket_t fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
static char signals[100];
|
static char signals[100];
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user