#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.
@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
*chainp = chain;
return nvecs;
}
-#endif
/* TODO(niels): should this function return ssize_t and take ssize_t
* as 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
{
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)
{
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]);
}
/** 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);
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
#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;
@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.