snapshot socket.[ch] code and commit dynbuf_t -> buffer_t changes
This commit is contained in:
@@ -36,7 +36,7 @@ struct ns_query {
|
||||
dns_name_t * qname;
|
||||
dns_name_t * origqname;
|
||||
unsigned int dboptions;
|
||||
ISC_LIST(isc_dynbuffer_t) namebufs;
|
||||
isc_bufferlist_t namebufs;
|
||||
ISC_LIST(dns_name_t) tmpnames;
|
||||
ISC_LIST(dns_rdataset_t) tmprdatasets;
|
||||
ISC_LIST(ns_dbversion_t) activeversions;
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
static inline void
|
||||
query_reset(ns_client_t *client, isc_boolean_t everything) {
|
||||
isc_dynbuffer_t *dbuf, *dbuf_next;
|
||||
isc_buffer_t *dbuf, *dbuf_next;
|
||||
ns_dbversion_t *dbversion, *dbversion_next;
|
||||
unsigned int i;
|
||||
|
||||
@@ -97,7 +97,7 @@ query_reset(ns_client_t *client, isc_boolean_t everything) {
|
||||
dbuf_next = ISC_LIST_NEXT(dbuf, link);
|
||||
if (dbuf_next != NULL || everything) {
|
||||
ISC_LIST_UNLINK(client->query.namebufs, dbuf, link);
|
||||
isc_dynbuffer_free(client->mctx, &dbuf);
|
||||
isc_buffer_free(&dbuf);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -126,7 +126,7 @@ ns_query_free(ns_client_t *client) {
|
||||
|
||||
static inline isc_result_t
|
||||
query_newnamebuf(ns_client_t *client) {
|
||||
isc_dynbuffer_t *dbuf;
|
||||
isc_buffer_t *dbuf;
|
||||
isc_result_t result;
|
||||
|
||||
/*
|
||||
@@ -134,8 +134,8 @@ query_newnamebuf(ns_client_t *client) {
|
||||
*/
|
||||
|
||||
dbuf = NULL;
|
||||
result = isc_dynbuffer_allocate(client->mctx, &dbuf, 1024,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
result = isc_buffer_allocate(client->mctx, &dbuf, 1024,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
ISC_LIST_APPEND(client->query.namebufs, dbuf, link);
|
||||
@@ -143,9 +143,9 @@ query_newnamebuf(ns_client_t *client) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static inline isc_dynbuffer_t *
|
||||
static inline isc_buffer_t *
|
||||
query_getnamebuf(ns_client_t *client) {
|
||||
isc_dynbuffer_t *dbuf;
|
||||
isc_buffer_t *dbuf;
|
||||
isc_result_t result;
|
||||
isc_region_t r;
|
||||
|
||||
@@ -162,20 +162,20 @@ query_getnamebuf(ns_client_t *client) {
|
||||
|
||||
dbuf = ISC_LIST_TAIL(client->query.namebufs);
|
||||
INSIST(dbuf != NULL);
|
||||
isc_buffer_available(&dbuf->buffer, &r);
|
||||
isc_buffer_available(dbuf, &r);
|
||||
if (r.length < 255) {
|
||||
result = query_newnamebuf(client);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (NULL);
|
||||
dbuf = ISC_LIST_TAIL(client->query.namebufs);
|
||||
isc_buffer_available(&dbuf->buffer, &r);
|
||||
isc_buffer_available(dbuf, &r);
|
||||
INSIST(r.length >= 255);
|
||||
}
|
||||
return (dbuf);
|
||||
}
|
||||
|
||||
static inline void
|
||||
query_keepname(ns_client_t *client, dns_name_t *name, isc_dynbuffer_t *dbuf) {
|
||||
query_keepname(ns_client_t *client, dns_name_t *name, isc_buffer_t *dbuf) {
|
||||
isc_region_t r;
|
||||
|
||||
/*
|
||||
@@ -186,7 +186,7 @@ query_keepname(ns_client_t *client, dns_name_t *name, isc_dynbuffer_t *dbuf) {
|
||||
REQUIRE((client->query.attributes & NS_QUERYATTR_NAMEBUFUSED) != 0);
|
||||
|
||||
dns_name_toregion(name, &r);
|
||||
isc_buffer_add(&dbuf->buffer, r.length);
|
||||
isc_buffer_add(dbuf, r.length);
|
||||
dns_name_setbuffer(name, NULL);
|
||||
client->query.attributes &= ~NS_QUERYATTR_NAMEBUFUSED;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ query_releasename(ns_client_t *client, dns_name_t **namep) {
|
||||
}
|
||||
|
||||
static inline dns_name_t *
|
||||
query_newname(ns_client_t *client, isc_dynbuffer_t *dbuf,
|
||||
query_newname(ns_client_t *client, isc_buffer_t *dbuf,
|
||||
isc_buffer_t *nbuf)
|
||||
{
|
||||
dns_name_t *name;
|
||||
@@ -227,7 +227,7 @@ query_newname(ns_client_t *client, isc_dynbuffer_t *dbuf,
|
||||
return (NULL);
|
||||
} else
|
||||
ISC_LIST_UNLINK(client->query.tmpnames, name, link);
|
||||
isc_buffer_available(&dbuf->buffer, &r);
|
||||
isc_buffer_available(dbuf, &r);
|
||||
isc_buffer_init(nbuf, r.base, r.length, ISC_BUFFERTYPE_BINARY);
|
||||
dns_name_init(name, NULL);
|
||||
dns_name_setbuffer(name, nbuf);
|
||||
@@ -353,7 +353,7 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
|
||||
dns_name_t *fname, *mname;
|
||||
dns_rdataset_t *rdataset, *sigrdataset;
|
||||
dns_section_t section;
|
||||
isc_dynbuffer_t *dbuf;
|
||||
isc_buffer_t *dbuf;
|
||||
isc_buffer_t b;
|
||||
dns_dbversion_t *version;
|
||||
|
||||
@@ -544,7 +544,7 @@ query_addrdataset(ns_client_t *client, dns_name_t *fname,
|
||||
static inline void
|
||||
query_addrrset(ns_client_t *client, dns_name_t **namep,
|
||||
dns_rdataset_t **rdatasetp, dns_rdataset_t **sigrdatasetp,
|
||||
isc_dynbuffer_t *dbuf, dns_section_t section)
|
||||
isc_buffer_t *dbuf, dns_section_t section)
|
||||
{
|
||||
dns_name_t *name, *mname;
|
||||
dns_rdataset_t *rdataset, *mrdataset, *sigrdataset;
|
||||
@@ -767,7 +767,7 @@ query_find(ns_client_t *client) {
|
||||
unsigned int restarts, qcount, n, nlabels, nbits;
|
||||
dns_namereln_t namereln;
|
||||
int order;
|
||||
isc_dynbuffer_t *dbuf;
|
||||
isc_buffer_t *dbuf;
|
||||
isc_region_t r;
|
||||
isc_buffer_t b;
|
||||
isc_result_t result, eresult;
|
||||
|
||||
@@ -130,7 +130,7 @@ struct dns_message {
|
||||
dns_compress_t cctx;
|
||||
|
||||
isc_mem_t *mctx;
|
||||
ISC_LIST(isc_dynbuffer_t) scratchpad;
|
||||
isc_bufferlist_t scratchpad;
|
||||
ISC_LIST(dns_msgblock_t) names;
|
||||
ISC_LIST(dns_msgblock_t) rdatas;
|
||||
ISC_LIST(dns_msgblock_t) rdatasets;
|
||||
|
||||
@@ -164,10 +164,10 @@ static inline dns_result_t
|
||||
newbuffer(dns_message_t *msg, unsigned int size)
|
||||
{
|
||||
isc_result_t result;
|
||||
isc_dynbuffer_t *dynbuf;
|
||||
isc_buffer_t *dynbuf;
|
||||
|
||||
dynbuf = NULL;
|
||||
result = isc_dynbuffer_allocate(msg->mctx, &dynbuf, size,
|
||||
result = isc_buffer_allocate(msg->mctx, &dynbuf, size,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (DNS_R_NOMEMORY);
|
||||
@@ -179,12 +179,12 @@ newbuffer(dns_message_t *msg, unsigned int size)
|
||||
static inline isc_buffer_t *
|
||||
currentbuffer(dns_message_t *msg)
|
||||
{
|
||||
isc_dynbuffer_t *dynbuf;
|
||||
isc_buffer_t *dynbuf;
|
||||
|
||||
dynbuf = ISC_LIST_TAIL(msg->scratchpad);
|
||||
INSIST(dynbuf != NULL);
|
||||
|
||||
return (&dynbuf->buffer);
|
||||
return (dynbuf);
|
||||
}
|
||||
|
||||
static inline void
|
||||
@@ -409,7 +409,7 @@ static void
|
||||
msgreset(dns_message_t *msg, isc_boolean_t everything)
|
||||
{
|
||||
dns_msgblock_t *msgblock, *next_msgblock;
|
||||
isc_dynbuffer_t *dynbuf, *next_dynbuf;
|
||||
isc_buffer_t *dynbuf, *next_dynbuf;
|
||||
dns_rdataset_t *rds;
|
||||
dns_name_t *name;
|
||||
dns_rdata_t *rdata;
|
||||
@@ -454,13 +454,13 @@ msgreset(dns_message_t *msg, isc_boolean_t everything)
|
||||
dynbuf = ISC_LIST_HEAD(msg->scratchpad);
|
||||
INSIST(dynbuf != NULL);
|
||||
if (!everything) {
|
||||
isc_dynbuffer_reset(dynbuf);
|
||||
isc_buffer_clear(dynbuf);
|
||||
dynbuf = ISC_LIST_NEXT(dynbuf, link);
|
||||
}
|
||||
while (dynbuf != NULL) {
|
||||
next_dynbuf = ISC_LIST_NEXT(dynbuf, link);
|
||||
ISC_LIST_UNLINK(msg->scratchpad, dynbuf, link);
|
||||
isc_dynbuffer_free(msg->mctx, &dynbuf);
|
||||
isc_buffer_free(&dynbuf);
|
||||
dynbuf = next_dynbuf;
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp)
|
||||
dns_message_t *m;
|
||||
isc_result_t iresult;
|
||||
dns_msgblock_t *msgblock;
|
||||
isc_dynbuffer_t *dynbuf;
|
||||
isc_buffer_t *dynbuf;
|
||||
unsigned int i;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
@@ -580,8 +580,8 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp)
|
||||
ISC_LIST_INIT(m->freerdatalist);
|
||||
|
||||
dynbuf = NULL;
|
||||
iresult = isc_dynbuffer_allocate(mctx, &dynbuf, SCRATCHPAD_SIZE,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
iresult = isc_buffer_allocate(mctx, &dynbuf, SCRATCHPAD_SIZE,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
if (iresult != ISC_R_SUCCESS)
|
||||
goto cleanup1;
|
||||
ISC_LIST_APPEND(m->scratchpad, dynbuf, link);
|
||||
@@ -629,7 +629,7 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp)
|
||||
msgblock_free(mctx, msgblock, sizeof(dns_name_t));
|
||||
cleanup2:
|
||||
dynbuf = ISC_LIST_HEAD(m->scratchpad);
|
||||
isc_dynbuffer_free(mctx, &dynbuf);
|
||||
isc_buffer_free(&dynbuf);
|
||||
cleanup1:
|
||||
m->magic = 0;
|
||||
isc_mem_put(mctx, m, sizeof(dns_message_t));
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: tsig.c,v 1.6 1999/09/01 18:56:18 bwelling Exp $
|
||||
* $Id: tsig.c,v 1.7 1999/09/02 02:10:43 explorer Exp $
|
||||
* Principal Author: Brian Wellington
|
||||
*/
|
||||
|
||||
@@ -166,7 +166,7 @@ dns_tsig_sign(dns_message_t *msg) {
|
||||
dns_rdata_any_tsig_t *tsig;
|
||||
unsigned char data[128];
|
||||
isc_buffer_t databuf, sigbuf, rdatabuf;
|
||||
isc_dynbuffer_t *dynbuf;
|
||||
isc_buffer_t *dynbuf;
|
||||
dns_name_t *owner;
|
||||
dns_rdata_t *rdata;
|
||||
dns_rdatalist_t *datalist;
|
||||
@@ -356,7 +356,7 @@ dns_tsig_sign(dns_message_t *msg) {
|
||||
tries = 0;
|
||||
dynbuf = ISC_LIST_TAIL(msg->scratchpad);
|
||||
INSIST(dynbuf != NULL);
|
||||
rdatabuf = dynbuf->buffer;
|
||||
rdatabuf = *dynbuf;
|
||||
while (tries < 2) {
|
||||
ret = dns_rdata_fromstruct(rdata, dns_rdataclass_any,
|
||||
dns_rdatatype_tsig, tsig, &rdatabuf);
|
||||
@@ -365,12 +365,12 @@ dns_tsig_sign(dns_message_t *msg) {
|
||||
else if (ret == ISC_R_NOSPACE) {
|
||||
if (++tries == 2)
|
||||
return (ISC_R_NOMEMORY);
|
||||
ret = isc_dynbuffer_allocate(msg->mctx, &dynbuf, 512,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
ret = isc_buffer_allocate(msg->mctx, &dynbuf, 512,
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
if (ret != ISC_R_SUCCESS)
|
||||
goto cleanup_signature;
|
||||
ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);
|
||||
rdatabuf = dynbuf->buffer;
|
||||
rdatabuf = *dynbuf;
|
||||
}
|
||||
else
|
||||
goto cleanup_signature;
|
||||
|
||||
@@ -23,17 +23,14 @@
|
||||
#include <isc/buffer.h>
|
||||
|
||||
#define BUFFER_MAGIC 0x42756621U /* Buf!. */
|
||||
#define DYNBUFFER_MAGIC 0x64427566U /* dBuf. */
|
||||
|
||||
#define VALID_BUFFER(b) ((b) != NULL && \
|
||||
(b)->magic == BUFFER_MAGIC)
|
||||
|
||||
#define VALID_DYNBUFFER(b) ((b) != NULL && \
|
||||
(b)->magic == DYNBUFFER_MAGIC)
|
||||
|
||||
void
|
||||
isc_buffer_init(isc_buffer_t *b, void *base, unsigned int length,
|
||||
unsigned int type) {
|
||||
unsigned int type)
|
||||
{
|
||||
/*
|
||||
* Make 'b' refer to the 'length'-byte region starting at base.
|
||||
*/
|
||||
@@ -47,6 +44,8 @@ isc_buffer_init(isc_buffer_t *b, void *base, unsigned int length,
|
||||
b->used = 0;
|
||||
b->current = 0;
|
||||
b->active = 0;
|
||||
b->mctx = NULL;
|
||||
ISC_LINK_INIT(b, link);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -56,6 +55,8 @@ isc_buffer_invalidate(isc_buffer_t *b) {
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_BUFFER(b));
|
||||
REQUIRE(!ISC_LINK_LINKED(b, link));
|
||||
REQUIRE(b->mctx == NULL);
|
||||
|
||||
b->magic = 0;
|
||||
b->type = 0;
|
||||
@@ -390,23 +391,21 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val)
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_dynbuffer_allocate(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer,
|
||||
unsigned int length, unsigned int type)
|
||||
isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
|
||||
unsigned int length, unsigned int type)
|
||||
{
|
||||
isc_dynbuffer_t *dbuf;
|
||||
isc_buffer_t *dbuf;
|
||||
|
||||
REQUIRE(dynbuffer != NULL);
|
||||
REQUIRE(*dynbuffer == NULL);
|
||||
|
||||
dbuf = isc_mem_get(mctx, length + sizeof(isc_dynbuffer_t));
|
||||
dbuf = isc_mem_get(mctx, length + sizeof(isc_buffer_t));
|
||||
if (dbuf == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
|
||||
dbuf->magic = DYNBUFFER_MAGIC;
|
||||
ISC_LINK_INIT(dbuf, link);
|
||||
isc_buffer_init(&dbuf->buffer,
|
||||
((unsigned char *)dbuf) + sizeof(isc_dynbuffer_t),
|
||||
isc_buffer_init(dbuf, ((unsigned char *)dbuf) + sizeof(isc_buffer_t),
|
||||
length, type);
|
||||
dbuf->mctx = mctx;
|
||||
|
||||
*dynbuffer = dbuf;
|
||||
|
||||
@@ -414,28 +413,23 @@ isc_dynbuffer_allocate(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer,
|
||||
}
|
||||
|
||||
void
|
||||
isc_dynbuffer_reset(isc_dynbuffer_t *dynbuffer)
|
||||
{
|
||||
REQUIRE(VALID_DYNBUFFER(dynbuffer));
|
||||
|
||||
isc_buffer_clear(&dynbuffer->buffer);
|
||||
}
|
||||
|
||||
void
|
||||
isc_dynbuffer_free(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer)
|
||||
isc_buffer_free(isc_buffer_t **dynbuffer)
|
||||
{
|
||||
unsigned int real_length;
|
||||
isc_dynbuffer_t *dbuf;
|
||||
isc_buffer_t *dbuf;
|
||||
isc_mem_t *mctx;
|
||||
|
||||
REQUIRE(dynbuffer != NULL);
|
||||
REQUIRE(VALID_DYNBUFFER(*dynbuffer));
|
||||
REQUIRE(VALID_BUFFER(*dynbuffer));
|
||||
REQUIRE((*dynbuffer)->mctx != NULL);
|
||||
|
||||
dbuf = *dynbuffer;
|
||||
*dynbuffer = NULL; /* destroy external reference */
|
||||
|
||||
real_length = dbuf->buffer.length + sizeof(isc_dynbuffer_t);
|
||||
isc_buffer_invalidate(&dbuf->buffer);
|
||||
dbuf->magic = 0;
|
||||
real_length = dbuf->length + sizeof(isc_buffer_t);
|
||||
mctx = dbuf->mctx;
|
||||
dbuf->mctx = NULL;
|
||||
isc_buffer_invalidate(dbuf);
|
||||
|
||||
isc_mem_put(mctx, dbuf, real_length);
|
||||
}
|
||||
|
||||
@@ -125,38 +125,31 @@ ISC_LANG_BEGINDECLS
|
||||
* discouraged from directly manipulating the structure.
|
||||
*/
|
||||
|
||||
typedef struct isc_buffer {
|
||||
unsigned int magic;
|
||||
unsigned int type;
|
||||
void * base;
|
||||
typedef struct isc_buffer isc_buffer_t;
|
||||
struct isc_buffer {
|
||||
unsigned int magic;
|
||||
unsigned int type;
|
||||
void *base;
|
||||
/* The following integers are byte offsets from 'base'. */
|
||||
unsigned int length;
|
||||
unsigned int used;
|
||||
unsigned int current;
|
||||
unsigned int active;
|
||||
} isc_buffer_t;
|
||||
unsigned int length;
|
||||
unsigned int used;
|
||||
unsigned int current;
|
||||
unsigned int active;
|
||||
/* linkable */
|
||||
ISC_LINK(isc_buffer_t) link;
|
||||
/* private internal elements */
|
||||
isc_mem_t *mctx;
|
||||
};
|
||||
|
||||
/*
|
||||
* A handy thing to have, linkable buffers with built-in storage. These
|
||||
* are allocated and freed with the isc_dynbuffer_alloc() and _free()
|
||||
* functions below. These function should _ALWAYS_ be used to create these
|
||||
* dynbuffers. The link is initialized on allocation and is solely for the
|
||||
* caller to use.
|
||||
*/
|
||||
typedef struct isc_dynbuffer isc_dynbuffer_t;
|
||||
struct isc_dynbuffer {
|
||||
unsigned int magic;
|
||||
isc_buffer_t buffer;
|
||||
ISC_LINK(isc_dynbuffer_t) link;
|
||||
}; /* variable sized */
|
||||
typedef ISC_LIST(isc_buffer_t) isc_bufferlist_t;
|
||||
|
||||
/***
|
||||
*** Functions
|
||||
***/
|
||||
|
||||
isc_result_t
|
||||
isc_dynbuffer_allocate(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer,
|
||||
unsigned int length, unsigned int type);
|
||||
isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
|
||||
unsigned int length, unsigned int type);
|
||||
/*
|
||||
* Allocate a dynamic linkable buffer which has "length" bytes in the
|
||||
* data region.
|
||||
@@ -169,17 +162,13 @@ isc_dynbuffer_allocate(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer,
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS - success
|
||||
* ISC_R_NOMEMORY - no memory available
|
||||
*
|
||||
* Note:
|
||||
* Changing the buffer's length field is not permitted.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_dynbuffer_reset(isc_dynbuffer_t *dynbuffer);
|
||||
/*
|
||||
* Reset the dynamic buffer to the initial state
|
||||
*/
|
||||
|
||||
|
||||
void
|
||||
isc_dynbuffer_free(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer);
|
||||
isc_buffer_free(isc_buffer_t **dynbuffer);
|
||||
/*
|
||||
* Release resources allocated for a dynamic buffer.
|
||||
*
|
||||
@@ -188,11 +177,10 @@ isc_dynbuffer_free(isc_mem_t *mctx, isc_dynbuffer_t **dynbuffer);
|
||||
*
|
||||
* "*dynbuffer" is a valid dynamic buffer.
|
||||
*
|
||||
* "mctx" is valid.
|
||||
*
|
||||
* Ensures:
|
||||
* "*dynbuffer" will be NULL on return, and all memory associated with
|
||||
* the dynamic buffer is returned to memory context "mctx".
|
||||
* the dynamic buffer is returned to the memory context used in
|
||||
* isc_buffer_allocate().
|
||||
*/
|
||||
|
||||
void
|
||||
|
||||
@@ -61,16 +61,27 @@
|
||||
|
||||
#include <isc/lang.h>
|
||||
#include <isc/boolean.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/event.h>
|
||||
#include <isc/eventclass.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/net.h>
|
||||
#include <isc/sockaddr.h>
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
/***
|
||||
*** Constants
|
||||
***/
|
||||
|
||||
/*
|
||||
* Maximum number of buffers in a scatter/gather read/write
|
||||
*/
|
||||
#define ISC_SOCKET_MAXSCATTERGATHER 8
|
||||
|
||||
/***
|
||||
*** Types
|
||||
***/
|
||||
@@ -84,7 +95,9 @@ struct isc_socketevent {
|
||||
isc_result_t result; /* OK, EOF, whatever else */
|
||||
unsigned int minimum; /* minimum i/o for event */
|
||||
unsigned int n; /* bytes read or written */
|
||||
isc_region_t region; /* the region info */
|
||||
unsigned int offset; /* offset into buffer list */
|
||||
isc_region_t region; /* for single-buffer i/o */
|
||||
ISC_LIST(isc_buffer_t) bufferlist; /* list of buffers */
|
||||
isc_sockaddr_t address; /* source address */
|
||||
};
|
||||
|
||||
|
||||
@@ -28,13 +28,15 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <isc/assertions.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/condition.h>
|
||||
#include <isc/error.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/list.h>
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/net.h>
|
||||
#include <isc/condition.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/list.h>
|
||||
#include <isc/thread.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
@@ -186,6 +188,10 @@ static void internal_connect(isc_task_t *, isc_event_t *);
|
||||
static void internal_recv(isc_task_t *, isc_event_t *);
|
||||
static void internal_send(isc_task_t *, isc_event_t *);
|
||||
static void process_cmsg(isc_socket_t *, struct msghdr *, isc_socketevent_t *);
|
||||
static int build_msghdr_send(isc_socketevent_t *, struct msghdr *,
|
||||
struct iovec *, unsigned int maxiov);
|
||||
static int build_msghdr_recv(isc_socketevent_t *, struct msghdr *,
|
||||
struct iovec *, unsigned int maxiov);
|
||||
|
||||
#define SELECT_POKE_SHUTDOWN (-1)
|
||||
#define SELECT_POKE_NOTHING (-2)
|
||||
@@ -287,6 +293,47 @@ process_cmsg(isc_socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev)
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct an iov array and attach it to the msghdr passed in. Return
|
||||
* 0 on success, non-zero on failure. This is the SEND constructor, which
|
||||
* will used the used region of the buffer.
|
||||
*
|
||||
* Nothing can be NULL, and the done event must list at least one buffer
|
||||
* on the buffer linked list for this function to be meaningful.
|
||||
*/
|
||||
static int
|
||||
build_msghdr_send(isc_socketevent_t *dev, struct msghdr *msg,
|
||||
struct iovec *iov, unsigned int maxiov)
|
||||
{
|
||||
unsigned int iovcount;
|
||||
isc_buffer_t *buffer;
|
||||
isc_region_t used;
|
||||
|
||||
iovcount = 0;
|
||||
buffer = ISC_LIST_HEAD(dev->bufferlist);
|
||||
|
||||
for (;;) {
|
||||
if (buffer == NULL)
|
||||
break;
|
||||
|
||||
if (iovcount == maxiov)
|
||||
return (-1);
|
||||
|
||||
isc_buffer_used(buffer, &used);
|
||||
if (used.length > 0) {
|
||||
iov[iovcount].iov_base = (void *)used.base;
|
||||
iov[iovcount].iov_len = used.length;
|
||||
iovcount++;
|
||||
}
|
||||
buffer = ISC_LIST_NEXT(buffer, link);
|
||||
}
|
||||
|
||||
msg->msg_iov = iov;
|
||||
msg->msg_iovlen = iovcount;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Kill.
|
||||
*
|
||||
@@ -870,7 +917,7 @@ internal_recv(isc_task_t *me, isc_event_t *ev)
|
||||
int cc;
|
||||
size_t read_count;
|
||||
struct msghdr msghdr;
|
||||
struct iovec iov;
|
||||
struct iovec iov[ISC_SOCKET_MAXSCATTERGATHER];
|
||||
|
||||
(void)me;
|
||||
|
||||
@@ -920,8 +967,8 @@ internal_recv(isc_task_t *me, isc_event_t *ev)
|
||||
* we can.
|
||||
*/
|
||||
read_count = dev->region.length - dev->n;
|
||||
iov.iov_base = (void *)(dev->region.base + dev->n);
|
||||
iov.iov_len = read_count;
|
||||
iov[0].iov_base = (void *)(dev->region.base + dev->n);
|
||||
iov[0].iov_len = read_count;
|
||||
|
||||
memset(&msghdr, 0, sizeof (msghdr));
|
||||
if (sock->type == isc_sockettype_udp) {
|
||||
@@ -933,7 +980,7 @@ internal_recv(isc_task_t *me, isc_event_t *ev)
|
||||
msghdr.msg_namelen = 0;
|
||||
dev->address = sock->address;
|
||||
}
|
||||
msghdr.msg_iov = &iov;
|
||||
msghdr.msg_iov = iov;
|
||||
msghdr.msg_iovlen = 1;
|
||||
|
||||
#ifdef ISC_NET_BSD44MSGHDR
|
||||
@@ -1068,7 +1115,7 @@ internal_send(isc_task_t *me, isc_event_t *ev)
|
||||
int cc;
|
||||
size_t write_count;
|
||||
struct msghdr msghdr;
|
||||
struct iovec iov;
|
||||
struct iovec iov[ISC_SOCKET_MAXSCATTERGATHER];
|
||||
|
||||
(void)me;
|
||||
|
||||
@@ -1121,8 +1168,8 @@ internal_send(isc_task_t *me, isc_event_t *ev)
|
||||
* we can.
|
||||
*/
|
||||
write_count = dev->region.length - dev->n;
|
||||
iov.iov_base = (void *)(dev->region.base + dev->n);
|
||||
iov.iov_len = write_count;
|
||||
iov[0].iov_base = (void *)(dev->region.base + dev->n);
|
||||
iov[0].iov_len = write_count;
|
||||
|
||||
memset(&msghdr, 0, sizeof (msghdr));
|
||||
if (sock->type == isc_sockettype_udp) {
|
||||
@@ -1130,7 +1177,7 @@ internal_send(isc_task_t *me, isc_event_t *ev)
|
||||
msghdr.msg_namelen = dev->address.length;
|
||||
}
|
||||
|
||||
msghdr.msg_iov = &iov;
|
||||
msghdr.msg_iov = iov;
|
||||
msghdr.msg_iovlen = 1;
|
||||
|
||||
#ifdef ISC_NET_BSD44MSGHDR
|
||||
@@ -1618,6 +1665,13 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp)
|
||||
*managerp = NULL;
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
|
||||
unsigned int minimum,
|
||||
isc_task_t *task, isc_taskaction_t action, void *arg)
|
||||
{
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
|
||||
isc_task_t *task, isc_taskaction_t action, void *arg)
|
||||
@@ -1628,7 +1682,7 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
|
||||
int cc;
|
||||
isc_boolean_t was_empty;
|
||||
struct msghdr msghdr;
|
||||
struct iovec iov;
|
||||
struct iovec iov[ISC_SOCKET_MAXSCATTERGATHER];
|
||||
|
||||
REQUIRE(VALID_SOCKET(sock));
|
||||
REQUIRE(region != NULL);
|
||||
@@ -1650,6 +1704,7 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
ISC_LINK_INIT(dev, link);
|
||||
ISC_LIST_INIT(dev->bufferlist);
|
||||
|
||||
/*
|
||||
* UDP sockets are always partial read
|
||||
@@ -1675,8 +1730,8 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
|
||||
if (!was_empty)
|
||||
goto queue;
|
||||
|
||||
iov.iov_base = (void *)dev->region.base;
|
||||
iov.iov_len = dev->region.length;
|
||||
iov[0].iov_base = (void *)dev->region.base;
|
||||
iov[0].iov_len = dev->region.length;
|
||||
|
||||
memset(&msghdr, 0, sizeof(msghdr));
|
||||
if (sock->type == isc_sockettype_udp) {
|
||||
@@ -1688,7 +1743,7 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
|
||||
msghdr.msg_namelen = 0;
|
||||
dev->address = sock->address;
|
||||
}
|
||||
msghdr.msg_iov = &iov;
|
||||
msghdr.msg_iov = iov;
|
||||
msghdr.msg_iovlen = 1;
|
||||
|
||||
#ifdef ISC_NET_BSD44MSGHDR
|
||||
@@ -1832,7 +1887,7 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
|
||||
int cc;
|
||||
isc_boolean_t was_empty;
|
||||
struct msghdr msghdr;
|
||||
struct iovec iov;
|
||||
struct iovec iov[ISC_SOCKET_MAXSCATTERGATHER];
|
||||
|
||||
REQUIRE(VALID_SOCKET(sock));
|
||||
REQUIRE(region != NULL);
|
||||
@@ -1855,6 +1910,7 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
ISC_LINK_INIT(dev, link);
|
||||
ISC_LIST_INIT(dev->bufferlist);
|
||||
|
||||
dev->result = ISC_R_SUCCESS;
|
||||
dev->minimum = region->length;
|
||||
@@ -1879,8 +1935,8 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
|
||||
if (!was_empty)
|
||||
goto queue;
|
||||
|
||||
iov.iov_base = (void *)(dev->region.base);
|
||||
iov.iov_len = dev->region.length;
|
||||
iov[0].iov_base = (void *)(dev->region.base);
|
||||
iov[0].iov_len = dev->region.length;
|
||||
|
||||
memset(&msghdr, 0, sizeof (msghdr));
|
||||
if (sock->type == isc_sockettype_udp) {
|
||||
@@ -1888,7 +1944,7 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
|
||||
msghdr.msg_namelen = dev->address.length;
|
||||
}
|
||||
|
||||
msghdr.msg_iov = &iov;
|
||||
msghdr.msg_iov = iov;
|
||||
msghdr.msg_iovlen = 1;
|
||||
|
||||
#ifdef ISC_NET_BSD44MSGHDR
|
||||
@@ -2530,6 +2586,7 @@ isc_socket_recvmark(isc_socket_t *sock,
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
ISC_LINK_INIT(dev, link);
|
||||
ISC_LIST_INIT(dev->bufferlist);
|
||||
|
||||
dev->result = ISC_R_SUCCESS;
|
||||
dev->attributes = 0;
|
||||
@@ -2593,6 +2650,7 @@ isc_socket_sendmark(isc_socket_t *sock,
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
ISC_LINK_INIT(dev, link);
|
||||
ISC_LIST_INIT(dev->bufferlist);
|
||||
|
||||
dev->result = ISC_R_SUCCESS;
|
||||
dev->attributes = 0;
|
||||
|
||||
Reference in New Issue
Block a user