diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-10-28 04:00:43 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:04:52 -0500 |
commit | c6888da1487ab301292c3d4d05d0464833f3ce57 (patch) | |
tree | 35660282f621edb23885c40bfc4634489def3d6d /source4/rpc_server | |
parent | 9d1e2b29ebf14beae4fc63b2cb85f4e2d1798021 (diff) | |
download | samba-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/rpc_server')
-rw-r--r-- | source4/rpc_server/dcerpc_sock.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/source4/rpc_server/dcerpc_sock.c b/source4/rpc_server/dcerpc_sock.c index 79d1f5a3bb..32d1f0df35 100644 --- a/source4/rpc_server/dcerpc_sock.c +++ b/source4/rpc_server/dcerpc_sock.c @@ -38,7 +38,7 @@ static ssize_t dcerpc_write_fn(void *private, DATA_BLOB *out) struct socket_context *sock = private; size_t sendlen; - status = socket_send(sock, sock, out, &sendlen, 0); + status = socket_send(sock, out, &sendlen, 0); if (!NT_STATUS_IS_OK(status)) { return -1; } @@ -131,7 +131,7 @@ static void add_socket_rpc_tcp_iface(struct server_service *service, struct server_socket *sock; struct dcesrv_socket_context *dcesrv_sock; uint16_t port = 0; - const char *ip_str = talloc_strdup(service, inet_ntoa(*ifip)); + char *ip_str = talloc_strdup(service, inet_ntoa(*ifip)); if (e->ep_description.endpoint) port = atoi(e->ep_description.endpoint); @@ -251,22 +251,30 @@ void dcesrv_sock_recv(struct server_connection *conn, time_t t, uint16_t flags) NTSTATUS status; struct dcesrv_connection *dce_conn = conn->private_data; DATA_BLOB tmp_blob; + size_t nread; - DEBUG(10,("dcesrv_sock_recv\n")); + tmp_blob = data_blob_talloc(conn->socket, NULL, 0x1000); + if (tmp_blob.data == NULL) { + dcesrv_terminate_connection(dce_conn, "out of memory"); + return; + } - status = socket_recv(conn->socket, conn->socket, &tmp_blob, 0x4000, 0); - if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_IS_ERR(status)) { - dcesrv_terminate_connection(dce_conn, "eof on socket"); - return; - } + status = socket_recv(conn->socket, tmp_blob.data, tmp_blob.length, &nread, 0); + if (NT_STATUS_IS_ERR(status)) { + dcesrv_terminate_connection(dce_conn, nt_errstr(status)); return; } + if (nread == 0) { + return; + } + + tmp_blob.length = nread; status = dcesrv_input(dce_conn, &tmp_blob); talloc_free(tmp_blob.data); + if (!NT_STATUS_IS_OK(status)) { - dcesrv_terminate_connection(dce_conn, "eof on socket"); + dcesrv_terminate_connection(dce_conn, nt_errstr(status)); return; } |