From c6888da1487ab301292c3d4d05d0464833f3ce57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 28 Oct 2004 04:00:43 +0000 Subject: r3304: changed the API to lib/socket/ a little. The main change is to make socket_recv() take a pre-allocated buffer, rather than allocating one itself. This allows non-blocking users of this API to avoid a memcpy(). As a result our messaging code is now about 10% faster, and the ncacn_ip_tcp and ncalrpc code is also faster. The second change was to remove the unused mem_ctx argument from socket_send(). Having it there implied that memory could be allocated, which meant the caller had to worry about freeing that memory (if for example it is sending in a tight loop using the same memory context). Removing that unused argument keeps life simpler for users. (This used to be commit a16e4756cd68ca8aab4ffc59d4d9db0b6e44dbd1) --- source4/lib/messaging/messaging.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'source4/lib/messaging') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index afd18b4f2f..09d0c43934 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -123,22 +123,21 @@ static void messaging_recv_handler(struct event_context *ev, struct fd_event *fd if (rec->ndone < sizeof(rec->header)) { /* receive the header */ - DATA_BLOB blob; - blob.length = 0; - status = socket_recv(rec->sock, rec, - &blob, sizeof(rec->header) - rec->ndone, 0); + size_t nread; + + status = socket_recv(rec->sock, + rec->ndone + (char *)&rec->header, + sizeof(rec->header) - rec->ndone, &nread, 0); if (NT_STATUS_IS_ERR(status)) { talloc_free(rec); return; } - if (blob.length == 0) { + if (nread == 0) { return; } - memcpy(rec->ndone + (char *)&rec->header, blob.data, blob.length); - rec->ndone += blob.length; - data_blob_free(&blob); + rec->ndone += nread; if (rec->ndone == sizeof(rec->header)) { if (rec->header.version != MESSAGING_VERSION) { @@ -158,23 +157,22 @@ static void messaging_recv_handler(struct event_context *ev, struct fd_event *fd if (rec->ndone >= sizeof(rec->header) && rec->ndone < sizeof(rec->header) + rec->header.length) { /* receive the body, if any */ - DATA_BLOB blob; - blob.length = 0; - status = socket_recv(rec->sock, rec, - &blob, sizeof(rec->header) + rec->header.length - rec->ndone, 0); + size_t nread; + + status = socket_recv(rec->sock, + rec->data.data + (rec->ndone - sizeof(rec->header)), + sizeof(rec->header) + rec->header.length - rec->ndone, + &nread, 0); if (NT_STATUS_IS_ERR(status)) { talloc_free(rec); return; } - if (blob.length == 0) { + if (nread == 0) { return; } - memcpy(rec->data.data + (rec->ndone - sizeof(rec->header)), - blob.data, blob.length); - - rec->ndone += blob.length; + rec->ndone += nread; } if (rec->ndone == sizeof(rec->header) + rec->header.length) { @@ -283,7 +281,7 @@ static void messaging_send_handler(struct event_context *ev, struct fd_event *fd blob.data = rec->ndone + (char *)&rec->header; blob.length = sizeof(rec->header) - rec->ndone; - status = socket_send(rec->sock, rec, &blob, &nsent, 0); + status = socket_send(rec->sock, &blob, &nsent, 0); if (NT_STATUS_IS_ERR(status)) { talloc_free(rec); return; @@ -305,7 +303,7 @@ static void messaging_send_handler(struct event_context *ev, struct fd_event *fd blob.data = rec->data.data + (rec->ndone - sizeof(rec->header)); blob.length = rec->header.length - (rec->ndone - sizeof(rec->header)); - status = socket_send(rec->sock, rec, &blob, &nsent, 0); + status = socket_send(rec->sock, &blob, &nsent, 0); if (NT_STATUS_IS_ERR(status)) { talloc_free(rec); return; -- cgit