mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 23:05:03 -04:00
Remove all trailing whitespace in all the source files.
svn:r1063
This commit is contained in:
parent
3065389973
commit
9993137cbb
28
buffer.c
28
buffer.c
@ -119,7 +119,7 @@ evbuffer_chain_new(size_t size)
|
|||||||
size_t to_alloc;
|
size_t to_alloc;
|
||||||
|
|
||||||
size += EVBUFFER_CHAIN_SIZE;
|
size += EVBUFFER_CHAIN_SIZE;
|
||||||
|
|
||||||
/* get the next largest memory that can hold the buffer */
|
/* get the next largest memory that can hold the buffer */
|
||||||
to_alloc = MIN_BUFFER_SIZE;
|
to_alloc = MIN_BUFFER_SIZE;
|
||||||
while (to_alloc < size)
|
while (to_alloc < size)
|
||||||
@ -288,7 +288,7 @@ evbuffer_commit_space(struct evbuffer *buf, size_t size)
|
|||||||
{
|
{
|
||||||
struct evbuffer_chain *chain = buf->last;
|
struct evbuffer_chain *chain = buf->last;
|
||||||
|
|
||||||
if (chain == NULL ||
|
if (chain == NULL ||
|
||||||
chain->buffer_len - chain->off - chain->misalign < size)
|
chain->buffer_len - chain->off - chain->misalign < size)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ evbuffer_commit_space(struct evbuffer *buf, size_t size)
|
|||||||
(dst)->previous_to_last = NULL; \
|
(dst)->previous_to_last = NULL; \
|
||||||
(dst)->total_len = 0; \
|
(dst)->total_len = 0; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define COPY_CHAIN(dst, src) do { \
|
#define COPY_CHAIN(dst, src) do { \
|
||||||
(dst)->first = (src)->first; \
|
(dst)->first = (src)->first; \
|
||||||
(dst)->previous_to_last = (src)->previous_to_last; \
|
(dst)->previous_to_last = (src)->previous_to_last; \
|
||||||
@ -327,7 +327,7 @@ evbuffer_commit_space(struct evbuffer *buf, size_t size)
|
|||||||
if ((dst)->previous_to_last == NULL) \
|
if ((dst)->previous_to_last == NULL) \
|
||||||
(dst)->previous_to_last = (src)->last; \
|
(dst)->previous_to_last = (src)->last; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf)
|
evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf)
|
||||||
@ -502,7 +502,7 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
|||||||
src->first = chain;
|
src->first = chain;
|
||||||
if (src->first == src->last)
|
if (src->first == src->last)
|
||||||
src->previous_to_last = NULL;
|
src->previous_to_last = NULL;
|
||||||
|
|
||||||
dst->total_len += nread;
|
dst->total_len += nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +569,7 @@ evbuffer_pullup(struct evbuffer *buf, ssize_t size)
|
|||||||
memcpy(buffer, chain->buffer + chain->misalign, chain->off);
|
memcpy(buffer, chain->buffer + chain->misalign, chain->off);
|
||||||
size -= chain->off;
|
size -= chain->off;
|
||||||
buffer += chain->off;
|
buffer += chain->off;
|
||||||
|
|
||||||
evbuffer_chain_free(chain);
|
evbuffer_chain_free(chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -802,7 +802,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
|
|||||||
chain->buffer + chain->misalign,
|
chain->buffer + chain->misalign,
|
||||||
chain->off);
|
chain->off);
|
||||||
chain->misalign = 0;
|
chain->misalign = 0;
|
||||||
|
|
||||||
memcpy(chain->buffer + chain->off, data, datlen);
|
memcpy(chain->buffer + chain->off, data, datlen);
|
||||||
chain->off += datlen;
|
chain->off += datlen;
|
||||||
buf->total_len += datlen;
|
buf->total_len += datlen;
|
||||||
@ -822,7 +822,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
|
|||||||
tmp = evbuffer_chain_new(to_alloc);
|
tmp = evbuffer_chain_new(to_alloc);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (remain) {
|
if (remain) {
|
||||||
memcpy(chain->buffer + chain->misalign + chain->off,
|
memcpy(chain->buffer + chain->misalign + chain->off,
|
||||||
data, remain);
|
data, remain);
|
||||||
@ -1260,7 +1260,7 @@ evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t fd,
|
|||||||
res = sendfile(fd, info->fd, &offset, chain->off);
|
res = sendfile(fd, info->fd, &offset, chain->off);
|
||||||
if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
|
if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
|
||||||
/* if this is EGAIN or EINTR return 0; otherwise, -1 */
|
/* if this is EGAIN or EINTR return 0; otherwise, -1 */
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
return (res);
|
return (res);
|
||||||
#endif
|
#endif
|
||||||
@ -1449,11 +1449,11 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
|
|||||||
|
|
||||||
info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain);
|
info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain);
|
||||||
info->fd = fd;
|
info->fd = fd;
|
||||||
|
|
||||||
evbuffer_chain_insert(outbuf, chain);
|
evbuffer_chain_insert(outbuf, chain);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_MMAP)
|
#if defined(HAVE_MMAP)
|
||||||
if (use_mmap) {
|
if (use_mmap) {
|
||||||
void *mapped = mmap(NULL, length + offset, PROT_READ,
|
void *mapped = mmap(NULL, length + offset, PROT_READ,
|
||||||
#ifdef MAP_NOCACHE
|
#ifdef MAP_NOCACHE
|
||||||
@ -1483,10 +1483,10 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
|
|||||||
chain->buffer = mapped;
|
chain->buffer = mapped;
|
||||||
chain->buffer_len = length + offset;
|
chain->buffer_len = length + offset;
|
||||||
chain->off = length + offset;
|
chain->off = length + offset;
|
||||||
|
|
||||||
info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain);
|
info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain);
|
||||||
info->fd = fd;
|
info->fd = fd;
|
||||||
|
|
||||||
evbuffer_chain_insert(outbuf, chain);
|
evbuffer_chain_insert(outbuf, chain);
|
||||||
|
|
||||||
/* we need to subtract whatever we don't need */
|
/* we need to subtract whatever we don't need */
|
||||||
@ -1509,7 +1509,7 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
|
|||||||
|
|
||||||
length -= read;
|
length -= read;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ bufferevent_add(struct event *ev, int timeout)
|
|||||||
return (event_add(ev, ptv));
|
return (event_add(ev, ptv));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This callback is executed when the size of the input buffer changes.
|
* This callback is executed when the size of the input buffer changes.
|
||||||
* We use it to apply back pressure on the reading side.
|
* We use it to apply back pressure on the reading side.
|
||||||
*/
|
*/
|
||||||
@ -398,7 +398,7 @@ bufferevent_free(struct bufferevent *bufev)
|
|||||||
|
|
||||||
bufferevent_filter_free(filter);
|
bufferevent_filter_free(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((filter = TAILQ_FIRST(&bufev->output_filters)) != NULL) {
|
while ((filter = TAILQ_FIRST(&bufev->output_filters)) != NULL) {
|
||||||
bufferevent_filter_remove(bufev, BEV_OUTPUT, filter);
|
bufferevent_filter_remove(bufev, BEV_OUTPUT, filter);
|
||||||
|
|
||||||
@ -469,7 +469,7 @@ bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf)
|
|||||||
|
|
||||||
if (evbuffer_add_buffer(output, buf) == -1)
|
if (evbuffer_add_buffer(output, buf) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
return (bufferevent_write_closure(bufev, len > 0));
|
return (bufferevent_write_closure(bufev, len > 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,7 +648,7 @@ bufferevent_filter_remove(struct bufferevent *bufev,
|
|||||||
|
|
||||||
if (filter->free_context)
|
if (filter->free_context)
|
||||||
filter->free_context(filter->ctx);
|
filter->free_context(filter->ctx);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
10
devpoll.c
10
devpoll.c
@ -102,8 +102,8 @@ devpoll_queue(struct devpollop *devpollop, int fd, int events) {
|
|||||||
|
|
||||||
if (devpollop->nchanges >= devpollop->nevents) {
|
if (devpollop->nchanges >= devpollop->nevents) {
|
||||||
/*
|
/*
|
||||||
* Change buffer is full, must commit it to /dev/poll before
|
* Change buffer is full, must commit it to /dev/poll before
|
||||||
* adding more
|
* adding more
|
||||||
*/
|
*/
|
||||||
if (devpoll_commit(devpollop) != 0)
|
if (devpoll_commit(devpollop) != 0)
|
||||||
return(-1);
|
return(-1);
|
||||||
@ -228,7 +228,7 @@ devpoll_add(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
int res;
|
int res;
|
||||||
(void)p;
|
(void)p;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It's not necessary to OR the existing read/write events that we
|
* It's not necessary to OR the existing read/write events that we
|
||||||
* are currently interested in with the new event we are adding.
|
* are currently interested in with the new event we are adding.
|
||||||
* The /dev/poll driver ORs any new events with the existing events
|
* The /dev/poll driver ORs any new events with the existing events
|
||||||
@ -262,8 +262,8 @@ devpoll_del(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The only way to remove an fd from the /dev/poll monitored set is
|
* The only way to remove an fd from the /dev/poll monitored set is
|
||||||
* to use POLLREMOVE by itself. This removes ALL events for the fd
|
* to use POLLREMOVE by itself. This removes ALL events for the fd
|
||||||
* provided so if we care about two events and are only removing one
|
* provided so if we care about two events and are only removing one
|
||||||
* we must re-add the other event after POLLREMOVE.
|
* we must re-add the other event after POLLREMOVE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
2
evdns.c
2
evdns.c
@ -1513,7 +1513,7 @@ evdns_request_data_build(const char *const name, const int name_len,
|
|||||||
if (j < 0) {
|
if (j < 0) {
|
||||||
return (int)j;
|
return (int)j;
|
||||||
}
|
}
|
||||||
|
|
||||||
APPEND16(type);
|
APPEND16(type);
|
||||||
APPEND16(class);
|
APPEND16(class);
|
||||||
|
|
||||||
|
24
event.c
24
event.c
@ -38,7 +38,7 @@
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#ifdef HAVE_SYS_TIME_H
|
#ifdef HAVE_SYS_TIME_H
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/_time.h>
|
#include <sys/_time.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -399,7 +399,7 @@ event_reinit(struct event_base *base)
|
|||||||
EVLIST_ACTIVE);
|
EVLIST_ACTIVE);
|
||||||
base->sig.ev_signal_added = 0;
|
base->sig.ev_signal_added = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base->evsel->dealloc != NULL)
|
if (base->evsel->dealloc != NULL)
|
||||||
base->evsel->dealloc(base);
|
base->evsel->dealloc(base);
|
||||||
base->evbase = evsel->init(base);
|
base->evbase = evsel->init(base);
|
||||||
@ -623,10 +623,10 @@ event_process_active(struct event_base *base)
|
|||||||
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
||||||
else
|
else
|
||||||
event_del_internal(ev);
|
event_del_internal(ev);
|
||||||
|
|
||||||
event_debug((
|
event_debug((
|
||||||
"event_process_active: event: %p, %s%scall %p",
|
"event_process_active: event: %p, %s%scall %p",
|
||||||
ev,
|
ev,
|
||||||
ev->ev_res & EV_READ ? "EV_READ " : " ",
|
ev->ev_res & EV_READ ? "EV_READ " : " ",
|
||||||
ev->ev_res & EV_WRITE ? "EV_WRITE " : " ",
|
ev->ev_res & EV_WRITE ? "EV_WRITE " : " ",
|
||||||
ev->ev_callback));
|
ev->ev_callback));
|
||||||
@ -769,13 +769,13 @@ event_base_loop(struct event_base *base, int flags)
|
|||||||
if (!base->event_count_active && !(flags & EVLOOP_NONBLOCK)) {
|
if (!base->event_count_active && !(flags & EVLOOP_NONBLOCK)) {
|
||||||
timeout_next(base, &tv_p);
|
timeout_next(base, &tv_p);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* if we have active events, we just poll new events
|
* if we have active events, we just poll new events
|
||||||
* without waiting.
|
* without waiting.
|
||||||
*/
|
*/
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have no events, we just exit */
|
/* If we have no events, we just exit */
|
||||||
if (!event_haveevents(base)) {
|
if (!event_haveevents(base)) {
|
||||||
event_debug(("%s: no events registered.", __func__));
|
event_debug(("%s: no events registered.", __func__));
|
||||||
@ -1119,7 +1119,7 @@ event_add_internal(struct event *ev, const struct timeval *tv)
|
|||||||
event_queue_insert(base, ev, EVLIST_INSERTED);
|
event_queue_insert(base, ev, EVLIST_INSERTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we should change the timout state only if the previous event
|
* we should change the timout state only if the previous event
|
||||||
* addition succeeded.
|
* addition succeeded.
|
||||||
*/
|
*/
|
||||||
@ -1133,13 +1133,13 @@ event_add_internal(struct event *ev, const struct timeval *tv)
|
|||||||
if (ev->ev_closure == event_persist_closure)
|
if (ev->ev_closure == event_persist_closure)
|
||||||
ev->ev_io_timeout = *tv;
|
ev->ev_io_timeout = *tv;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we already reserved memory above for the case where we
|
* we already reserved memory above for the case where we
|
||||||
* are not replacing an exisiting timeout.
|
* are not replacing an exisiting timeout.
|
||||||
*/
|
*/
|
||||||
if (ev->ev_flags & EVLIST_TIMEOUT)
|
if (ev->ev_flags & EVLIST_TIMEOUT)
|
||||||
event_queue_remove(base, ev, EVLIST_TIMEOUT);
|
event_queue_remove(base, ev, EVLIST_TIMEOUT);
|
||||||
|
|
||||||
/* Check if it is active due to a timeout. Rescheduling
|
/* Check if it is active due to a timeout. Rescheduling
|
||||||
* this timeout before the callback can be executed
|
* this timeout before the callback can be executed
|
||||||
* removes it from the active list. */
|
* removes it from the active list. */
|
||||||
@ -1154,7 +1154,7 @@ event_add_internal(struct event *ev, const struct timeval *tv)
|
|||||||
*ev->ev_pncalls = 0;
|
*ev->ev_pncalls = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1181,7 +1181,7 @@ event_del(struct event *ev)
|
|||||||
int res;
|
int res;
|
||||||
|
|
||||||
EVTHREAD_ACQUIRE_LOCK(ev->ev_base, EVTHREAD_WRITE, th_base_lock);
|
EVTHREAD_ACQUIRE_LOCK(ev->ev_base, EVTHREAD_WRITE, th_base_lock);
|
||||||
|
|
||||||
res = event_del_internal(ev);
|
res = event_del_internal(ev);
|
||||||
|
|
||||||
EVTHREAD_RELEASE_LOCK(ev->ev_base, EVTHREAD_WRITE, th_base_lock);
|
EVTHREAD_RELEASE_LOCK(ev->ev_base, EVTHREAD_WRITE, th_base_lock);
|
||||||
@ -1448,7 +1448,7 @@ event_get_version(void)
|
|||||||
return (VERSION);
|
return (VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No thread-safe interface needed - the information should be the same
|
* No thread-safe interface needed - the information should be the same
|
||||||
* for all threads.
|
* for all threads.
|
||||||
*/
|
*/
|
||||||
|
146
event_rpcgen.py
146
event_rpcgen.py
@ -59,10 +59,10 @@ class Struct:
|
|||||||
|
|
||||||
class StructCCode(Struct):
|
class StructCCode(Struct):
|
||||||
""" Knows how to generate C code for a struct """
|
""" Knows how to generate C code for a struct """
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
Struct.__init__(self, name)
|
Struct.__init__(self, name)
|
||||||
|
|
||||||
def PrintTags(self, file):
|
def PrintTags(self, file):
|
||||||
"""Prints the tag definitions for a structure."""
|
"""Prints the tag definitions for a structure."""
|
||||||
print >>file, '/* Tag definition for %s */' % self._name
|
print >>file, '/* Tag definition for %s */' % self._name
|
||||||
@ -106,7 +106,7 @@ void %(name)s_clear(struct %(name)s *);
|
|||||||
void %(name)s_marshal(struct evbuffer *, const struct %(name)s *);
|
void %(name)s_marshal(struct evbuffer *, const struct %(name)s *);
|
||||||
int %(name)s_unmarshal(struct %(name)s *, struct evbuffer *);
|
int %(name)s_unmarshal(struct %(name)s *, struct evbuffer *);
|
||||||
int %(name)s_complete(struct %(name)s *);
|
int %(name)s_complete(struct %(name)s *);
|
||||||
void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
||||||
const struct %(name)s *);
|
const struct %(name)s *);
|
||||||
int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
||||||
struct %(name)s *);""" % { 'name' : self._name }
|
struct %(name)s *);""" % { 'name' : self._name }
|
||||||
@ -161,7 +161,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
if entry.Array():
|
if entry.Array():
|
||||||
self.PrintIndented(file, '', entry.CodeAdd())
|
self.PrintIndented(file, '', entry.CodeAdd())
|
||||||
print >>file, ''
|
print >>file, ''
|
||||||
|
|
||||||
# Assigning
|
# Assigning
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, '', entry.CodeAssign())
|
self.PrintIndented(file, '', entry.CodeAssign())
|
||||||
@ -171,7 +171,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, '', entry.CodeGet())
|
self.PrintIndented(file, '', entry.CodeGet())
|
||||||
print >>file, ''
|
print >>file, ''
|
||||||
|
|
||||||
# Clearing
|
# Clearing
|
||||||
print >>file, ( 'void\n'
|
print >>file, ( 'void\n'
|
||||||
'%(name)s_clear(struct %(name)s *tmp)\n'
|
'%(name)s_clear(struct %(name)s *tmp)\n'
|
||||||
@ -187,7 +187,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
'%(name)s_free(struct %(name)s *tmp)\n'
|
'%(name)s_free(struct %(name)s *tmp)\n'
|
||||||
'{'
|
'{'
|
||||||
) % { 'name' : self._name }
|
) % { 'name' : self._name }
|
||||||
|
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, ' ', entry.CodeFree('tmp'))
|
self.PrintIndented(file, ' ', entry.CodeFree('tmp'))
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
print >>file, ' }'
|
print >>file, ' }'
|
||||||
|
|
||||||
print >>file, '}\n'
|
print >>file, '}\n'
|
||||||
|
|
||||||
# Unmarshaling
|
# Unmarshaling
|
||||||
print >>file, ('int\n'
|
print >>file, ('int\n'
|
||||||
'%(name)s_unmarshal(struct %(name)s *tmp, '
|
'%(name)s_unmarshal(struct %(name)s *tmp, '
|
||||||
@ -269,7 +269,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
code = TranslateList(code, entry.GetTranslation())
|
code = TranslateList(code, entry.GetTranslation())
|
||||||
self.PrintIndented(
|
self.PrintIndented(
|
||||||
file, ' ', code)
|
file, ' ', code)
|
||||||
|
|
||||||
self.PrintIndented(
|
self.PrintIndented(
|
||||||
file, ' ',
|
file, ' ',
|
||||||
entry.CodeComplete('msg', entry.GetVarName('msg')))
|
entry.CodeComplete('msg', entry.GetVarName('msg')))
|
||||||
@ -361,7 +361,7 @@ class Entry:
|
|||||||
|
|
||||||
def MakeArray(self, yes=1):
|
def MakeArray(self, yes=1):
|
||||||
self._array = yes
|
self._array = yes
|
||||||
|
|
||||||
def MakeOptional(self):
|
def MakeOptional(self):
|
||||||
self._optional = 1
|
self._optional = 1
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ class Entry:
|
|||||||
mapping[k] = v
|
mapping[k] = v
|
||||||
|
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
def GetVarName(self, var):
|
def GetVarName(self, var):
|
||||||
return '%(var)s->%(name)s_data' % self.GetTranslation({ 'var' : var })
|
return '%(var)s->%(name)s_data' % self.GetTranslation({ 'var' : var })
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ class Entry:
|
|||||||
|
|
||||||
def GetFuncName(self):
|
def GetFuncName(self):
|
||||||
return '%s_%s_get' % (self._struct.Name(), self._name)
|
return '%s_%s_get' % (self._struct.Name(), self._name)
|
||||||
|
|
||||||
def GetDeclaration(self, funcname):
|
def GetDeclaration(self, funcname):
|
||||||
code = [ 'int %s(struct %s *, %s *);' % (
|
code = [ 'int %s(struct %s *, %s *);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
@ -426,13 +426,13 @@ class Entry:
|
|||||||
code = '\n'.join(code)
|
code = '\n'.join(code)
|
||||||
code = code % self.GetTranslation()
|
code = code % self.GetTranslation()
|
||||||
return code.split('\n')
|
return code.split('\n')
|
||||||
|
|
||||||
def AssignFuncName(self):
|
def AssignFuncName(self):
|
||||||
return '%s_%s_assign' % (self._struct.Name(), self._name)
|
return '%s_%s_assign' % (self._struct.Name(), self._name)
|
||||||
|
|
||||||
def AddFuncName(self):
|
def AddFuncName(self):
|
||||||
return '%s_%s_add' % (self._struct.Name(), self._name)
|
return '%s_%s_add' % (self._struct.Name(), self._name)
|
||||||
|
|
||||||
def AssignDeclaration(self, funcname):
|
def AssignDeclaration(self, funcname):
|
||||||
code = [ 'int %s(struct %s *, const %s);' % (
|
code = [ 'int %s(struct %s *, const %s);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
@ -455,7 +455,7 @@ class Entry:
|
|||||||
code = [ '%s->%s_set = 0;' % (structname, self.Name()) ]
|
code = [ '%s->%s_set = 0;' % (structname, self.Name()) ]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeComplete(self, structname, var_name):
|
def CodeComplete(self, structname, var_name):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -496,15 +496,15 @@ class EntryBytes(Entry):
|
|||||||
code = [ 'int %s(struct %s *, %s **);' % (
|
code = [ 'int %s(struct %s *, %s **);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def AssignDeclaration(self, funcname):
|
def AssignDeclaration(self, funcname):
|
||||||
code = [ 'int %s(struct %s *, const %s *);' % (
|
code = [ 'int %s(struct %s *, const %s *);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def Declaration(self):
|
def Declaration(self):
|
||||||
dcl = ['ev_uint8_t %s_data[%s];' % (self._name, self._length)]
|
dcl = ['ev_uint8_t %s_data[%s];' % (self._name, self._length)]
|
||||||
|
|
||||||
return dcl
|
return dcl
|
||||||
|
|
||||||
def CodeGet(self):
|
def CodeGet(self):
|
||||||
@ -520,7 +520,7 @@ class EntryBytes(Entry):
|
|||||||
' return (0);',
|
' return (0);',
|
||||||
'}' ]
|
'}' ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeAssign(self):
|
def CodeAssign(self):
|
||||||
name = self._name
|
name = self._name
|
||||||
code = [ 'int',
|
code = [ 'int',
|
||||||
@ -534,7 +534,7 @@ class EntryBytes(Entry):
|
|||||||
' return (0);',
|
' return (0);',
|
||||||
'}' ]
|
'}' ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
||||||
code = [ 'if (evtag_unmarshal_fixed(%(buf)s, %(tag)s, '
|
code = [ 'if (evtag_unmarshal_fixed(%(buf)s, %(tag)s, '
|
||||||
'%(var)s, %(varlen)s) == -1) {',
|
'%(var)s, %(varlen)s) == -1) {',
|
||||||
@ -560,7 +560,7 @@ class EntryBytes(Entry):
|
|||||||
structname, self._name, structname, self._name)]
|
structname, self._name, structname, self._name)]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeInitialize(self, name):
|
def CodeInitialize(self, name):
|
||||||
code = ['memset(%s->%s_data, 0, sizeof(%s->%s_data));' % (
|
code = ['memset(%s->%s_data, 0, sizeof(%s->%s_data));' % (
|
||||||
name, self._name, name, self._name)]
|
name, self._name, name, self._name)]
|
||||||
@ -588,11 +588,11 @@ class EntryInt(Entry):
|
|||||||
self._marshal_type = 'int64'
|
self._marshal_type = 'int64'
|
||||||
|
|
||||||
def GetInitializer(self):
|
def GetInitializer(self):
|
||||||
return "0"
|
return "0"
|
||||||
|
|
||||||
def CodeArrayFree(self, var):
|
def CodeArrayFree(self, var):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def CodeArrayAssign(self, varname, srcvar):
|
def CodeArrayAssign(self, varname, srcvar):
|
||||||
return [ '%(varname)s = %(srcvar)s;' % { 'varname' : varname,
|
return [ '%(varname)s = %(srcvar)s;' % { 'varname' : varname,
|
||||||
'srcvar' : srcvar } ]
|
'srcvar' : srcvar } ]
|
||||||
@ -695,7 +695,7 @@ class EntryString(Entry):
|
|||||||
}""" % self.GetTranslation()
|
}""" % self.GetTranslation()
|
||||||
|
|
||||||
return code.split('\n')
|
return code.split('\n')
|
||||||
|
|
||||||
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
||||||
code = ['if (evtag_unmarshal_string(%(buf)s, %(tag)s, &%(var)s) == -1) {',
|
code = ['if (evtag_unmarshal_string(%(buf)s, %(tag)s, &%(var)s) == -1) {',
|
||||||
' event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
|
' event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
|
||||||
@ -722,14 +722,14 @@ class EntryString(Entry):
|
|||||||
]
|
]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeInitialize(self, name):
|
def CodeInitialize(self, name):
|
||||||
code = ['%s->%s_data = NULL;' % (name, self._name)]
|
code = ['%s->%s_data = NULL;' % (name, self._name)]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeFree(self, name):
|
def CodeFree(self, name):
|
||||||
code = ['if (%s->%s_data != NULL)' % (name, self._name),
|
code = ['if (%s->%s_data != NULL)' % (name, self._name),
|
||||||
' free (%s->%s_data); ' % (name, self._name)]
|
' free (%s->%s_data);' % (name, self._name)]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
@ -750,7 +750,7 @@ class EntryStruct(Entry):
|
|||||||
self._optaddarg = False
|
self._optaddarg = False
|
||||||
|
|
||||||
def GetInitializer(self):
|
def GetInitializer(self):
|
||||||
return "NULL"
|
return "NULL"
|
||||||
|
|
||||||
def GetVarLen(self, var):
|
def GetVarLen(self, var):
|
||||||
return '-1'
|
return '-1'
|
||||||
@ -791,7 +791,7 @@ class EntryStruct(Entry):
|
|||||||
' %(refname)s_clear(%(var)s);',
|
' %(refname)s_clear(%(var)s);',
|
||||||
' return (-1);',
|
' return (-1);',
|
||||||
'}' ]
|
'}' ]
|
||||||
|
|
||||||
return TranslateList(code, self.GetTranslation({
|
return TranslateList(code, self.GetTranslation({
|
||||||
'var' : var,
|
'var' : var,
|
||||||
'srcvar' : srcvar}))
|
'srcvar' : srcvar}))
|
||||||
@ -813,7 +813,7 @@ class EntryStruct(Entry):
|
|||||||
' return (0);',
|
' return (0);',
|
||||||
'}' ]
|
'}' ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeAssign(self):
|
def CodeAssign(self):
|
||||||
name = self._name
|
name = self._name
|
||||||
code = """int
|
code = """int
|
||||||
@ -853,7 +853,7 @@ class EntryStruct(Entry):
|
|||||||
return (-1);
|
return (-1);
|
||||||
}""" % self.GetTranslation()
|
}""" % self.GetTranslation()
|
||||||
return code.split('\n')
|
return code.split('\n')
|
||||||
|
|
||||||
def CodeComplete(self, structname, var_name):
|
def CodeComplete(self, structname, var_name):
|
||||||
code = [ 'if (%(structname)s->%(name)s_set && '
|
code = [ 'if (%(structname)s->%(name)s_set && '
|
||||||
'%(refname)s_complete(%(var)s) == -1)',
|
'%(refname)s_complete(%(var)s) == -1)',
|
||||||
@ -862,7 +862,7 @@ class EntryStruct(Entry):
|
|||||||
return TranslateList(code, self.GetTranslation({
|
return TranslateList(code, self.GetTranslation({
|
||||||
'structname' : structname,
|
'structname' : structname,
|
||||||
'var' : var_name }))
|
'var' : var_name }))
|
||||||
|
|
||||||
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
||||||
code = ['%(var)s = %(refname)s_new();',
|
code = ['%(var)s = %(refname)s_new();',
|
||||||
'if (%(var)s == NULL)',
|
'if (%(var)s == NULL)',
|
||||||
@ -894,7 +894,7 @@ class EntryStruct(Entry):
|
|||||||
]
|
]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeInitialize(self, name):
|
def CodeInitialize(self, name):
|
||||||
code = ['%s->%s_data = NULL;' % (name, self._name)]
|
code = ['%s->%s_data = NULL;' % (name, self._name)]
|
||||||
return code
|
return code
|
||||||
@ -919,7 +919,7 @@ class EntryVarBytes(Entry):
|
|||||||
self._ctype = 'ev_uint8_t *'
|
self._ctype = 'ev_uint8_t *'
|
||||||
|
|
||||||
def GetInitializer(self):
|
def GetInitializer(self):
|
||||||
return "NULL"
|
return "NULL"
|
||||||
|
|
||||||
def GetVarLen(self, var):
|
def GetVarLen(self, var):
|
||||||
return '%(var)s->%(name)s_length' % self.GetTranslation({ 'var' : var })
|
return '%(var)s->%(name)s_length' % self.GetTranslation({ 'var' : var })
|
||||||
@ -932,12 +932,12 @@ class EntryVarBytes(Entry):
|
|||||||
code = [ 'int %s(struct %s *, %s *, ev_uint32_t *);' % (
|
code = [ 'int %s(struct %s *, %s *, ev_uint32_t *);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def AssignDeclaration(self, funcname):
|
def AssignDeclaration(self, funcname):
|
||||||
code = [ 'int %s(struct %s *, const %s, ev_uint32_t);' % (
|
code = [ 'int %s(struct %s *, const %s, ev_uint32_t);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeAssign(self):
|
def CodeAssign(self):
|
||||||
name = self._name
|
name = self._name
|
||||||
code = [ 'int',
|
code = [ 'int',
|
||||||
@ -957,7 +957,7 @@ class EntryVarBytes(Entry):
|
|||||||
' return (0);',
|
' return (0);',
|
||||||
'}' ]
|
'}' ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeGet(self):
|
def CodeGet(self):
|
||||||
name = self._name
|
name = self._name
|
||||||
code = [ 'int',
|
code = [ 'int',
|
||||||
@ -1009,7 +1009,7 @@ class EntryVarBytes(Entry):
|
|||||||
]
|
]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeInitialize(self, name):
|
def CodeInitialize(self, name):
|
||||||
code = ['%s->%s_data = NULL;' % (name, self._name),
|
code = ['%s->%s_data = NULL;' % (name, self._name),
|
||||||
'%s->%s_length = 0;' % (name, self._name) ]
|
'%s->%s_length = 0;' % (name, self._name) ]
|
||||||
@ -1047,7 +1047,7 @@ class EntryArray(Entry):
|
|||||||
self._entry.GetVarName = GetVarName
|
self._entry.GetVarName = GetVarName
|
||||||
|
|
||||||
def GetInitializer(self):
|
def GetInitializer(self):
|
||||||
return "NULL"
|
return "NULL"
|
||||||
|
|
||||||
def GetVarName(self, var_name):
|
def GetVarName(self, var_name):
|
||||||
return var_name
|
return var_name
|
||||||
@ -1061,19 +1061,19 @@ class EntryArray(Entry):
|
|||||||
'int %(funcname)s(struct %(parent_name)s *, int, %(ctype)s *);' %
|
'int %(funcname)s(struct %(parent_name)s *, int, %(ctype)s *);' %
|
||||||
self.GetTranslation({ 'funcname' : funcname }) ]
|
self.GetTranslation({ 'funcname' : funcname }) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def AssignDeclaration(self, funcname):
|
def AssignDeclaration(self, funcname):
|
||||||
code = [ 'int %s(struct %s *, int, const %s);' % (
|
code = [ 'int %s(struct %s *, int, const %s);' % (
|
||||||
funcname, self._struct.Name(), self._ctype ) ]
|
funcname, self._struct.Name(), self._ctype ) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def AddDeclaration(self, funcname):
|
def AddDeclaration(self, funcname):
|
||||||
code = [
|
code = [
|
||||||
'%(ctype)s %(optpointer)s '
|
'%(ctype)s %(optpointer)s '
|
||||||
'%(funcname)s(struct %(parent_name)s *msg%(optaddarg)s);' % \
|
'%(funcname)s(struct %(parent_name)s *msg%(optaddarg)s);' % \
|
||||||
self.GetTranslation({ 'funcname' : funcname }) ]
|
self.GetTranslation({ 'funcname' : funcname }) ]
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeGet(self):
|
def CodeGet(self):
|
||||||
code = """int
|
code = """int
|
||||||
%(parent_name)s_%(name)s_get(struct %(parent_name)s *msg, int offset,
|
%(parent_name)s_%(name)s_get(struct %(parent_name)s *msg, int offset,
|
||||||
@ -1086,7 +1086,7 @@ class EntryArray(Entry):
|
|||||||
}""" % self.GetTranslation()
|
}""" % self.GetTranslation()
|
||||||
|
|
||||||
return code.split('\n')
|
return code.split('\n')
|
||||||
|
|
||||||
def CodeAssign(self):
|
def CodeAssign(self):
|
||||||
code = [
|
code = [
|
||||||
'int',
|
'int',
|
||||||
@ -1108,7 +1108,7 @@ class EntryArray(Entry):
|
|||||||
'}' ], self.GetTranslation())
|
'}' ], self.GetTranslation())
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeAdd(self):
|
def CodeAdd(self):
|
||||||
codearrayadd = self._entry.CodeArrayAdd(
|
codearrayadd = self._entry.CodeArrayAdd(
|
||||||
'msg->%(name)s_data[msg->%(name)s_length - 1]' % self.GetTranslation(),
|
'msg->%(name)s_data[msg->%(name)s_length - 1]' % self.GetTranslation(),
|
||||||
@ -1131,7 +1131,7 @@ class EntryArray(Entry):
|
|||||||
' }' ]
|
' }' ]
|
||||||
|
|
||||||
code = TranslateList(code, self.GetTranslation())
|
code = TranslateList(code, self.GetTranslation())
|
||||||
|
|
||||||
code += map(lambda x: ' ' + x, codearrayadd)
|
code += map(lambda x: ' ' + x, codearrayadd)
|
||||||
|
|
||||||
code += TranslateList([
|
code += TranslateList([
|
||||||
@ -1167,7 +1167,7 @@ class EntryArray(Entry):
|
|||||||
'}' ]
|
'}' ]
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
|
||||||
translate = self.GetTranslation({ 'var' : var_name,
|
translate = self.GetTranslation({ 'var' : var_name,
|
||||||
'buf' : buf,
|
'buf' : buf,
|
||||||
@ -1209,7 +1209,7 @@ class EntryArray(Entry):
|
|||||||
]
|
]
|
||||||
|
|
||||||
code = "\n".join(code) % self.GetTranslation({ 'var' : var_name })
|
code = "\n".join(code) % self.GetTranslation({ 'var' : var_name })
|
||||||
|
|
||||||
return code.split('\n')
|
return code.split('\n')
|
||||||
|
|
||||||
def CodeClear(self, structname):
|
def CodeClear(self, structname):
|
||||||
@ -1231,8 +1231,8 @@ class EntryArray(Entry):
|
|||||||
code += map(lambda x: ' ' + x, codearrayfree)
|
code += map(lambda x: ' ' + x, codearrayfree)
|
||||||
code += [
|
code += [
|
||||||
' }' ]
|
' }' ]
|
||||||
|
|
||||||
code += TranslateList([
|
code += TranslateList([
|
||||||
' free(%(structname)s->%(name)s_data);',
|
' free(%(structname)s->%(name)s_data);',
|
||||||
' %(structname)s->%(name)s_data = NULL;',
|
' %(structname)s->%(name)s_data = NULL;',
|
||||||
' %(structname)s->%(name)s_set = 0;',
|
' %(structname)s->%(name)s_set = 0;',
|
||||||
@ -1242,7 +1242,7 @@ class EntryArray(Entry):
|
|||||||
], translate)
|
], translate)
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def CodeInitialize(self, name):
|
def CodeInitialize(self, name):
|
||||||
code = ['%s->%s_data = NULL;' % (name, self._name),
|
code = ['%s->%s_data = NULL;' % (name, self._name),
|
||||||
'%s->%s_length = 0;' % (name, self._name),
|
'%s->%s_length = 0;' % (name, self._name),
|
||||||
@ -1268,7 +1268,7 @@ class EntryArray(Entry):
|
|||||||
def NormalizeLine(line):
|
def NormalizeLine(line):
|
||||||
global white
|
global white
|
||||||
global cppcomment
|
global cppcomment
|
||||||
|
|
||||||
line = cppcomment.sub('', line)
|
line = cppcomment.sub('', line)
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
line = white.sub(' ', line)
|
line = white.sub(' ', line)
|
||||||
@ -1361,7 +1361,7 @@ def ProcessOneEntry(factory, newstruct, entry):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
structs = []
|
structs = []
|
||||||
|
|
||||||
if optional:
|
if optional:
|
||||||
newentry.MakeOptional()
|
newentry.MakeOptional()
|
||||||
if array:
|
if array:
|
||||||
@ -1422,7 +1422,7 @@ def GetNextStruct(file):
|
|||||||
line = file.readline()
|
line = file.readline()
|
||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
|
|
||||||
line_count += 1
|
line_count += 1
|
||||||
line = line[:-1]
|
line = line[:-1]
|
||||||
|
|
||||||
@ -1448,7 +1448,7 @@ def GetNextStruct(file):
|
|||||||
if re.match(r'#include ["<].*[>"]', line):
|
if re.match(r'#include ["<].*[>"]', line):
|
||||||
cppdirect.append(line)
|
cppdirect.append(line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if re.match(r'^#(if( |def)|endif)', line):
|
if re.match(r'^#(if( |def)|endif)', line):
|
||||||
cppdirect.append(line)
|
cppdirect.append(line)
|
||||||
continue
|
continue
|
||||||
@ -1484,9 +1484,9 @@ def GetNextStruct(file):
|
|||||||
|
|
||||||
# Remove any comments, that might be in there
|
# Remove any comments, that might be in there
|
||||||
data = re.sub(r'/\*.*\*/', '', data)
|
data = re.sub(r'/\*.*\*/', '', data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def Parse(factory, file):
|
def Parse(factory, file):
|
||||||
"""
|
"""
|
||||||
@ -1509,14 +1509,14 @@ def Parse(factory, file):
|
|||||||
class CCodeGenerator:
|
class CCodeGenerator:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def GuardName(self, name):
|
def GuardName(self, name):
|
||||||
name = '_'.join(name.split('.'))
|
name = '_'.join(name.split('.'))
|
||||||
name = '_'.join(name.split('/'))
|
name = '_'.join(name.split('/'))
|
||||||
guard = '_' + name.upper() + '_'
|
guard = '_' + name.upper() + '_'
|
||||||
|
|
||||||
return guard
|
return guard
|
||||||
|
|
||||||
def HeaderPreamble(self, name):
|
def HeaderPreamble(self, name):
|
||||||
guard = self.GuardName(name)
|
guard = self.GuardName(name)
|
||||||
pre = (
|
pre = (
|
||||||
@ -1526,19 +1526,19 @@ class CCodeGenerator:
|
|||||||
'#ifndef %s\n'
|
'#ifndef %s\n'
|
||||||
'#define %s\n\n' ) % (
|
'#define %s\n\n' ) % (
|
||||||
name, guard, guard)
|
name, guard, guard)
|
||||||
|
|
||||||
# insert stdint.h - let's hope everyone has it
|
# insert stdint.h - let's hope everyone has it
|
||||||
pre += (
|
pre += (
|
||||||
'#include <event-config.h>\n'
|
'#include <event-config.h>\n'
|
||||||
'#ifdef _EVENT_HAVE_STDINT_H\n'
|
'#ifdef _EVENT_HAVE_STDINT_H\n'
|
||||||
'#include <stdint.h>\n'
|
'#include <stdint.h>\n'
|
||||||
'#endif\n' )
|
'#endif\n' )
|
||||||
|
|
||||||
for statement in headerdirect:
|
for statement in headerdirect:
|
||||||
pre += '%s\n' % statement
|
pre += '%s\n' % statement
|
||||||
if headerdirect:
|
if headerdirect:
|
||||||
pre += '\n'
|
pre += '\n'
|
||||||
|
|
||||||
pre += (
|
pre += (
|
||||||
'#define EVTAG_HAS(msg, member) ((msg)->member##_set == 1)\n'
|
'#define EVTAG_HAS(msg, member) ((msg)->member##_set == 1)\n'
|
||||||
'#define EVTAG_ASSIGN(msg, member, args...) '
|
'#define EVTAG_ASSIGN(msg, member, args...) '
|
||||||
@ -1549,19 +1549,19 @@ class CCodeGenerator:
|
|||||||
'(*(msg)->base->member##_add)(msg, ## args)\n'
|
'(*(msg)->base->member##_add)(msg, ## args)\n'
|
||||||
'#define EVTAG_LEN(msg, member) ((msg)->member##_length)\n'
|
'#define EVTAG_LEN(msg, member) ((msg)->member##_length)\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
return pre
|
return pre
|
||||||
|
|
||||||
def HeaderPostamble(self, name):
|
def HeaderPostamble(self, name):
|
||||||
guard = self.GuardName(name)
|
guard = self.GuardName(name)
|
||||||
return '#endif /* %s */' % guard
|
return '#endif /* %s */' % guard
|
||||||
|
|
||||||
def BodyPreamble(self, name):
|
def BodyPreamble(self, name):
|
||||||
global _NAME
|
global _NAME
|
||||||
global _VERSION
|
global _VERSION
|
||||||
|
|
||||||
header_file = '.'.join(name.split('.')[:-1]) + '.gen.h'
|
header_file = '.'.join(name.split('.')[:-1]) + '.gen.h'
|
||||||
|
|
||||||
pre = ( '/*\n'
|
pre = ( '/*\n'
|
||||||
' * Automatically generated from %s\n'
|
' * Automatically generated from %s\n'
|
||||||
' * by %s/%s. DO NOT EDIT THIS FILE.\n'
|
' * by %s/%s. DO NOT EDIT THIS FILE.\n'
|
||||||
@ -1575,24 +1575,24 @@ class CCodeGenerator:
|
|||||||
'#include <event2/buffer.h>\n'
|
'#include <event2/buffer.h>\n'
|
||||||
'#include <event2/tag.h>\n\n'
|
'#include <event2/tag.h>\n\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
for statement in cppdirect:
|
for statement in cppdirect:
|
||||||
pre += '%s\n' % statement
|
pre += '%s\n' % statement
|
||||||
|
|
||||||
pre += '\n#include "%s"\n\n' % header_file
|
pre += '\n#include "%s"\n\n' % header_file
|
||||||
|
|
||||||
pre += 'void event_err(int eval, const char *fmt, ...);\n'
|
pre += 'void event_err(int eval, const char *fmt, ...);\n'
|
||||||
pre += 'void event_warn(const char *fmt, ...);\n'
|
pre += 'void event_warn(const char *fmt, ...);\n'
|
||||||
pre += 'void event_errx(int eval, const char *fmt, ...);\n'
|
pre += 'void event_errx(int eval, const char *fmt, ...);\n'
|
||||||
pre += 'void event_warnx(const char *fmt, ...);\n\n'
|
pre += 'void event_warnx(const char *fmt, ...);\n\n'
|
||||||
|
|
||||||
return pre
|
return pre
|
||||||
|
|
||||||
def HeaderFilename(self, filename):
|
def HeaderFilename(self, filename):
|
||||||
return '.'.join(filename.split('.')[:-1]) + '.gen.h'
|
return '.'.join(filename.split('.')[:-1]) + '.gen.h'
|
||||||
|
|
||||||
def CodeFilename(self, filename):
|
def CodeFilename(self, filename):
|
||||||
return '.'.join(filename.split('.')[:-1]) + '.gen.c'
|
return '.'.join(filename.split('.')[:-1]) + '.gen.c'
|
||||||
|
|
||||||
def Struct(self, name):
|
def Struct(self, name):
|
||||||
return StructCCode(name)
|
return StructCCode(name)
|
||||||
@ -1652,7 +1652,7 @@ def Generate(factory, filename):
|
|||||||
for entry in entities:
|
for entry in entities:
|
||||||
entry.PrintCode(impl_fp)
|
entry.PrintCode(impl_fp)
|
||||||
impl_fp.close()
|
impl_fp.close()
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
if len(argv) < 2 or not argv[1]:
|
if len(argv) < 2 or not argv[1]:
|
||||||
print >>sys.stderr, 'Need RPC description file as first argument.'
|
print >>sys.stderr, 'Need RPC description file as first argument.'
|
||||||
|
@ -496,7 +496,7 @@ evtag_unmarshal_fixed(struct evbuffer *src, ev_uint32_t need_tag, void *data,
|
|||||||
|
|
||||||
if (tag_len != len)
|
if (tag_len != len)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
evbuffer_remove(src, data, len);
|
evbuffer_remove(src, data, len);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
12
evport.c
12
evport.c
@ -21,7 +21,7 @@
|
|||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -41,7 +41,7 @@
|
|||||||
*
|
*
|
||||||
* evport_add and evport_del update this data structure. evport_dispatch uses it
|
* evport_add and evport_del update this data structure. evport_dispatch uses it
|
||||||
* to determine where to callback when an event occurs (which it gets from
|
* to determine where to callback when an event occurs (which it gets from
|
||||||
* port_getn).
|
* port_getn).
|
||||||
*
|
*
|
||||||
* Helper functions are used: grow() grows the file descriptor array as
|
* Helper functions are used: grow() grows the file descriptor array as
|
||||||
* necessary when large fd's come in. reassociate() takes care of maintaining
|
* necessary when large fd's come in. reassociate() takes care of maintaining
|
||||||
@ -220,7 +220,7 @@ grow(struct evport_data *epdp, int factor)
|
|||||||
if (NULL == tmp)
|
if (NULL == tmp)
|
||||||
return -1;
|
return -1;
|
||||||
epdp->ed_fds = tmp;
|
epdp->ed_fds = tmp;
|
||||||
memset((char*) (epdp->ed_fds + oldsize), 0,
|
memset((char*) (epdp->ed_fds + oldsize), 0,
|
||||||
(newsize - oldsize)*sizeof(struct fd_info));
|
(newsize - oldsize)*sizeof(struct fd_info));
|
||||||
epdp->ed_nevents = newsize;
|
epdp->ed_nevents = newsize;
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ evport_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
|
if ((res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
|
||||||
(unsigned int *) &nevents, ts_p)) == -1) {
|
(unsigned int *) &nevents, ts_p)) == -1) {
|
||||||
if (errno == EINTR || errno == EAGAIN) {
|
if (errno == EINTR || errno == EAGAIN) {
|
||||||
evsig_process(base);
|
evsig_process(base);
|
||||||
@ -318,7 +318,7 @@ evport_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
} else if (base->sig.evsig_caught) {
|
} else if (base->sig.evsig_caught) {
|
||||||
evsig_process(base);
|
evsig_process(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
event_debug(("%s: port_getn reports %d events", __func__, nevents));
|
event_debug(("%s: port_getn reports %d events", __func__, nevents));
|
||||||
|
|
||||||
for (i = 0; i < nevents; ++i) {
|
for (i = 0; i < nevents; ++i) {
|
||||||
@ -331,7 +331,7 @@ evport_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
epdp->ed_pending[i] = fd;
|
epdp->ed_pending[i] = fd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Figure out what kind of event it was
|
* Figure out what kind of event it was
|
||||||
* (because we have to pass this to the callback)
|
* (because we have to pass this to the callback)
|
||||||
*/
|
*/
|
||||||
res = 0;
|
res = 0;
|
||||||
|
22
evrpc.c
22
evrpc.c
@ -132,7 +132,7 @@ evrpc_add_hook(void *vbase,
|
|||||||
|
|
||||||
hook = mm_calloc(1, sizeof(struct evrpc_hook));
|
hook = mm_calloc(1, sizeof(struct evrpc_hook));
|
||||||
assert(hook != NULL);
|
assert(hook != NULL);
|
||||||
|
|
||||||
hook->process = cb;
|
hook->process = cb;
|
||||||
hook->process_arg = cb_arg;
|
hook->process_arg = cb_arg;
|
||||||
TAILQ_INSERT_TAIL(head, hook, next);
|
TAILQ_INSERT_TAIL(head, hook, next);
|
||||||
@ -234,7 +234,7 @@ evrpc_register_rpc(struct evrpc_base *base, struct evrpc *rpc,
|
|||||||
constructed_uri,
|
constructed_uri,
|
||||||
evrpc_request_cb,
|
evrpc_request_cb,
|
||||||
rpc);
|
rpc);
|
||||||
|
|
||||||
mm_free(constructed_uri);
|
mm_free(constructed_uri);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@ -256,7 +256,7 @@ evrpc_unregister_rpc(struct evrpc_base *base, const char *name)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
TAILQ_REMOVE(&base->registered_rpcs, rpc, next);
|
TAILQ_REMOVE(&base->registered_rpcs, rpc, next);
|
||||||
|
|
||||||
mm_free((char *)rpc->uri);
|
mm_free((char *)rpc->uri);
|
||||||
mm_free(rpc);
|
mm_free(rpc);
|
||||||
|
|
||||||
@ -558,20 +558,20 @@ evrpc_pool_add_connection(struct evrpc_pool *pool,
|
|||||||
if (pool->base != NULL)
|
if (pool->base != NULL)
|
||||||
evhttp_connection_set_base(connection, pool->base);
|
evhttp_connection_set_base(connection, pool->base);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* unless a timeout was specifically set for a connection,
|
* unless a timeout was specifically set for a connection,
|
||||||
* the connection inherits the timeout from the pool.
|
* the connection inherits the timeout from the pool.
|
||||||
*/
|
*/
|
||||||
if (connection->timeout == -1)
|
if (connection->timeout == -1)
|
||||||
connection->timeout = pool->timeout;
|
connection->timeout = pool->timeout;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we have any requests pending, schedule them with the new
|
* if we have any requests pending, schedule them with the new
|
||||||
* connections.
|
* connections.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (TAILQ_FIRST(&pool->requests) != NULL) {
|
if (TAILQ_FIRST(&pool->requests) != NULL) {
|
||||||
struct evrpc_request_wrapper *request =
|
struct evrpc_request_wrapper *request =
|
||||||
TAILQ_FIRST(&pool->requests);
|
TAILQ_FIRST(&pool->requests);
|
||||||
TAILQ_REMOVE(&pool->requests, request, next);
|
TAILQ_REMOVE(&pool->requests, request, next);
|
||||||
evrpc_schedule_request(connection, request);
|
evrpc_schedule_request(connection, request);
|
||||||
@ -617,7 +617,7 @@ evrpc_pool_find_connection(struct evrpc_pool *pool)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Prototypes responsible for evrpc scheduling and hooking
|
* Prototypes responsible for evrpc scheduling and hooking
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void evrpc_schedule_request_closure(void *ctx, enum EVRPC_HOOK_RESULT);
|
static void evrpc_schedule_request_closure(void *ctx, enum EVRPC_HOOK_RESULT);
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ evrpc_schedule_request_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (pool->timeout > 0) {
|
if (pool->timeout > 0) {
|
||||||
/*
|
/*
|
||||||
* a timeout after which the whole rpc is going to be aborted.
|
* a timeout after which the whole rpc is going to be aborted.
|
||||||
*/
|
*/
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -775,7 +775,7 @@ evrpc_make_request(struct evrpc_request_wrapper *ctx)
|
|||||||
/* we better have some available connections on the pool */
|
/* we better have some available connections on the pool */
|
||||||
assert(TAILQ_FIRST(&pool->connections) != NULL);
|
assert(TAILQ_FIRST(&pool->connections) != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if no connection is available, we queue the request on the pool,
|
* if no connection is available, we queue the request on the pool,
|
||||||
* the next time a connection is empty, the rpc will be send on that.
|
* the next time a connection is empty, the rpc will be send on that.
|
||||||
*/
|
*/
|
||||||
@ -830,7 +830,7 @@ evrpc_reply_done(struct evhttp_request *req, void *arg)
|
|||||||
struct evrpc_request_wrapper *ctx = arg;
|
struct evrpc_request_wrapper *ctx = arg;
|
||||||
struct evrpc_pool *pool = ctx->pool;
|
struct evrpc_pool *pool = ctx->pool;
|
||||||
int hook_res = EVRPC_CONTINUE;
|
int hook_res = EVRPC_CONTINUE;
|
||||||
|
|
||||||
/* cancel any timeout we might have scheduled */
|
/* cancel any timeout we might have scheduled */
|
||||||
event_del(&ctx->ev_timeout);
|
event_del(&ctx->ev_timeout);
|
||||||
|
|
||||||
@ -907,7 +907,7 @@ evrpc_reply_done_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
(*ctx->cb)(&status, ctx->request, ctx->reply, ctx->cb_arg);
|
(*ctx->cb)(&status, ctx->request, ctx->reply, ctx->cb_arg);
|
||||||
|
|
||||||
evrpc_request_wrapper_free(ctx);
|
evrpc_request_wrapper_free(ctx);
|
||||||
|
|
||||||
/* the http layer owned the orignal request structure, but if we
|
/* the http layer owned the orignal request structure, but if we
|
||||||
|
2
evutil.c
2
evutil.c
@ -184,7 +184,7 @@ evutil_make_socket_nonblocking(evutil_socket_t fd)
|
|||||||
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
|
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
|
||||||
event_warn("fcntl(O_NONBLOCK)");
|
event_warn("fcntl(O_NONBLOCK)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
112
http.c
112
http.c
@ -109,11 +109,11 @@
|
|||||||
#define NI_NUMERICSERV 2
|
#define NI_NUMERICSERV 2
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fake_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
fake_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
||||||
size_t hostlen, char *serv, size_t servlen, int flags)
|
size_t hostlen, char *serv, size_t servlen, int flags)
|
||||||
{
|
{
|
||||||
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
||||||
|
|
||||||
if (serv != NULL) {
|
if (serv != NULL) {
|
||||||
char tmpserv[16];
|
char tmpserv[16];
|
||||||
evutil_snprintf(tmpserv, sizeof(tmpserv),
|
evutil_snprintf(tmpserv, sizeof(tmpserv),
|
||||||
@ -131,11 +131,11 @@ fake_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
|||||||
return (0);
|
return (0);
|
||||||
} else {
|
} else {
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
hp = gethostbyaddr((char *)&sin->sin_addr,
|
hp = gethostbyaddr((char *)&sin->sin_addr,
|
||||||
sizeof(struct in_addr), AF_INET);
|
sizeof(struct in_addr), AF_INET);
|
||||||
if (hp == NULL)
|
if (hp == NULL)
|
||||||
return (-2);
|
return (-2);
|
||||||
|
|
||||||
if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
|
if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
|
||||||
return (-1);
|
return (-1);
|
||||||
else
|
else
|
||||||
@ -262,7 +262,7 @@ html_replace(char ch, char *buf)
|
|||||||
/* Echo the character back */
|
/* Echo the character back */
|
||||||
buf[0] = ch;
|
buf[0] = ch;
|
||||||
buf[1] = '\0';
|
buf[1] = '\0';
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ evhttp_add_event(struct event *ev, int timeout, int default_timeout)
|
|||||||
{
|
{
|
||||||
if (timeout != 0) {
|
if (timeout != 0) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
tv.tv_sec = timeout != -1 ? timeout : default_timeout;
|
tv.tv_sec = timeout != -1 ? timeout : default_timeout;
|
||||||
event_add(ev, &tv);
|
event_add(ev, &tv);
|
||||||
@ -396,7 +396,7 @@ evhttp_make_header_request(struct evhttp_connection *evcon,
|
|||||||
struct evhttp_request *req)
|
struct evhttp_request *req)
|
||||||
{
|
{
|
||||||
const char *method;
|
const char *method;
|
||||||
|
|
||||||
evhttp_remove_header(req->output_headers, "Proxy-Connection");
|
evhttp_remove_header(req->output_headers, "Proxy-Connection");
|
||||||
|
|
||||||
/* Generate request line */
|
/* Generate request line */
|
||||||
@ -432,7 +432,7 @@ static int
|
|||||||
evhttp_is_connection_keepalive(struct evkeyvalq* headers)
|
evhttp_is_connection_keepalive(struct evkeyvalq* headers)
|
||||||
{
|
{
|
||||||
const char *connection = evhttp_find_header(headers, "Connection");
|
const char *connection = evhttp_find_header(headers, "Connection");
|
||||||
return (connection != NULL
|
return (connection != NULL
|
||||||
&& strncasecmp(connection, "keep-alive", 10) == 0);
|
&& strncasecmp(connection, "keep-alive", 10) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
|
|||||||
|
|
||||||
if ((req->minor == 1 || is_keepalive) &&
|
if ((req->minor == 1 || is_keepalive) &&
|
||||||
evhttp_response_needs_body(req)) {
|
evhttp_response_needs_body(req)) {
|
||||||
/*
|
/*
|
||||||
* we need to add the content length if the
|
* we need to add the content length if the
|
||||||
* user did not give it, this is required for
|
* user did not give it, this is required for
|
||||||
* persistent connections to work.
|
* persistent connections to work.
|
||||||
@ -533,7 +533,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
|
|||||||
{
|
{
|
||||||
struct evkeyval *header;
|
struct evkeyval *header;
|
||||||
struct evbuffer *output = bufferevent_get_output(evcon->bufev);
|
struct evbuffer *output = bufferevent_get_output(evcon->bufev);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Depending if this is a HTTP request or response, we might need to
|
* Depending if this is a HTTP request or response, we might need to
|
||||||
* add some new headers or remove existing headers.
|
* add some new headers or remove existing headers.
|
||||||
@ -566,7 +566,7 @@ evhttp_connection_incoming_fail(struct evhttp_request *req,
|
|||||||
switch (error) {
|
switch (error) {
|
||||||
case EVCON_HTTP_TIMEOUT:
|
case EVCON_HTTP_TIMEOUT:
|
||||||
case EVCON_HTTP_EOF:
|
case EVCON_HTTP_EOF:
|
||||||
/*
|
/*
|
||||||
* these are cases in which we probably should just
|
* these are cases in which we probably should just
|
||||||
* close the connection and not send a reply. this
|
* close the connection and not send a reply. this
|
||||||
* case may happen when a browser keeps a persistent
|
* case may happen when a browser keeps a persistent
|
||||||
@ -583,13 +583,13 @@ evhttp_connection_incoming_fail(struct evhttp_request *req,
|
|||||||
req->uri = NULL;
|
req->uri = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the callback needs to send a reply, once the reply has
|
* the callback needs to send a reply, once the reply has
|
||||||
* been send, the connection should get freed.
|
* been send, the connection should get freed.
|
||||||
*/
|
*/
|
||||||
(*req->cb)(req, req->cb_arg);
|
(*req->cb)(req, req->cb_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,11 +601,11 @@ evhttp_connection_fail(struct evhttp_connection *evcon,
|
|||||||
void (*cb)(struct evhttp_request *, void *);
|
void (*cb)(struct evhttp_request *, void *);
|
||||||
void *cb_arg;
|
void *cb_arg;
|
||||||
assert(req != NULL);
|
assert(req != NULL);
|
||||||
|
|
||||||
bufferevent_disable(evcon->bufev, EV_READ|EV_WRITE);
|
bufferevent_disable(evcon->bufev, EV_READ|EV_WRITE);
|
||||||
|
|
||||||
if (evcon->flags & EVHTTP_CON_INCOMING) {
|
if (evcon->flags & EVHTTP_CON_INCOMING) {
|
||||||
/*
|
/*
|
||||||
* for incoming requests, there are two different
|
* for incoming requests, there are two different
|
||||||
* failure cases. it's either a network level error
|
* failure cases. it's either a network level error
|
||||||
* or an http layer error. for problems on the network
|
* or an http layer error. for problems on the network
|
||||||
@ -638,7 +638,7 @@ evhttp_connection_fail(struct evhttp_connection *evcon,
|
|||||||
|
|
||||||
/* reset the connection */
|
/* reset the connection */
|
||||||
evhttp_connection_reset(evcon);
|
evhttp_connection_reset(evcon);
|
||||||
|
|
||||||
/* We are trying the next request that was queued on us */
|
/* We are trying the next request that was queued on us */
|
||||||
if (TAILQ_FIRST(&evcon->requests) != NULL)
|
if (TAILQ_FIRST(&evcon->requests) != NULL)
|
||||||
evhttp_connection_connect(evcon);
|
evhttp_connection_connect(evcon);
|
||||||
@ -679,7 +679,7 @@ evhttp_connection_done(struct evhttp_connection *evcon)
|
|||||||
|
|
||||||
evcon->state = EVCON_IDLE;
|
evcon->state = EVCON_IDLE;
|
||||||
|
|
||||||
need_close =
|
need_close =
|
||||||
evhttp_is_connection_close(req->flags, req->input_headers)||
|
evhttp_is_connection_close(req->flags, req->input_headers)||
|
||||||
evhttp_is_connection_close(req->flags, req->output_headers);
|
evhttp_is_connection_close(req->flags, req->output_headers);
|
||||||
|
|
||||||
@ -816,7 +816,7 @@ static void
|
|||||||
evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req)
|
evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req)
|
||||||
{
|
{
|
||||||
struct evbuffer *buf = bufferevent_get_input(evcon->bufev);
|
struct evbuffer *buf = bufferevent_get_input(evcon->bufev);
|
||||||
|
|
||||||
if (req->chunked) {
|
if (req->chunked) {
|
||||||
switch (evhttp_handle_chunked_read(req, buf)) {
|
switch (evhttp_handle_chunked_read(req, buf)) {
|
||||||
case ALL_DATA_READ:
|
case ALL_DATA_READ:
|
||||||
@ -992,14 +992,14 @@ static void
|
|||||||
evhttp_request_dispatch(struct evhttp_connection* evcon)
|
evhttp_request_dispatch(struct evhttp_connection* evcon)
|
||||||
{
|
{
|
||||||
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
||||||
|
|
||||||
/* this should not usually happy but it's possible */
|
/* this should not usually happy but it's possible */
|
||||||
if (req == NULL)
|
if (req == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* delete possible close detection events */
|
/* delete possible close detection events */
|
||||||
evhttp_connection_stop_detectclose(evcon);
|
evhttp_connection_stop_detectclose(evcon);
|
||||||
|
|
||||||
/* we assume that the connection is connected already */
|
/* we assume that the connection is connected already */
|
||||||
assert(evcon->state == EVCON_IDLE);
|
assert(evcon->state == EVCON_IDLE);
|
||||||
|
|
||||||
@ -1130,7 +1130,7 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
|
|||||||
/* For connections from the client, we just
|
/* For connections from the client, we just
|
||||||
* reset the connection so that it becomes
|
* reset the connection so that it becomes
|
||||||
* disconnected.
|
* disconnected.
|
||||||
*/
|
*/
|
||||||
assert(evcon->state == EVCON_IDLE);
|
assert(evcon->state == EVCON_IDLE);
|
||||||
evhttp_connection_reset(evcon);
|
evhttp_connection_reset(evcon);
|
||||||
return;
|
return;
|
||||||
@ -1187,10 +1187,10 @@ evhttp_connection_cb(struct bufferevent *bufev, void *arg)
|
|||||||
evcon);
|
evcon);
|
||||||
|
|
||||||
if (evcon->timeout == -1)
|
if (evcon->timeout == -1)
|
||||||
bufferevent_settimeout(evcon->bufev,
|
bufferevent_settimeout(evcon->bufev,
|
||||||
HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
|
HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
|
||||||
else
|
else
|
||||||
bufferevent_settimeout(evcon->bufev,
|
bufferevent_settimeout(evcon->bufev,
|
||||||
evcon->timeout, evcon->timeout);
|
evcon->timeout, evcon->timeout);
|
||||||
|
|
||||||
/* try to start requests that have queued up on this connection */
|
/* try to start requests that have queued up on this connection */
|
||||||
@ -1524,7 +1524,7 @@ evhttp_get_body_length(struct evhttp_request *req)
|
|||||||
|
|
||||||
content_length = evhttp_find_header(headers, "Content-Length");
|
content_length = evhttp_find_header(headers, "Content-Length");
|
||||||
connection = evhttp_find_header(headers, "Connection");
|
connection = evhttp_find_header(headers, "Connection");
|
||||||
|
|
||||||
if (content_length == NULL && connection == NULL)
|
if (content_length == NULL && connection == NULL)
|
||||||
req->ntoread = -1;
|
req->ntoread = -1;
|
||||||
else if (content_length == NULL &&
|
else if (content_length == NULL &&
|
||||||
@ -1546,7 +1546,7 @@ evhttp_get_body_length(struct evhttp_request *req)
|
|||||||
}
|
}
|
||||||
req->ntoread = ntoread;
|
req->ntoread = ntoread;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_debug(("%s: bytes to read: %d (in buffer %ld)\n",
|
event_debug(("%s: bytes to read: %d (in buffer %ld)\n",
|
||||||
__func__, req->ntoread,
|
__func__, req->ntoread,
|
||||||
EVBUFFER_LENGTH(bufferevent_get_input(req->evcon->bufev))));
|
EVBUFFER_LENGTH(bufferevent_get_input(req->evcon->bufev))));
|
||||||
@ -1558,7 +1558,7 @@ static void
|
|||||||
evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
|
evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
|
||||||
{
|
{
|
||||||
const char *xfer_enc;
|
const char *xfer_enc;
|
||||||
|
|
||||||
/* If this is a request without a body, then we are done */
|
/* If this is a request without a body, then we are done */
|
||||||
if (req->kind == EVHTTP_REQUEST &&
|
if (req->kind == EVHTTP_REQUEST &&
|
||||||
(req->type != EVHTTP_REQ_POST && req->type != EVHTTP_REQ_PUT)) {
|
(req->type != EVHTTP_REQ_POST && req->type != EVHTTP_REQ_PUT)) {
|
||||||
@ -1676,7 +1676,7 @@ evhttp_connection_base_new(struct event_base *base,
|
|||||||
const char *address, unsigned short port)
|
const char *address, unsigned short port)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
|
|
||||||
event_debug(("Attempting connection to %s:%d\n", address, port));
|
event_debug(("Attempting connection to %s:%d\n", address, port));
|
||||||
|
|
||||||
if ((evcon = mm_calloc(1, sizeof(struct evhttp_connection))) == NULL) {
|
if ((evcon = mm_calloc(1, sizeof(struct evhttp_connection))) == NULL) {
|
||||||
@ -1712,7 +1712,7 @@ evhttp_connection_base_new(struct event_base *base,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (evcon);
|
return (evcon);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (evcon != NULL)
|
if (evcon != NULL)
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
@ -1736,10 +1736,10 @@ evhttp_connection_set_timeout(struct evhttp_connection *evcon,
|
|||||||
evcon->timeout = timeout_in_secs;
|
evcon->timeout = timeout_in_secs;
|
||||||
|
|
||||||
if (evcon->timeout == -1)
|
if (evcon->timeout == -1)
|
||||||
bufferevent_settimeout(evcon->bufev,
|
bufferevent_settimeout(evcon->bufev,
|
||||||
HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
|
HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
|
||||||
else
|
else
|
||||||
bufferevent_settimeout(evcon->bufev,
|
bufferevent_settimeout(evcon->bufev,
|
||||||
evcon->timeout, evcon->timeout);
|
evcon->timeout, evcon->timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1771,12 +1771,12 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
|
|||||||
{
|
{
|
||||||
if (evcon->state == EVCON_CONNECTING)
|
if (evcon->state == EVCON_CONNECTING)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
evhttp_connection_reset(evcon);
|
evhttp_connection_reset(evcon);
|
||||||
|
|
||||||
assert(!(evcon->flags & EVHTTP_CON_INCOMING));
|
assert(!(evcon->flags & EVHTTP_CON_INCOMING));
|
||||||
evcon->flags |= EVHTTP_CON_OUTGOING;
|
evcon->flags |= EVHTTP_CON_OUTGOING;
|
||||||
|
|
||||||
evcon->fd = bind_socket(
|
evcon->fd = bind_socket(
|
||||||
evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
|
evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
|
||||||
if (evcon->fd == -1) {
|
if (evcon->fd == -1) {
|
||||||
@ -1794,7 +1794,7 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
|
|||||||
|
|
||||||
/* Set up a callback for successful connection setup */
|
/* Set up a callback for successful connection setup */
|
||||||
bufferevent_setfd(evcon->bufev, evcon->fd);
|
bufferevent_setfd(evcon->bufev, evcon->fd);
|
||||||
bufferevent_setcb(evcon->bufev,
|
bufferevent_setcb(evcon->bufev,
|
||||||
NULL /* evhttp_read_cb */,
|
NULL /* evhttp_read_cb */,
|
||||||
evhttp_connection_cb,
|
evhttp_connection_cb,
|
||||||
evhttp_error_cb, evcon);
|
evhttp_error_cb, evcon);
|
||||||
@ -1804,7 +1804,7 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
|
|||||||
bufferevent_enable(evcon->bufev, EV_WRITE);
|
bufferevent_enable(evcon->bufev, EV_WRITE);
|
||||||
|
|
||||||
evcon->state = EVCON_CONNECTING;
|
evcon->state = EVCON_CONNECTING;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1832,11 +1832,11 @@ evhttp_make_request(struct evhttp_connection *evcon,
|
|||||||
req->major = 1;
|
req->major = 1;
|
||||||
req->minor = 1;
|
req->minor = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(req->evcon == NULL);
|
assert(req->evcon == NULL);
|
||||||
req->evcon = evcon;
|
req->evcon = evcon;
|
||||||
assert(!(req->flags & EVHTTP_REQ_OWN_CONNECTION));
|
assert(!(req->flags & EVHTTP_REQ_OWN_CONNECTION));
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&evcon->requests, req, next);
|
TAILQ_INSERT_TAIL(&evcon->requests, req, next);
|
||||||
|
|
||||||
/* If the connection object is not connected; make it so */
|
/* If the connection object is not connected; make it so */
|
||||||
@ -1913,7 +1913,7 @@ evhttp_send_done(struct evhttp_connection *evcon, void *arg)
|
|||||||
if (need_close) {
|
if (need_close) {
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we have a persistent connection; try to accept another request. */
|
/* we have a persistent connection; try to accept another request. */
|
||||||
if (evhttp_associate_new_request_with_connection(evcon) == -1) {
|
if (evhttp_associate_new_request_with_connection(evcon) == -1) {
|
||||||
@ -1962,7 +1962,7 @@ evhttp_send(struct evhttp_request *req, struct evbuffer *databuf)
|
|||||||
/* xxx: not sure if we really should expose the data buffer this way */
|
/* xxx: not sure if we really should expose the data buffer this way */
|
||||||
if (databuf != NULL)
|
if (databuf != NULL)
|
||||||
evbuffer_add_buffer(req->output_buffer, databuf);
|
evbuffer_add_buffer(req->output_buffer, databuf);
|
||||||
|
|
||||||
/* Adds headers to the response */
|
/* Adds headers to the response */
|
||||||
evhttp_make_header(evcon, req);
|
evhttp_make_header(evcon, req);
|
||||||
|
|
||||||
@ -1974,7 +1974,7 @@ evhttp_send_reply(struct evhttp_request *req, int code, const char *reason,
|
|||||||
struct evbuffer *databuf)
|
struct evbuffer *databuf)
|
||||||
{
|
{
|
||||||
evhttp_response_code(req, code, reason);
|
evhttp_response_code(req, code, reason);
|
||||||
|
|
||||||
evhttp_send(req, databuf);
|
evhttp_send(req, databuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2055,7 +2055,7 @@ evhttp_send_page(struct evhttp_request *req, struct evbuffer *databuf)
|
|||||||
req->major = 1;
|
req->major = 1;
|
||||||
req->minor = 1;
|
req->minor = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->kind != EVHTTP_RESPONSE)
|
if (req->kind != EVHTTP_RESPONSE)
|
||||||
evhttp_response_code(req, 200, "OK");
|
evhttp_response_code(req, 200, "OK");
|
||||||
|
|
||||||
@ -2108,7 +2108,7 @@ evhttp_encode_uri(const char *uri)
|
|||||||
evbuffer_add(buf, "", 1);
|
evbuffer_add(buf, "", 1);
|
||||||
p = mm_strdup((char *)EVBUFFER_DATA(buf));
|
p = mm_strdup((char *)EVBUFFER_DATA(buf));
|
||||||
evbuffer_free(buf);
|
evbuffer_free(buf);
|
||||||
|
|
||||||
return (p);
|
return (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2141,17 +2141,17 @@ char *
|
|||||||
evhttp_decode_uri(const char *uri)
|
evhttp_decode_uri(const char *uri)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if ((ret = mm_malloc(strlen(uri) + 1)) == NULL)
|
if ((ret = mm_malloc(strlen(uri) + 1)) == NULL)
|
||||||
event_err(1, "%s: malloc(%lu)", __func__,
|
event_err(1, "%s: malloc(%lu)", __func__,
|
||||||
(unsigned long)(strlen(uri) + 1));
|
(unsigned long)(strlen(uri) + 1));
|
||||||
|
|
||||||
evhttp_decode_uri_internal(uri, strlen(uri), ret);
|
evhttp_decode_uri_internal(uri, strlen(uri), ret);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to parse out arguments in a query.
|
* Helper function to parse out arguments in a query.
|
||||||
* The arguments are separated by key and value.
|
* The arguments are separated by key and value.
|
||||||
* URI should already be decoded.
|
* URI should already be decoded.
|
||||||
@ -2236,7 +2236,7 @@ static int
|
|||||||
prefix_suffix_match(const char *pattern, const char *name, int ignorecase)
|
prefix_suffix_match(const char *pattern, const char *name, int ignorecase)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (c = *pattern++) {
|
switch (c = *pattern++) {
|
||||||
case '\0':
|
case '\0':
|
||||||
@ -2357,7 +2357,7 @@ evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = evhttp_accept_socket(http, fd);
|
res = evhttp_accept_socket(http, fd);
|
||||||
|
|
||||||
if (res != -1)
|
if (res != -1)
|
||||||
event_debug(("Bound to port %d - Awaiting connections ... ",
|
event_debug(("Bound to port %d - Awaiting connections ... ",
|
||||||
port));
|
port));
|
||||||
@ -2480,7 +2480,7 @@ evhttp_free(struct evhttp* http)
|
|||||||
|
|
||||||
if (http->vhost_pattern != NULL)
|
if (http->vhost_pattern != NULL)
|
||||||
mm_free(http->vhost_pattern);
|
mm_free(http->vhost_pattern);
|
||||||
|
|
||||||
mm_free(http);
|
mm_free(http);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2734,7 +2734,7 @@ evhttp_get_request_connection(
|
|||||||
|
|
||||||
evcon->flags |= EVHTTP_CON_INCOMING;
|
evcon->flags |= EVHTTP_CON_INCOMING;
|
||||||
evcon->state = EVCON_READING_FIRSTLINE;
|
evcon->state = EVCON_READING_FIRSTLINE;
|
||||||
|
|
||||||
evcon->fd = fd;
|
evcon->fd = fd;
|
||||||
|
|
||||||
bufferevent_setfd(evcon->bufev, fd);
|
bufferevent_setfd(evcon->bufev, fd);
|
||||||
@ -2752,17 +2752,17 @@ evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon)
|
|||||||
|
|
||||||
req->evcon = evcon; /* the request ends up owning the connection */
|
req->evcon = evcon; /* the request ends up owning the connection */
|
||||||
req->flags |= EVHTTP_REQ_OWN_CONNECTION;
|
req->flags |= EVHTTP_REQ_OWN_CONNECTION;
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&evcon->requests, req, next);
|
TAILQ_INSERT_TAIL(&evcon->requests, req, next);
|
||||||
|
|
||||||
req->kind = EVHTTP_REQUEST;
|
req->kind = EVHTTP_REQUEST;
|
||||||
|
|
||||||
if ((req->remote_host = mm_strdup(evcon->address)) == NULL)
|
if ((req->remote_host = mm_strdup(evcon->address)) == NULL)
|
||||||
event_err(1, "%s: strdup", __func__);
|
event_err(1, "%s: strdup", __func__);
|
||||||
req->remote_port = evcon->port;
|
req->remote_port = evcon->port;
|
||||||
|
|
||||||
evhttp_start_read(evcon);
|
evhttp_start_read(evcon);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2783,13 +2783,13 @@ evhttp_get_request(struct evhttp *http, evutil_socket_t fd,
|
|||||||
if (http->timeout != -1)
|
if (http->timeout != -1)
|
||||||
evhttp_connection_set_timeout(evcon, http->timeout);
|
evhttp_connection_set_timeout(evcon, http->timeout);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we want to accept more than one request on a connection,
|
* if we want to accept more than one request on a connection,
|
||||||
* we need to know which http server it belongs to.
|
* we need to know which http server it belongs to.
|
||||||
*/
|
*/
|
||||||
evcon->http_server = http;
|
evcon->http_server = http;
|
||||||
TAILQ_INSERT_TAIL(&http->connections, evcon, next);
|
TAILQ_INSERT_TAIL(&http->connections, evcon, next);
|
||||||
|
|
||||||
if (evhttp_associate_new_request_with_connection(evcon) == -1)
|
if (evhttp_associate_new_request_with_connection(evcon) == -1)
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
}
|
}
|
||||||
@ -2838,7 +2838,7 @@ name_from_addr(struct sockaddr *sa, socklen_t salen,
|
|||||||
ni_result = getnameinfo(sa, salen,
|
ni_result = getnameinfo(sa, salen,
|
||||||
ntop, sizeof(ntop), strport, sizeof(strport),
|
ntop, sizeof(ntop), strport, sizeof(strport),
|
||||||
NI_NUMERICHOST|NI_NUMERICSERV);
|
NI_NUMERICHOST|NI_NUMERICSERV);
|
||||||
|
|
||||||
if (ni_result != 0) {
|
if (ni_result != 0) {
|
||||||
if (ni_result == EAI_SYSTEM)
|
if (ni_result == EAI_SYSTEM)
|
||||||
event_err(1, "getnameinfo failed");
|
event_err(1, "getnameinfo failed");
|
||||||
@ -2953,7 +2953,7 @@ bind_socket(const char *address, ev_uint16_t port, int reuse)
|
|||||||
/* just create an unbound socket */
|
/* just create an unbound socket */
|
||||||
if (address == NULL && port == 0)
|
if (address == NULL && port == 0)
|
||||||
return bind_socket_ai(NULL, 0);
|
return bind_socket_ai(NULL, 0);
|
||||||
|
|
||||||
aitop = make_addrinfo(address, port);
|
aitop = make_addrinfo(address, port);
|
||||||
|
|
||||||
if (aitop == NULL)
|
if (aitop == NULL)
|
||||||
|
@ -94,7 +94,7 @@ int event_base_dispatch(struct event_base *);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Get the kernel event notification mechanism used by libevent.
|
Get the kernel event notification mechanism used by libevent.
|
||||||
|
|
||||||
@param eb the event_base structure returned by event_base_new()
|
@param eb the event_base structure returned by event_base_new()
|
||||||
@return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
|
@return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
|
||||||
*/
|
*/
|
||||||
|
@ -126,7 +126,7 @@ void evhttp_set_cb(struct evhttp *, const char *,
|
|||||||
/** Removes the callback for a specified URI */
|
/** Removes the callback for a specified URI */
|
||||||
int evhttp_del_cb(struct evhttp *, const char *);
|
int evhttp_del_cb(struct evhttp *, const char *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set a callback for all requests that are not caught by specific callbacks
|
Set a callback for all requests that are not caught by specific callbacks
|
||||||
|
|
||||||
Invokes the specified callback for all requests that do not match any of
|
Invokes the specified callback for all requests that do not match any of
|
||||||
@ -332,9 +332,9 @@ void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
|
|||||||
void evhttp_connection_get_peer(struct evhttp_connection *evcon,
|
void evhttp_connection_get_peer(struct evhttp_connection *evcon,
|
||||||
char **address, ev_uint16_t *port);
|
char **address, ev_uint16_t *port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Make an HTTP request over the specified connection.
|
Make an HTTP request over the specified connection.
|
||||||
|
|
||||||
The connection gets ownership of the request.
|
The connection gets ownership of the request.
|
||||||
|
|
||||||
@param evcon the evhttp_connection object over which to send the request
|
@param evcon the evhttp_connection object over which to send the request
|
||||||
@ -350,7 +350,7 @@ int evhttp_make_request(struct evhttp_connection *evcon,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Cancels a pending HTTP request.
|
Cancels a pending HTTP request.
|
||||||
|
|
||||||
Cancels an ongoing HTTP request. The callback associated with this request
|
Cancels an ongoing HTTP request. The callback associated with this request
|
||||||
is not executed and the request object is freed. If the request is
|
is not executed and the request object is freed. If the request is
|
||||||
currently being processed, e.g. it is ongoing, the corresponding
|
currently being processed, e.g. it is ongoing, the corresponding
|
||||||
@ -379,7 +379,7 @@ struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Finds the value belonging to a header.
|
Finds the value belonging to a header.
|
||||||
|
|
||||||
@param headers the evkeyvalq object in which to find the header
|
@param headers the evkeyvalq object in which to find the header
|
||||||
@param key the name of the header to find
|
@param key the name of the header to find
|
||||||
@returns a pointer to the value for the header or NULL if the header
|
@returns a pointer to the value for the header or NULL if the header
|
||||||
@ -391,7 +391,7 @@ const char *evhttp_find_header(const struct evkeyvalq *headers,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Removes a header from a list of exisiting headers.
|
Removes a header from a list of exisiting headers.
|
||||||
|
|
||||||
@param headers the evkeyvalq object from which to remove a header
|
@param headers the evkeyvalq object from which to remove a header
|
||||||
@param key the name of the header to remove
|
@param key the name of the header to remove
|
||||||
@returns 0 if the header was removed, -1 otherwise.
|
@returns 0 if the header was removed, -1 otherwise.
|
||||||
@ -401,7 +401,7 @@ int evhttp_remove_header(struct evkeyvalq *headers, const char *key);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Adds a header to a list of exisiting headers.
|
Adds a header to a list of exisiting headers.
|
||||||
|
|
||||||
@param headers the evkeyvalq object to which to add a header
|
@param headers the evkeyvalq object to which to add a header
|
||||||
@param key the name of the header
|
@param key the name of the header
|
||||||
@param value the value belonging to the header
|
@param value the value belonging to the header
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#define _EVENT2_THREAD_H_
|
#define _EVENT2_THREAD_H_
|
||||||
|
|
||||||
/** @file thread.h
|
/** @file thread.h
|
||||||
|
|
||||||
Functions for multi-threaded applications using libevent.
|
Functions for multi-threaded applications using libevent.
|
||||||
|
|
||||||
When using a multi-threaded application in which multiple threads
|
When using a multi-threaded application in which multiple threads
|
||||||
|
24
kqueue.c
24
kqueue.c
@ -116,7 +116,7 @@ kq_init(struct event_base *base)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
/* Initalize the kernel queue */
|
/* Initalize the kernel queue */
|
||||||
|
|
||||||
if ((kq = kqueue()) == -1) {
|
if ((kq = kqueue()) == -1) {
|
||||||
event_warn("kqueue");
|
event_warn("kqueue");
|
||||||
mm_free (kqueueop);
|
mm_free (kqueueop);
|
||||||
@ -145,7 +145,7 @@ kq_init(struct event_base *base)
|
|||||||
kqueueop->changes[0].ident = -1;
|
kqueueop->changes[0].ident = -1;
|
||||||
kqueueop->changes[0].filter = EVFILT_READ;
|
kqueueop->changes[0].filter = EVFILT_READ;
|
||||||
kqueueop->changes[0].flags = EV_ADD;
|
kqueueop->changes[0].flags = EV_ADD;
|
||||||
/*
|
/*
|
||||||
* If kqueue works, then kevent will succeed, and it will
|
* If kqueue works, then kevent will succeed, and it will
|
||||||
* stick an error in events[0]. If kqueue is broken, then
|
* stick an error in events[0]. If kqueue is broken, then
|
||||||
* kevent will fail.
|
* kevent will fail.
|
||||||
@ -206,7 +206,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
|
|||||||
memcpy(&kqop->changes[kqop->nchanges++], kev, sizeof(struct kevent));
|
memcpy(&kqop->changes[kqop->nchanges++], kev, sizeof(struct kevent));
|
||||||
|
|
||||||
event_debug(("%s: fd %d %s%s",
|
event_debug(("%s: fd %d %s%s",
|
||||||
__func__, (int)kev->ident,
|
__func__, (int)kev->ident,
|
||||||
kev->filter == EVFILT_READ ? "EVFILT_READ" : "EVFILT_WRITE",
|
kev->filter == EVFILT_READ ? "EVFILT_READ" : "EVFILT_WRITE",
|
||||||
kev->flags == EV_DELETE ? " (del)" : ""));
|
kev->flags == EV_DELETE ? " (del)" : ""));
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ kq_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
int which = 0;
|
int which = 0;
|
||||||
|
|
||||||
if (events[i].flags & EV_ERROR) {
|
if (events[i].flags & EV_ERROR) {
|
||||||
/*
|
/*
|
||||||
* Error messages that can happen, when a delete fails.
|
* Error messages that can happen, when a delete fails.
|
||||||
* EBADF happens when the file discriptor has been
|
* EBADF happens when the file discriptor has been
|
||||||
* closed,
|
* closed,
|
||||||
@ -311,7 +311,7 @@ kq_add(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
kev.flags = EV_ADD;
|
kev.flags = EV_ADD;
|
||||||
if (events & EV_ET)
|
if (events & EV_ET)
|
||||||
kev.flags |= EV_CLEAR;
|
kev.flags |= EV_CLEAR;
|
||||||
|
|
||||||
if (kq_insert(kqop, &kev) == -1)
|
if (kq_insert(kqop, &kev) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ kq_add(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
kev.flags = EV_ADD;
|
kev.flags = EV_ADD;
|
||||||
if (events & EV_ET)
|
if (events & EV_ET)
|
||||||
kev.flags |= EV_CLEAR;
|
kev.flags |= EV_CLEAR;
|
||||||
|
|
||||||
if (kq_insert(kqop, &kev) == -1)
|
if (kq_insert(kqop, &kev) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ kq_del(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
kev.ident = fd;
|
kev.ident = fd;
|
||||||
kev.filter = EVFILT_READ;
|
kev.filter = EVFILT_READ;
|
||||||
kev.flags = EV_DELETE;
|
kev.flags = EV_DELETE;
|
||||||
|
|
||||||
if (kq_insert(kqop, &kev) == -1)
|
if (kq_insert(kqop, &kev) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -353,7 +353,7 @@ kq_del(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
kev.ident = fd;
|
kev.ident = fd;
|
||||||
kev.filter = EVFILT_WRITE;
|
kev.filter = EVFILT_WRITE;
|
||||||
kev.flags = EV_DELETE;
|
kev.flags = EV_DELETE;
|
||||||
|
|
||||||
if (kq_insert(kqop, &kev) == -1)
|
if (kq_insert(kqop, &kev) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -386,18 +386,18 @@ kq_sig_add(struct event_base *base, int nsignal, short old, short events, void *
|
|||||||
(void)p;
|
(void)p;
|
||||||
|
|
||||||
assert(nsignal >= 0 && nsignal < NSIG);
|
assert(nsignal >= 0 && nsignal < NSIG);
|
||||||
|
|
||||||
memset(&kev, 0, sizeof(kev));
|
memset(&kev, 0, sizeof(kev));
|
||||||
kev.ident = nsignal;
|
kev.ident = nsignal;
|
||||||
kev.filter = EVFILT_SIGNAL;
|
kev.filter = EVFILT_SIGNAL;
|
||||||
kev.flags = EV_ADD;
|
kev.flags = EV_ADD;
|
||||||
|
|
||||||
/* Be ready for the signal if it is sent any
|
/* Be ready for the signal if it is sent any
|
||||||
* time between now and the next call to
|
* time between now and the next call to
|
||||||
* kq_dispatch. */
|
* kq_dispatch. */
|
||||||
if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1)
|
if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (_evsig_set_handler(base, nsignal, kq_sighandler) == -1)
|
if (_evsig_set_handler(base, nsignal, kq_sighandler) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ kq_sig_del(struct event_base *base, int nsignal, short old, short events, void *
|
|||||||
kev.ident = nsignal;
|
kev.ident = nsignal;
|
||||||
kev.filter = EVFILT_SIGNAL;
|
kev.filter = EVFILT_SIGNAL;
|
||||||
kev.flags = EV_DELETE;
|
kev.flags = EV_DELETE;
|
||||||
|
|
||||||
/* Because we insert signal events
|
/* Because we insert signal events
|
||||||
* immediately, we need to delete them
|
* immediately, we need to delete them
|
||||||
* immediately, too */
|
* immediately, too */
|
||||||
|
12
log.c
12
log.c
@ -70,7 +70,7 @@ void
|
|||||||
event_err(int eval, const char *fmt, ...)
|
event_err(int eval, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warn_helper(_EVENT_LOG_ERR, strerror(errno), fmt, ap);
|
_warn_helper(_EVENT_LOG_ERR, strerror(errno), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -81,7 +81,7 @@ void
|
|||||||
event_warn(const char *fmt, ...)
|
event_warn(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warn_helper(_EVENT_LOG_WARN, strerror(errno), fmt, ap);
|
_warn_helper(_EVENT_LOG_WARN, strerror(errno), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -114,7 +114,7 @@ void
|
|||||||
event_errx(int eval, const char *fmt, ...)
|
event_errx(int eval, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warn_helper(_EVENT_LOG_ERR, NULL, fmt, ap);
|
_warn_helper(_EVENT_LOG_ERR, NULL, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -125,7 +125,7 @@ void
|
|||||||
event_warnx(const char *fmt, ...)
|
event_warnx(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warn_helper(_EVENT_LOG_WARN, NULL, fmt, ap);
|
_warn_helper(_EVENT_LOG_WARN, NULL, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -135,7 +135,7 @@ void
|
|||||||
event_msgx(const char *fmt, ...)
|
event_msgx(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warn_helper(_EVENT_LOG_MSG, NULL, fmt, ap);
|
_warn_helper(_EVENT_LOG_MSG, NULL, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -145,7 +145,7 @@ void
|
|||||||
_event_debugx(const char *fmt, ...)
|
_event_debugx(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warn_helper(_EVENT_LOG_DEBUG, NULL, fmt, ap);
|
_warn_helper(_EVENT_LOG_DEBUG, NULL, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
@ -42,7 +42,7 @@ fifo_read(int fd, short event, void *arg)
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
len = ReadFile((HANDLE)fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL);
|
len = ReadFile((HANDLE)fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL);
|
||||||
|
|
||||||
// Check for end of file.
|
// Check for end of file.
|
||||||
if(len && dwBytesRead == 0) {
|
if(len && dwBytesRead == 0) {
|
||||||
fprintf(stderr, "End Of File");
|
fprintf(stderr, "End Of File");
|
||||||
event_del(ev);
|
event_del(ev);
|
||||||
@ -72,14 +72,14 @@ main (int argc, char **argv)
|
|||||||
struct event evfifo;
|
struct event evfifo;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE socket;
|
HANDLE socket;
|
||||||
// Open a file.
|
// Open a file.
|
||||||
socket = CreateFile("test.txt", // open File
|
socket = CreateFile("test.txt", // open File
|
||||||
GENERIC_READ, // open for reading
|
GENERIC_READ, // open for reading
|
||||||
0, // do not share
|
0, // do not share
|
||||||
NULL, // no security
|
NULL, // no security
|
||||||
OPEN_EXISTING, // existing file only
|
OPEN_EXISTING, // existing file only
|
||||||
FILE_ATTRIBUTE_NORMAL, // normal file
|
FILE_ATTRIBUTE_NORMAL, // normal file
|
||||||
NULL); // no attr. template
|
NULL); // no attr. template
|
||||||
|
|
||||||
if(socket == INVALID_HANDLE_VALUE)
|
if(socket == INVALID_HANDLE_VALUE)
|
||||||
return 1;
|
return 1;
|
||||||
@ -88,7 +88,7 @@ main (int argc, char **argv)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
const char *fifo = "event.fifo";
|
const char *fifo = "event.fifo";
|
||||||
int socket;
|
int socket;
|
||||||
|
|
||||||
if (lstat (fifo, &st) == 0) {
|
if (lstat (fifo, &st) == 0) {
|
||||||
if ((st.st_mode & S_IFMT) == S_IFREG) {
|
if ((st.st_mode & S_IFMT) == S_IFREG) {
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
@ -129,7 +129,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
/* Add it to the active events, without a timeout */
|
/* Add it to the active events, without a timeout */
|
||||||
event_add(&evfifo, NULL);
|
event_add(&evfifo, NULL);
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
CloseHandle(socket);
|
CloseHandle(socket);
|
||||||
|
@ -38,7 +38,7 @@ signal_cb(int fd, short event, void *arg)
|
|||||||
|
|
||||||
if (called >= 2)
|
if (called >= 2)
|
||||||
event_del(signal);
|
event_del(signal);
|
||||||
|
|
||||||
called++;
|
called++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ int
|
|||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct event signal_int;
|
struct event signal_int;
|
||||||
|
|
||||||
/* Initalize the event library */
|
/* Initalize the event library */
|
||||||
event_init();
|
event_init();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
struct event timeout;
|
struct event timeout;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
/* Initalize the event library */
|
/* Initalize the event library */
|
||||||
event_init();
|
event_init();
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ main (int argc, char **argv)
|
|||||||
event_add(&timeout, &tv);
|
event_add(&timeout, &tv);
|
||||||
|
|
||||||
lasttime = time(NULL);
|
lasttime = time(NULL);
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
4
signal.c
4
signal.c
@ -111,7 +111,7 @@ evsig_cb(evutil_socket_t fd, short what, void *arg)
|
|||||||
void
|
void
|
||||||
evsig_init(struct event_base *base)
|
evsig_init(struct event_base *base)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Our signal handler is going to write to one end of the socket
|
* Our signal handler is going to write to one end of the socket
|
||||||
* pair to wake up our event loop. The event loop then scans for
|
* pair to wake up our event loop. The event loop then scans for
|
||||||
* signals that got delivered.
|
* signals that got delivered.
|
||||||
@ -305,7 +305,7 @@ evsig_process(struct event_base *base)
|
|||||||
struct evsig_info *sig = &base->sig;
|
struct evsig_info *sig = &base->sig;
|
||||||
sig_atomic_t ncalls;
|
sig_atomic_t ncalls;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
base->sig.evsig_caught = 0;
|
base->sig.evsig_caught = 0;
|
||||||
for (i = 1; i < NSIG; ++i) {
|
for (i = 1; i < NSIG; ++i) {
|
||||||
ncalls = sig->evsigcaught[i];
|
ncalls = sig->evsigcaught[i];
|
||||||
|
@ -178,7 +178,7 @@ multiple_read_cb(int fd, short event, void *arg)
|
|||||||
|
|
||||||
roff += len;
|
roff += len;
|
||||||
if (!usepersist) {
|
if (!usepersist) {
|
||||||
if (event_add(ev, NULL) == -1)
|
if (event_add(ev, NULL) == -1)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ test_simpleread(void)
|
|||||||
|
|
||||||
/* Very simple read test */
|
/* Very simple read test */
|
||||||
setup_test("Simple read: ");
|
setup_test("Simple read: ");
|
||||||
|
|
||||||
write(pair[0], TEST1, strlen(TEST1)+1);
|
write(pair[0], TEST1, strlen(TEST1)+1);
|
||||||
shutdown(pair[0], SHUT_WR);
|
shutdown(pair[0], SHUT_WR);
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ test_simplewrite(void)
|
|||||||
|
|
||||||
/* Very simple write test */
|
/* Very simple write test */
|
||||||
setup_test("Simple write: ");
|
setup_test("Simple write: ");
|
||||||
|
|
||||||
event_set(&ev, pair[0], EV_WRITE, simple_write_cb, &ev);
|
event_set(&ev, pair[0], EV_WRITE, simple_write_cb, &ev);
|
||||||
if (event_add(&ev, NULL) == -1)
|
if (event_add(&ev, NULL) == -1)
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -343,7 +343,7 @@ test_simpleread_multiple(void)
|
|||||||
|
|
||||||
/* Very simple read test */
|
/* Very simple read test */
|
||||||
setup_test("Simple read to multiple evens: ");
|
setup_test("Simple read to multiple evens: ");
|
||||||
|
|
||||||
write(pair[0], TEST1, strlen(TEST1)+1);
|
write(pair[0], TEST1, strlen(TEST1)+1);
|
||||||
shutdown(pair[0], SHUT_WR);
|
shutdown(pair[0], SHUT_WR);
|
||||||
|
|
||||||
@ -558,7 +558,7 @@ test_fork(void)
|
|||||||
|
|
||||||
event_base_free(current_base);
|
event_base_free(current_base);
|
||||||
|
|
||||||
/* we do not send an EOF; simple_read_cb requires an EOF
|
/* we do not send an EOF; simple_read_cb requires an EOF
|
||||||
* to set test_ok. we just verify that the callback was
|
* to set test_ok. we just verify that the callback was
|
||||||
* called. */
|
* called. */
|
||||||
exit(test_ok != 0 || called != 2 ? -2 : 76);
|
exit(test_ok != 0 || called != 2 ? -2 : 76);
|
||||||
@ -573,7 +573,7 @@ test_fork(void)
|
|||||||
fprintf(stdout, "FAILED (fork)\n");
|
fprintf(stdout, "FAILED (fork)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WEXITSTATUS(status) != 76) {
|
if (WEXITSTATUS(status) != 76) {
|
||||||
fprintf(stdout, "FAILED (exit): %d\n", WEXITSTATUS(status));
|
fprintf(stdout, "FAILED (exit): %d\n", WEXITSTATUS(status));
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -967,7 +967,7 @@ test_loopexit_multiple(void)
|
|||||||
setup_test("Loop Multiple exit: ");
|
setup_test("Loop Multiple exit: ");
|
||||||
|
|
||||||
base = event_base_new();
|
base = event_base_new();
|
||||||
|
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
event_base_loopexit(base, &tv);
|
event_base_loopexit(base, &tv);
|
||||||
@ -979,7 +979,7 @@ test_loopexit_multiple(void)
|
|||||||
event_base_dispatch(base);
|
event_base_dispatch(base);
|
||||||
|
|
||||||
event_base_free(base);
|
event_base_free(base);
|
||||||
|
|
||||||
test_ok = 1;
|
test_ok = 1;
|
||||||
|
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
@ -1083,7 +1083,7 @@ evbuffer_validate(struct evbuffer *buf)
|
|||||||
{
|
{
|
||||||
struct evbuffer_chain *chain, *previous = NULL;
|
struct evbuffer_chain *chain, *previous = NULL;
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
if (buf->first == NULL) {
|
if (buf->first == NULL) {
|
||||||
assert(buf->last == NULL);
|
assert(buf->last == NULL);
|
||||||
assert(buf->previous_to_last == NULL);
|
assert(buf->previous_to_last == NULL);
|
||||||
@ -1227,9 +1227,9 @@ test_evbuffer(void)
|
|||||||
evbuffer_validate(evb);
|
evbuffer_validate(evb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test_ok = 1;
|
test_ok = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
evbuffer_free(evb);
|
evbuffer_free(evb);
|
||||||
evbuffer_free(evb_two);
|
evbuffer_free(evb_two);
|
||||||
@ -1452,7 +1452,7 @@ test_evbuffer_iterative(void)
|
|||||||
sum += j;
|
sum += j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sum == EVBUFFER_LENGTH(buf))
|
if (sum == EVBUFFER_LENGTH(buf))
|
||||||
test_ok = 1;
|
test_ok = 1;
|
||||||
|
|
||||||
@ -1476,7 +1476,7 @@ test_evbuffer_find(void)
|
|||||||
fprintf(stdout, "Testing evbuffer_find 1: ");
|
fprintf(stdout, "Testing evbuffer_find 1: ");
|
||||||
evbuffer_add(buf, (u_char*)test1, strlen(test1));
|
evbuffer_add(buf, (u_char*)test1, strlen(test1));
|
||||||
evbuffer_validate(buf);
|
evbuffer_validate(buf);
|
||||||
evbuffer_drain(buf, strlen(test1));
|
evbuffer_drain(buf, strlen(test1));
|
||||||
evbuffer_validate(buf);
|
evbuffer_validate(buf);
|
||||||
evbuffer_add(buf, (u_char*)test2, strlen(test2));
|
evbuffer_add(buf, (u_char*)test2, strlen(test2));
|
||||||
evbuffer_validate(buf);
|
evbuffer_validate(buf);
|
||||||
@ -1852,7 +1852,7 @@ test_multiple_events_for_same_fd(void)
|
|||||||
write(pair[1], TEST1, strlen(TEST1)+1);
|
write(pair[1], TEST1, strlen(TEST1)+1);
|
||||||
event_loop(EVLOOP_ONCE);
|
event_loop(EVLOOP_ONCE);
|
||||||
event_del(&e1);
|
event_del(&e1);
|
||||||
|
|
||||||
if (test_ok != 3)
|
if (test_ok != 3)
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
@ -1890,14 +1890,14 @@ test_want_only_once(void)
|
|||||||
|
|
||||||
/* Very simple read test */
|
/* Very simple read test */
|
||||||
setup_test("Want read only once: ");
|
setup_test("Want read only once: ");
|
||||||
|
|
||||||
write(pair[0], TEST1, strlen(TEST1)+1);
|
write(pair[0], TEST1, strlen(TEST1)+1);
|
||||||
|
|
||||||
/* Setup the loop termination */
|
/* Setup the loop termination */
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
event_loopexit(&tv);
|
event_loopexit(&tv);
|
||||||
|
|
||||||
event_set(&ev, pair[1], EV_READ, read_once_cb, &ev);
|
event_set(&ev, pair[1], EV_READ, read_once_cb, &ev);
|
||||||
if (event_add(&ev, NULL) == -1)
|
if (event_add(&ev, NULL) == -1)
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -2174,7 +2174,7 @@ rpc_test(void)
|
|||||||
fprintf(stderr, "Incorrect note strings encoded.\n");
|
fprintf(stderr, "Incorrect note strings encoded.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EVTAG_GET(run, large_number, &large_number) == -1 ||
|
if (EVTAG_GET(run, large_number, &large_number) == -1 ||
|
||||||
large_number != 0xdead0a0bcafebeefLL) {
|
large_number != 0xdead0a0bcafebeefLL) {
|
||||||
fprintf(stderr, "Incorrrect large_number.\n");
|
fprintf(stderr, "Incorrrect large_number.\n");
|
||||||
@ -2437,7 +2437,7 @@ main (int argc, char **argv)
|
|||||||
test_signal_assert();
|
test_signal_assert();
|
||||||
test_signal_while_processing();
|
test_signal_while_processing();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ http_connect(const char *address, u_short port)
|
|||||||
struct sockaddr *sa;
|
struct sockaddr *sa;
|
||||||
int slen;
|
int slen;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!(he = gethostbyname(address))) {
|
if (!(he = gethostbyname(address))) {
|
||||||
event_warn("gethostbyname");
|
event_warn("gethostbyname");
|
||||||
@ -151,7 +151,7 @@ http_connect(const char *address, u_short port)
|
|||||||
sa = aitop->ai_addr;
|
sa = aitop->ai_addr;
|
||||||
slen = aitop->ai_addrlen;
|
slen = aitop->ai_addrlen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
event_err(1, "socket failed");
|
event_err(1, "socket failed");
|
||||||
@ -182,7 +182,7 @@ http_readcb(struct bufferevent *bev, void *arg)
|
|||||||
const char *what = BASIC_REQUEST_BODY;
|
const char *what = BASIC_REQUEST_BODY;
|
||||||
|
|
||||||
event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(EVBUFFER_INPUT(bev))));
|
event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(EVBUFFER_INPUT(bev))));
|
||||||
|
|
||||||
if (evbuffer_find(EVBUFFER_INPUT(bev),
|
if (evbuffer_find(EVBUFFER_INPUT(bev),
|
||||||
(const unsigned char*) what, strlen(what)) != NULL) {
|
(const unsigned char*) what, strlen(what)) != NULL) {
|
||||||
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
|
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
|
||||||
@ -236,7 +236,7 @@ http_basic_cb(struct evhttp_request *req, void *arg)
|
|||||||
int empty = evhttp_find_header(req->input_headers, "Empty") != NULL;
|
int empty = evhttp_find_header(req->input_headers, "Empty") != NULL;
|
||||||
event_debug(("%s: called\n", __func__));
|
event_debug(("%s: called\n", __func__));
|
||||||
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
||||||
|
|
||||||
/* For multi-line headers test */
|
/* For multi-line headers test */
|
||||||
{
|
{
|
||||||
const char *multi =
|
const char *multi =
|
||||||
@ -305,7 +305,7 @@ http_chunked_cb(struct evhttp_request *req, void *arg)
|
|||||||
if (strcmp(evhttp_request_uri(req), "/streamed") == 0) {
|
if (strcmp(evhttp_request_uri(req), "/streamed") == 0) {
|
||||||
evhttp_add_header(req->output_headers, "Content-Length", "39");
|
evhttp_add_header(req->output_headers, "Content-Length", "39");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* generate a chunked/streamed reply */
|
/* generate a chunked/streamed reply */
|
||||||
evhttp_send_reply_start(req, HTTP_OK, "Everything is fine");
|
evhttp_send_reply_start(req, HTTP_OK, "Everything is fine");
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ http_basic_test(void)
|
|||||||
fprintf(stdout, "FAILED (bind)\n");
|
fprintf(stdout, "FAILED (bind)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
@ -359,7 +359,7 @@ http_basic_test(void)
|
|||||||
timerclear(&tv);
|
timerclear(&tv);
|
||||||
tv.tv_usec = 10000;
|
tv.tv_usec = 10000;
|
||||||
event_once(-1, EV_TIMEOUT, http_complete_write, bev, &tv);
|
event_once(-1, EV_TIMEOUT, http_complete_write, bev, &tv);
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
if (test_ok != 3) {
|
if (test_ok != 3) {
|
||||||
@ -384,14 +384,14 @@ http_basic_test(void)
|
|||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
bufferevent_write(bev, http_request, strlen(http_request));
|
bufferevent_write(bev, http_request, strlen(http_request));
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
EVUTIL_CLOSESOCKET(fd);
|
EVUTIL_CLOSESOCKET(fd);
|
||||||
|
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
if (test_ok != 5) {
|
if (test_ok != 5) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -472,7 +472,7 @@ http_delete_test(void)
|
|||||||
fprintf(stdout, "Testing HTTP DELETE Request: ");
|
fprintf(stdout, "Testing HTTP DELETE Request: ");
|
||||||
|
|
||||||
http = http_setup(&port, NULL);
|
http = http_setup(&port, NULL);
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
@ -486,19 +486,19 @@ http_delete_test(void)
|
|||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
bufferevent_write(bev, http_request, strlen(http_request));
|
bufferevent_write(bev, http_request, strlen(http_request));
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
EVUTIL_CLOSESOCKET(fd);
|
EVUTIL_CLOSESOCKET(fd);
|
||||||
|
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
if (test_ok != 2) {
|
if (test_ok != 2) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,7 +511,7 @@ http_connection_test(int persistent)
|
|||||||
short port = -1;
|
short port = -1;
|
||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
struct evhttp_request *req = NULL;
|
struct evhttp_request *req = NULL;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
fprintf(stdout, "Testing Request Connection Pipeline %s: ",
|
fprintf(stdout, "Testing Request Connection Pipeline %s: ",
|
||||||
persistent ? "(persistent)" : "");
|
persistent ? "(persistent)" : "");
|
||||||
@ -549,13 +549,13 @@ http_connection_test(int persistent)
|
|||||||
|
|
||||||
/* try to make another request over the same connection */
|
/* try to make another request over the same connection */
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if our connections are not supposed to be persistent; request
|
* if our connections are not supposed to be persistent; request
|
||||||
* a close from the server.
|
* a close from the server.
|
||||||
*/
|
*/
|
||||||
@ -572,7 +572,7 @@ http_connection_test(int persistent)
|
|||||||
|
|
||||||
/* make another request: request empty reply */
|
/* make another request: request empty reply */
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
req = evhttp_request_new(http_request_empty_done, NULL);
|
req = evhttp_request_new(http_request_empty_done, NULL);
|
||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
@ -593,7 +593,7 @@ http_connection_test(int persistent)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,7 +627,7 @@ http_cancel_test(void)
|
|||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
struct evhttp_request *req = NULL;
|
struct evhttp_request *req = NULL;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
fprintf(stdout, "Testing Request Cancelation: ");
|
fprintf(stdout, "Testing Request Cancelation: ");
|
||||||
|
|
||||||
@ -670,7 +670,7 @@ http_cancel_test(void)
|
|||||||
|
|
||||||
/* try to make another request over the same connection */
|
/* try to make another request over the same connection */
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
@ -686,7 +686,7 @@ http_cancel_test(void)
|
|||||||
|
|
||||||
/* make another request: request empty reply */
|
/* make another request: request empty reply */
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
req = evhttp_request_new(http_request_empty_done, NULL);
|
req = evhttp_request_new(http_request_empty_done, NULL);
|
||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
@ -707,7 +707,7 @@ http_cancel_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +730,7 @@ http_request_done(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stderr, "FAILED\n");
|
fprintf(stderr, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
||||||
fprintf(stderr, "FAILED\n");
|
fprintf(stderr, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -760,7 +760,7 @@ http_virtual_host_test(void)
|
|||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
struct evhttp_request *req = NULL;
|
struct evhttp_request *req = NULL;
|
||||||
struct evhttp *second = NULL, *third = NULL;
|
struct evhttp *second = NULL, *third = NULL;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
fprintf(stdout, "Testing Virtual Hosts: ");
|
fprintf(stdout, "Testing Virtual Hosts: ");
|
||||||
|
|
||||||
@ -854,7 +854,7 @@ http_virtual_host_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -874,7 +874,7 @@ http_request_empty_done(struct evhttp_request *req, void *arg)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (evhttp_find_header(req->input_headers, "Content-Length") == NULL) {
|
if (evhttp_find_header(req->input_headers, "Content-Length") == NULL) {
|
||||||
fprintf(stderr, "FAILED\n");
|
fprintf(stderr, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -932,7 +932,7 @@ http_dispatcher_test_done(struct evhttp_request *req, void *arg)
|
|||||||
EVBUFFER_LENGTH(req->input_buffer), strlen(what));
|
EVBUFFER_LENGTH(req->input_buffer), strlen(what));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
||||||
fprintf(stderr, "FAILED (data)\n");
|
fprintf(stderr, "FAILED (data)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -976,7 +976,7 @@ http_dispatcher_test(void)
|
|||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/?arg=val") == -1) {
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/?arg=val") == -1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -986,12 +986,12 @@ http_dispatcher_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED: %d\n", test_ok);
|
fprintf(stdout, "FAILED: %d\n", test_ok);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1035,7 +1035,7 @@ http_post_test(void)
|
|||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
evbuffer_add_printf(req->output_buffer, POST_DATA);
|
evbuffer_add_printf(req->output_buffer, POST_DATA);
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/postit") == -1) {
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/postit") == -1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1045,12 +1045,12 @@ http_post_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED: %d\n", test_ok);
|
fprintf(stdout, "FAILED: %d\n", test_ok);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1079,7 +1079,7 @@ http_post_cb(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stdout, "Want:%s\n", POST_DATA);
|
fprintf(stdout, "Want:%s\n", POST_DATA);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
evb = evbuffer_new();
|
evb = evbuffer_new();
|
||||||
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
||||||
|
|
||||||
@ -1099,7 +1099,7 @@ http_postrequest_done(struct evhttp_request *req, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req->response_code != HTTP_OK) {
|
if (req->response_code != HTTP_OK) {
|
||||||
|
|
||||||
fprintf(stderr, "FAILED (response code)\n");
|
fprintf(stderr, "FAILED (response code)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1114,7 +1114,7 @@ http_postrequest_done(struct evhttp_request *req, void *arg)
|
|||||||
EVBUFFER_LENGTH(req->input_buffer), strlen(what));
|
EVBUFFER_LENGTH(req->input_buffer), strlen(what));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
||||||
fprintf(stderr, "FAILED (data)\n");
|
fprintf(stderr, "FAILED (data)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1163,7 +1163,7 @@ http_put_test(void)
|
|||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "someotherhost");
|
evhttp_add_header(req->output_headers, "Host", "someotherhost");
|
||||||
evbuffer_add_printf(req->output_buffer, PUT_DATA);
|
evbuffer_add_printf(req->output_buffer, PUT_DATA);
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req, EVHTTP_REQ_PUT, "/putit") == -1) {
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_PUT, "/putit") == -1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1173,12 +1173,12 @@ http_put_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED: %d\n", test_ok);
|
fprintf(stdout, "FAILED: %d\n", test_ok);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1207,7 +1207,7 @@ http_put_cb(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stdout, "Want:%s\n", PUT_DATA);
|
fprintf(stdout, "Want:%s\n", PUT_DATA);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
evb = evbuffer_new();
|
evb = evbuffer_new();
|
||||||
evbuffer_add_printf(evb, "That ain't funny");
|
evbuffer_add_printf(evb, "That ain't funny");
|
||||||
|
|
||||||
@ -1227,7 +1227,7 @@ http_putrequest_done(struct evhttp_request *req, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req->response_code != HTTP_OK) {
|
if (req->response_code != HTTP_OK) {
|
||||||
|
|
||||||
fprintf(stderr, "FAILED (response code)\n");
|
fprintf(stderr, "FAILED (response code)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1242,7 +1242,7 @@ http_putrequest_done(struct evhttp_request *req, void *arg)
|
|||||||
EVBUFFER_LENGTH(req->input_buffer), strlen(what));
|
EVBUFFER_LENGTH(req->input_buffer), strlen(what));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) {
|
||||||
fprintf(stderr, "FAILED (data)\n");
|
fprintf(stderr, "FAILED (data)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1279,7 +1279,7 @@ http_failure_test(void)
|
|||||||
fprintf(stdout, "Testing Bad HTTP Request: ");
|
fprintf(stdout, "Testing Bad HTTP Request: ");
|
||||||
|
|
||||||
http = http_setup(&port, NULL);
|
http = http_setup(&port, NULL);
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
@ -1289,19 +1289,19 @@ http_failure_test(void)
|
|||||||
http_request = "illegal request\r\n";
|
http_request = "illegal request\r\n";
|
||||||
|
|
||||||
bufferevent_write(bev, http_request, strlen(http_request));
|
bufferevent_write(bev, http_request, strlen(http_request));
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
EVUTIL_CLOSESOCKET(fd);
|
EVUTIL_CLOSESOCKET(fd);
|
||||||
|
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
if (test_ok != 2) {
|
if (test_ok != 2) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1346,7 +1346,7 @@ close_detect_cb(struct evhttp_request *req, void *arg)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
if (req != NULL && req->response_code != HTTP_OK) {
|
if (req != NULL && req->response_code != HTTP_OK) {
|
||||||
|
|
||||||
fprintf(stderr, "FAILED\n");
|
fprintf(stderr, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1365,7 +1365,7 @@ http_close_detection(int with_delay)
|
|||||||
short port = -1;
|
short port = -1;
|
||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
struct evhttp_request *req = NULL;
|
struct evhttp_request *req = NULL;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
fprintf(stdout, "Testing Connection Close Detection%s: ",
|
fprintf(stdout, "Testing Connection Close Detection%s: ",
|
||||||
with_delay ? " (with delay)" : "");
|
with_delay ? " (with delay)" : "");
|
||||||
@ -1415,7 +1415,7 @@ http_close_detection(int with_delay)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1424,7 +1424,7 @@ http_highport_test(void)
|
|||||||
{
|
{
|
||||||
int i = -1;
|
int i = -1;
|
||||||
struct evhttp *myhttp = NULL;
|
struct evhttp *myhttp = NULL;
|
||||||
|
|
||||||
fprintf(stdout, "Testing HTTP Server with high port: ");
|
fprintf(stdout, "Testing HTTP Server with high port: ");
|
||||||
|
|
||||||
/* Try a few different ports */
|
/* Try a few different ports */
|
||||||
@ -1452,7 +1452,7 @@ http_bad_header_test(void)
|
|||||||
|
|
||||||
if (evhttp_add_header(&headers, "One", "Two") != 0)
|
if (evhttp_add_header(&headers, "One", "Two") != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (evhttp_add_header(&headers, "One\r", "Two") != -1)
|
if (evhttp_add_header(&headers, "One\r", "Two") != -1)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@ -1488,14 +1488,14 @@ http_base_test(void)
|
|||||||
|
|
||||||
base = event_init();
|
base = event_init();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create another bogus base - which is being used by all subsequen
|
* create another bogus base - which is being used by all subsequen
|
||||||
* tests - yuck!
|
* tests - yuck!
|
||||||
*/
|
*/
|
||||||
tmp = event_init();
|
tmp = event_init();
|
||||||
|
|
||||||
http = http_setup(&port, base);
|
http = http_setup(&port, base);
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
@ -1510,7 +1510,7 @@ http_base_test(void)
|
|||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
bufferevent_write(bev, http_request, strlen(http_request));
|
bufferevent_write(bev, http_request, strlen(http_request));
|
||||||
|
|
||||||
event_base_dispatch(base);
|
event_base_dispatch(base);
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
@ -1520,12 +1520,12 @@ http_base_test(void)
|
|||||||
|
|
||||||
event_base_free(base);
|
event_base_free(base);
|
||||||
base = tmp;
|
base = tmp;
|
||||||
|
|
||||||
if (test_ok != 2) {
|
if (test_ok != 2) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1588,7 +1588,7 @@ http_incomplete_test(int use_timeout)
|
|||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = bufferevent_new(fd,
|
bev = bufferevent_new(fd,
|
||||||
http_incomplete_readcb, http_incomplete_writecb,
|
http_incomplete_readcb, http_incomplete_writecb,
|
||||||
http_incomplete_errorcb, use_timeout ? NULL : &fd);
|
http_incomplete_errorcb, use_timeout ? NULL : &fd);
|
||||||
|
|
||||||
@ -1599,7 +1599,7 @@ http_incomplete_test(int use_timeout)
|
|||||||
bufferevent_write(bev, http_request, strlen(http_request));
|
bufferevent_write(bev, http_request, strlen(http_request));
|
||||||
|
|
||||||
evutil_gettimeofday(&tv_start, NULL);
|
evutil_gettimeofday(&tv_start, NULL);
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
evutil_gettimeofday(&tv_end, NULL);
|
evutil_gettimeofday(&tv_end, NULL);
|
||||||
@ -1626,7 +1626,7 @@ http_incomplete_test(int use_timeout)
|
|||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1652,7 +1652,7 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
|
|||||||
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
|
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
|
||||||
const char *header;
|
const char *header;
|
||||||
enum message_read_status done;
|
enum message_read_status done;
|
||||||
|
|
||||||
req->kind = EVHTTP_RESPONSE;
|
req->kind = EVHTTP_RESPONSE;
|
||||||
done = evhttp_parse_firstline(req, EVBUFFER_INPUT(bev));
|
done = evhttp_parse_firstline(req, EVBUFFER_INPUT(bev));
|
||||||
if (done != ALL_DATA_READ)
|
if (done != ALL_DATA_READ)
|
||||||
@ -1764,7 +1764,7 @@ http_chunked_request_done(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stderr, "FAILED\n");
|
fprintf(stderr, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
test_ok = 1;
|
test_ok = 1;
|
||||||
event_loopexit(NULL);
|
event_loopexit(NULL);
|
||||||
}
|
}
|
||||||
@ -1789,7 +1789,7 @@ http_chunk_out_test(void)
|
|||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = bufferevent_new(fd,
|
bev = bufferevent_new(fd,
|
||||||
http_chunked_readcb, http_chunked_writecb,
|
http_chunked_readcb, http_chunked_writecb,
|
||||||
http_chunked_errorcb, NULL);
|
http_chunked_errorcb, NULL);
|
||||||
|
|
||||||
@ -1802,7 +1802,7 @@ http_chunk_out_test(void)
|
|||||||
bufferevent_write(bev, http_request, strlen(http_request));
|
bufferevent_write(bev, http_request, strlen(http_request));
|
||||||
|
|
||||||
evutil_gettimeofday(&tv_start, NULL);
|
evutil_gettimeofday(&tv_start, NULL);
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
@ -1853,7 +1853,7 @@ http_chunk_out_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1863,7 +1863,7 @@ http_stream_out_test(void)
|
|||||||
short port = -1;
|
short port = -1;
|
||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
struct evhttp_request *req = NULL;
|
struct evhttp_request *req = NULL;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
printf("Tests streaming responses out: ");
|
printf("Tests streaming responses out: ");
|
||||||
|
|
||||||
@ -1902,7 +1902,7 @@ http_stream_out_test(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2051,7 +2051,7 @@ http_connection_retry_done(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stderr, "FAILED (connection aborted)\n");
|
fprintf(stderr, "FAILED (connection aborted)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->response_code == HTTP_OK) {
|
if (req->response_code == HTTP_OK) {
|
||||||
fprintf(stderr, "FAILED\n");
|
fprintf(stderr, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -2066,7 +2066,7 @@ http_connection_retry_done(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stderr, "FAILED (length)\n");
|
fprintf(stderr, "FAILED (length)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
test_ok = 1;
|
test_ok = 1;
|
||||||
event_loopexit(NULL);
|
event_loopexit(NULL);
|
||||||
}
|
}
|
||||||
@ -2116,7 +2116,7 @@ http_connection_retry(void)
|
|||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
||||||
"/?arg=val") == -1) {
|
"/?arg=val") == -1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
@ -2153,7 +2153,7 @@ http_connection_retry(void)
|
|||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
||||||
"/?arg=val") == -1) {
|
"/?arg=val") == -1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
@ -2191,7 +2191,7 @@ http_connection_retry(void)
|
|||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
||||||
"/?arg=val") == -1) {
|
"/?arg=val") == -1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
@ -2222,7 +2222,7 @@ http_connection_retry(void)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2258,12 +2258,12 @@ http_multi_line_header_test(void)
|
|||||||
int fd;
|
int fd;
|
||||||
const char *http_start_request;
|
const char *http_start_request;
|
||||||
short port = -1;
|
short port = -1;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
fprintf(stdout, "Testing HTTP Server with multi line: ");
|
fprintf(stdout, "Testing HTTP Server with multi line: ");
|
||||||
|
|
||||||
http = http_setup(&port, NULL);
|
http = http_setup(&port, NULL);
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
@ -2279,11 +2279,11 @@ http_multi_line_header_test(void)
|
|||||||
"\tEND\r\n"
|
"\tEND\r\n"
|
||||||
"X-Last: last\r\n"
|
"X-Last: last\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
bufferevent_write(bev, http_start_request, strlen(http_start_request));
|
bufferevent_write(bev, http_start_request, strlen(http_start_request));
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
@ -2293,7 +2293,7 @@ http_multi_line_header_test(void)
|
|||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2315,7 +2315,7 @@ http_negative_content_length_test(void)
|
|||||||
short port = -1;
|
short port = -1;
|
||||||
struct evhttp_connection *evcon = NULL;
|
struct evhttp_connection *evcon = NULL;
|
||||||
struct evhttp_request *req = NULL;
|
struct evhttp_request *req = NULL;
|
||||||
|
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
fprintf(stdout, "Testing HTTP Negative Content Length: ");
|
fprintf(stdout, "Testing HTTP Negative Content Length: ");
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ rpc_setup(struct evhttp **phttp, short *pport, struct evrpc_base **pbase)
|
|||||||
|
|
||||||
http = http_setup(&port);
|
http = http_setup(&port);
|
||||||
base = evrpc_init(http);
|
base = evrpc_init(http);
|
||||||
|
|
||||||
EVRPC_REGISTER(base, Message, msg, kill, MessageCb, NULL);
|
EVRPC_REGISTER(base, Message, msg, kill, MessageCb, NULL);
|
||||||
EVRPC_REGISTER(base, NeverReply, msg, kill, NeverReplyCb, NULL);
|
EVRPC_REGISTER(base, NeverReply, msg, kill, NeverReplyCb, NULL);
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ static void
|
|||||||
rpc_postrequest_failure(struct evhttp_request *req, void *arg)
|
rpc_postrequest_failure(struct evhttp_request *req, void *arg)
|
||||||
{
|
{
|
||||||
if (req->response_code != HTTP_SERVUNAVAIL) {
|
if (req->response_code != HTTP_SERVUNAVAIL) {
|
||||||
|
|
||||||
fprintf(stderr, "FAILED (response code)\n");
|
fprintf(stderr, "FAILED (response code)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ rpc_basic_test(void)
|
|||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(req->output_headers, "Host", "somehost");
|
evhttp_add_header(req->output_headers, "Host", "somehost");
|
||||||
evbuffer_add_printf(req->output_buffer, "Some Nonsense");
|
evbuffer_add_printf(req->output_buffer, "Some Nonsense");
|
||||||
|
|
||||||
if (evhttp_make_request(evcon, req,
|
if (evhttp_make_request(evcon, req,
|
||||||
EVHTTP_REQ_POST,
|
EVHTTP_REQ_POST,
|
||||||
"/.rpc.Message") == -1) {
|
"/.rpc.Message") == -1) {
|
||||||
@ -220,7 +220,7 @@ rpc_basic_test(void)
|
|||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
|
|
||||||
rpc_teardown(base);
|
rpc_teardown(base);
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -237,7 +237,7 @@ rpc_postrequest_done(struct evhttp_request *req, void *arg)
|
|||||||
struct kill* kill_reply = NULL;
|
struct kill* kill_reply = NULL;
|
||||||
|
|
||||||
if (req->response_code != HTTP_OK) {
|
if (req->response_code != HTTP_OK) {
|
||||||
|
|
||||||
fprintf(stderr, "FAILED (response code)\n");
|
fprintf(stderr, "FAILED (response code)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ rpc_postrequest_done(struct evhttp_request *req, void *arg)
|
|||||||
fprintf(stderr, "FAILED (unmarshal)\n");
|
fprintf(stderr, "FAILED (unmarshal)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
kill_free(kill_reply);
|
kill_free(kill_reply);
|
||||||
|
|
||||||
test_ok = 1;
|
test_ok = 1;
|
||||||
@ -308,9 +308,9 @@ rpc_basic_message(void)
|
|||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
|
|
||||||
rpc_teardown(base);
|
rpc_teardown(base);
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -334,7 +334,7 @@ rpc_pool_with_connection(short port)
|
|||||||
assert(evcon != NULL);
|
assert(evcon != NULL);
|
||||||
|
|
||||||
evrpc_pool_add_connection(pool, evcon);
|
evrpc_pool_add_connection(pool, evcon);
|
||||||
|
|
||||||
return (pool);
|
return (pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ rpc_hook_add_header(void *ctx, struct evhttp_request *req,
|
|||||||
const char *hook_type = arg;
|
const char *hook_type = arg;
|
||||||
if (strcmp("input", hook_type) == 0)
|
if (strcmp("input", hook_type) == 0)
|
||||||
evhttp_add_header(req->input_headers, "X-Hook", hook_type);
|
evhttp_add_header(req->input_headers, "X-Hook", hook_type);
|
||||||
else
|
else
|
||||||
evhttp_add_header(req->output_headers, "X-Hook", hook_type);
|
evhttp_add_header(req->output_headers, "X-Hook", hook_type);
|
||||||
|
|
||||||
assert(evrpc_hook_get_connection(ctx) != NULL);
|
assert(evrpc_hook_get_connection(ctx) != NULL);
|
||||||
@ -496,7 +496,7 @@ rpc_basic_client(void)
|
|||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED (1)\n");
|
fprintf(stdout, "FAILED (1)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -508,7 +508,7 @@ rpc_basic_client(void)
|
|||||||
EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL);
|
EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL);
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
if (test_ok != 2) {
|
if (test_ok != 2) {
|
||||||
fprintf(stdout, "FAILED (2)\n");
|
fprintf(stdout, "FAILED (2)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -526,9 +526,9 @@ rpc_basic_client(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
rpc_teardown(base);
|
rpc_teardown(base);
|
||||||
|
|
||||||
if (test_ok != 3) {
|
if (test_ok != 3) {
|
||||||
fprintf(stdout, "FAILED (3)\n");
|
fprintf(stdout, "FAILED (3)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -546,7 +546,7 @@ rpc_basic_client(void)
|
|||||||
need_output_hook = 0;
|
need_output_hook = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We are testing that the second requests gets send over the same
|
* We are testing that the second requests gets send over the same
|
||||||
* connection after the first RPCs completes.
|
* connection after the first RPCs completes.
|
||||||
*/
|
*/
|
||||||
@ -580,9 +580,9 @@ rpc_basic_queued_client(void)
|
|||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
rpc_teardown(base);
|
rpc_teardown(base);
|
||||||
|
|
||||||
if (test_ok != 2) {
|
if (test_ok != 2) {
|
||||||
fprintf(stdout, "FAILED (1)\n");
|
fprintf(stdout, "FAILED (1)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -682,14 +682,14 @@ rpc_basic_client_with_pause(void)
|
|||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
if (test_ok != 1 || hook_pause_cb_called != 4) {
|
if (test_ok != 1 || hook_pause_cb_called != 4) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_teardown(base);
|
rpc_teardown(base);
|
||||||
|
|
||||||
fprintf(stdout, "OK\n");
|
fprintf(stdout, "OK\n");
|
||||||
|
|
||||||
msg_free(msg);
|
msg_free(msg);
|
||||||
@ -730,12 +730,12 @@ rpc_client_timeout(void)
|
|||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
/* free the saved RPC structure up */
|
/* free the saved RPC structure up */
|
||||||
EVRPC_REQUEST_DONE(saved_rpc);
|
EVRPC_REQUEST_DONE(saved_rpc);
|
||||||
|
|
||||||
rpc_teardown(base);
|
rpc_teardown(base);
|
||||||
|
|
||||||
if (test_ok != 2) {
|
if (test_ok != 2) {
|
||||||
fprintf(stdout, "FAILED (1)\n");
|
fprintf(stdout, "FAILED (1)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -63,7 +63,7 @@ main (int argc, char **argv)
|
|||||||
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
|
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
|
||||||
write(pair[0], test, strlen(test)+1);
|
write(pair[0], test, strlen(test)+1);
|
||||||
shutdown(pair[0], SHUT_WR);
|
shutdown(pair[0], SHUT_WR);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user