summaryrefslogtreecommitdiffstats
path: root/source/lib/socket/socket_unix.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-28 04:00:43 +0000
committerAndrew Tridgell <tridge@samba.org>2004-10-28 04:00:43 +0000
commit418e105907dde2e573f597392057656b4c834753 (patch)
tree2a55c358ef04696198a7cc666f2ad580a251c334 /source/lib/socket/socket_unix.c
parentbc0fcbe831fea003b515608a5c32194910d689a9 (diff)
downloadsamba-418e105907dde2e573f597392057656b4c834753.tar.gz
samba-418e105907dde2e573f597392057656b4c834753.tar.xz
samba-418e105907dde2e573f597392057656b4c834753.zip
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.
Diffstat (limited to 'source/lib/socket/socket_unix.c')
-rw-r--r--source/lib/socket/socket_unix.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/source/lib/socket/socket_unix.c b/source/lib/socket/socket_unix.c
index eda1597df7d..3a3ce5fe8af 100644
--- a/source/lib/socket/socket_unix.c
+++ b/source/lib/socket/socket_unix.c
@@ -155,18 +155,12 @@ static NTSTATUS unixdom_accept(struct socket_context *sock,
return NT_STATUS_OK;
}
-static NTSTATUS unixdom_recv(struct socket_context *sock, TALLOC_CTX *mem_ctx,
- DATA_BLOB *blob, size_t wantlen, uint32_t flags)
+static NTSTATUS unixdom_recv(struct socket_context *sock, void *buf,
+ size_t wantlen, size_t *nread, uint32_t flags)
{
ssize_t gotlen;
- void *buf;
int flgs = 0;
- buf = talloc(mem_ctx, wantlen);
- if (!buf) {
- return NT_STATUS_NO_MEMORY;
- }
-
/* TODO: we need to map all flags here */
if (flags & SOCKET_FLAG_PEEK) {
flgs |= MSG_PEEK;
@@ -176,26 +170,21 @@ static NTSTATUS unixdom_recv(struct socket_context *sock, TALLOC_CTX *mem_ctx,
flgs |= MSG_WAITALL;
}
+ *nread = 0;
+
gotlen = recv(sock->fd, buf, wantlen, flgs);
if (gotlen == 0) {
- talloc_free(buf);
return NT_STATUS_END_OF_FILE;
} else if (gotlen == -1) {
- NTSTATUS status = unixdom_error(errno);
- talloc_free(buf);
- return status;
+ return unixdom_error(errno);
}
- blob->length = gotlen;
- blob->data = talloc_realloc(mem_ctx, buf, gotlen);
- if (!blob->data) {
- return NT_STATUS_NO_MEMORY;
- }
+ *nread = gotlen;
return NT_STATUS_OK;
}
-static NTSTATUS unixdom_send(struct socket_context *sock, TALLOC_CTX *mem_ctx,
+static NTSTATUS unixdom_send(struct socket_context *sock,
const DATA_BLOB *blob, size_t *sendlen, uint32_t flags)
{
ssize_t len;