summaryrefslogtreecommitdiff
path: root/source4/lib/socket/socket_ipv4.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-28 04:00:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:04:52 -0500
commitc6888da1487ab301292c3d4d05d0464833f3ce57 (patch)
tree35660282f621edb23885c40bfc4634489def3d6d /source4/lib/socket/socket_ipv4.c
parent9d1e2b29ebf14beae4fc63b2cb85f4e2d1798021 (diff)
downloadsamba-c6888da1487ab301292c3d4d05d0464833f3ce57.tar.gz
samba-c6888da1487ab301292c3d4d05d0464833f3ce57.tar.bz2
samba-c6888da1487ab301292c3d4d05d0464833f3ce57.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. (This used to be commit a16e4756cd68ca8aab4ffc59d4d9db0b6e44dbd1)
Diffstat (limited to 'source4/lib/socket/socket_ipv4.c')
-rw-r--r--source4/lib/socket/socket_ipv4.c41
1 files changed, 7 insertions, 34 deletions
diff --git a/source4/lib/socket/socket_ipv4.c b/source4/lib/socket/socket_ipv4.c
index f280f804ef..4de0d8cebe 100644
--- a/source4/lib/socket/socket_ipv4.c
+++ b/source4/lib/socket/socket_ipv4.c
@@ -166,18 +166,12 @@ static NTSTATUS ipv4_tcp_accept(struct socket_context *sock, struct socket_conte
return NT_STATUS_OK;
}
-static NTSTATUS ipv4_tcp_recv(struct socket_context *sock, TALLOC_CTX *mem_ctx,
- DATA_BLOB *blob, size_t wantlen, uint32_t flags)
+static NTSTATUS ipv4_tcp_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;
@@ -187,42 +181,21 @@ static NTSTATUS ipv4_tcp_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 = NT_STATUS_UNSUCCESSFUL;
- switch (errno) {
- case EBADF:
- case ENOTCONN:
- case ENOTSOCK:
- case EFAULT:
- case EINVAL:
- status = NT_STATUS_INVALID_PARAMETER;
- break;
- case EAGAIN:
- case EINTR:
- status = STATUS_MORE_ENTRIES;
- break;
- case ECONNREFUSED:
- status = NT_STATUS_CONNECTION_REFUSED;
- break;
- }
- talloc_free(buf);
- return status;
+ return map_nt_error_from_unix(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 ipv4_tcp_send(struct socket_context *sock, TALLOC_CTX *mem_ctx,
+static NTSTATUS ipv4_tcp_send(struct socket_context *sock,
const DATA_BLOB *blob, size_t *sendlen, uint32_t flags)
{
ssize_t len;