mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 22:10:12 -04:00
Use the native "struct iovec" as our "struct evbuffer_iovec" when available, so we do not need to copy more pointers than necessary.
svn:r1299
This commit is contained in:
parent
594842970e
commit
8997f234f2
24
buffer.c
24
buffer.c
@ -1475,17 +1475,10 @@ _evbuffer_expand_fast(struct evbuffer *buf, size_t datlen)
|
||||
#define IOV_PTR_FIELD buf
|
||||
#define IOV_LEN_FIELD len
|
||||
#endif
|
||||
|
||||
#define IOV_TYPE_FROM_EVBUFFER_IOV(i,ei) do { \
|
||||
(i)->IOV_PTR_FIELD = (ei)->iov_base; \
|
||||
(i)->IOV_LEN_FIELD = (ei)->iov_len; \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
|
||||
#define EVBUFFER_MAX_READ 4096
|
||||
|
||||
#ifdef USE_IOVEC_IMPL
|
||||
/** Helper function to figure out which space to use for reading data into
|
||||
an evbuffer. Internal use only.
|
||||
|
||||
@ -1494,7 +1487,8 @@ _evbuffer_expand_fast(struct evbuffer *buf, size_t datlen)
|
||||
@param vecs An array of two iovecs or WSABUFs.
|
||||
@param chainp A pointer to a variable to hold the first chain we're
|
||||
reading into.
|
||||
@param exact DOCDOC
|
||||
@param exact Boolean: if true, we do not provide more than 'howmuch'
|
||||
space in the vectors, even if more space is available.
|
||||
@return The number of buffers we're using.
|
||||
*/
|
||||
int
|
||||
@ -1546,7 +1540,6 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
|
||||
*chainp = chain;
|
||||
return nvecs;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* TODO(niels): should this function return ssize_t and take ssize_t
|
||||
* as howmuch? */
|
||||
@ -1605,16 +1598,23 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
goto done;
|
||||
} else {
|
||||
IOV_TYPE vecs[2];
|
||||
#ifdef _EVBUFFER_IOVEC_IS_NATIVE
|
||||
nvecs = _evbuffer_read_setup_vecs(buf, howmuch, vecs,
|
||||
&chain, 1);
|
||||
#else
|
||||
/* We aren't using the native struct iovec. Therefore,
|
||||
we are on win32. */
|
||||
struct evbuffer_iovec ev_vecs[2];
|
||||
nvecs = _evbuffer_read_setup_vecs(buf, howmuch, ev_vecs,
|
||||
&chain, 1);
|
||||
|
||||
if (nvecs == 2) {
|
||||
IOV_TYPE_FROM_EVBUFFER_IOV(&vecs[1], &ev_vecs[1]);
|
||||
IOV_TYPE_FROM_EVBUFFER_IOV(&vecs[0], &ev_vecs[0]);
|
||||
WSABUF_FROM_EVBUFFER_IOV(&vecs[1], &ev_vecs[1]);
|
||||
WSABUF_FROM_EVBUFFER_IOV(&vecs[0], &ev_vecs[0]);
|
||||
} else if (nvecs == 1) {
|
||||
IOV_TYPE_FROM_EVBUFFER_IOV(&vecs[0], &ev_vecs[0]);
|
||||
WSABUF_FROM_EVBUFFER_IOV(&vecs[0], &ev_vecs[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
{
|
||||
|
@ -245,11 +245,6 @@ done:
|
||||
return r;
|
||||
}
|
||||
|
||||
#define IOV_TYPE_FROM_EVBUFFER_IOV(i,ei) do { \
|
||||
(i)->buf = (ei)->iov_base; \
|
||||
(i)->len = (ei)->iov_len; \
|
||||
} while(0)
|
||||
|
||||
int
|
||||
evbuffer_launch_read(struct evbuffer *buf, size_t at_most)
|
||||
{
|
||||
@ -280,7 +275,7 @@ evbuffer_launch_read(struct evbuffer *buf, size_t at_most)
|
||||
nvecs = _evbuffer_read_setup_vecs(buf, at_most,
|
||||
vecs, &chain, 1);
|
||||
for (i=0;i<nvecs;++i) {
|
||||
IOV_TYPE_FROM_EVBUFFER_IOV(
|
||||
WSABUF_FROM_EVBUFFER_IOV(
|
||||
&buf_o->read_info.buffers[i],
|
||||
&vecs[i]);
|
||||
}
|
||||
|
@ -252,6 +252,7 @@ void _evbuffer_chain_unpin(struct evbuffer_chain *chain, unsigned flag);
|
||||
/** As evbuffer_free, but requires that we hold a lock on the buffer, and
|
||||
* releases the lock before freeing it and the buffer. */
|
||||
void _evbuffer_decref_and_unlock(struct evbuffer *buffer);
|
||||
|
||||
/** As evbuffer_expand, but does not guarantee that the newly allocated memory
|
||||
* is contiguous. Instead, it may be split across two chunks. */
|
||||
int _evbuffer_expand_fast(struct evbuffer *, size_t);
|
||||
@ -265,6 +266,12 @@ int _evbuffer_expand_fast(struct evbuffer *, size_t);
|
||||
int _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
|
||||
struct evbuffer_iovec *vecs, struct evbuffer_chain **chainp, int exact);
|
||||
|
||||
/* Helper macro: copies an evbuffer_iovec in ei to a win32 WSABUF in i. */
|
||||
#define WSABUF_FROM_EVBUFFER_IOV(i,ei) do { \
|
||||
(i)->buf = (ei)->iov_base; \
|
||||
(i)->len = (ei)->iov_len; \
|
||||
} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -70,6 +70,9 @@ extern "C" {
|
||||
#ifdef _EVENT_HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef _EVENT_HAVE_SYS_UIO_H
|
||||
#include <sys/uio.h>
|
||||
#endif
|
||||
#include <event2/util.h>
|
||||
|
||||
struct evbuffer;
|
||||
@ -94,12 +97,18 @@ struct evbuffer_ptr {
|
||||
|
||||
@see evbuffer_reserve_space, evbuffer_commit_space, evbuffer_peek
|
||||
*/
|
||||
#ifdef _EVENT_HAVE_SYS_UIO_H
|
||||
#define evbuffer_iovec iovec
|
||||
/* Internal use -- defined only if we are using the native struct iovec */
|
||||
#define _EVBUFFER_IOVEC_IS_NATIVE
|
||||
#else
|
||||
struct evbuffer_iovec {
|
||||
/** The start of the extent of memory. */
|
||||
void *iov_base;
|
||||
/** The length of the extent of memory. */
|
||||
size_t iov_len;
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
Allocate storage for a new evbuffer.
|
||||
|
Loading…
x
Reference in New Issue
Block a user