summaryrefslogtreecommitdiffstats
path: root/source4/ldap_server
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/ldap_server
parent9d1e2b29ebf14beae4fc63b2cb85f4e2d1798021 (diff)
downloadsamba-c6888da1487ab301292c3d4d05d0464833f3ce57.tar.gz
samba-c6888da1487ab301292c3d4d05d0464833f3ce57.tar.xz
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/ldap_server')
-rw-r--r--source4/ldap_server/ldap_server.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c
index 6ce2dfdd79..70191c4827 100644
--- a/source4/ldap_server/ldap_server.c
+++ b/source4/ldap_server/ldap_server.c
@@ -155,10 +155,17 @@ static BOOL read_into_buf(struct socket_context *sock, struct rw_buffer *buf)
NTSTATUS status;
DATA_BLOB tmp_blob;
BOOL ret;
+ size_t nread;
- status = socket_recv(sock, sock, &tmp_blob, 1024, 0);
+ tmp_blob = data_blob_talloc(sock, NULL, 1024);
+ if (tmp_blob.data == NULL) {
+ return False;
+ }
+
+ status = socket_recv(sock, tmp_blob.data, tmp_blob.length, &nread, 0);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("socket_recv: %s\n",nt_errstr(status)));
+ talloc_free(tmp_blob.data);
return False;
}
@@ -179,6 +186,7 @@ static BOOL ldapsrv_read_buf(struct ldapsrv_connection *conn)
int buf_length, sasl_length;
struct socket_context *sock = conn->connection->socket;
TALLOC_CTX *mem_ctx;
+ size_t nread;
if (!conn->gensec || !conn->session_info ||
!(gensec_have_feature(conn->gensec, GENSEC_WANT_SIGN) &&
@@ -192,12 +200,19 @@ static BOOL ldapsrv_read_buf(struct ldapsrv_connection *conn)
return False;
}
- status = socket_recv(sock, mem_ctx, &tmp_blob, 1024, 0);
+ tmp_blob = data_blob_talloc(mem_ctx, NULL, 1024);
+ if (tmp_blob.data == NULL) {
+ talloc_free(mem_ctx);
+ return False;
+ }
+
+ status = socket_recv(sock, tmp_blob.data, tmp_blob.length, &nread, 0);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("socket_recv: %s\n",nt_errstr(status)));
talloc_free(mem_ctx);
return False;
}
+ tmp_blob.length = nread;
ret = ldapsrv_append_to_buf(&conn->sasl_in_buffer, tmp_blob.data, tmp_blob.length);
if (!ret) {
@@ -276,7 +291,7 @@ static BOOL write_from_buf(struct socket_context *sock, struct rw_buffer *buf)
tmp_blob.data = buf->data;
tmp_blob.length = buf->length;
- status = socket_send(sock, sock, &tmp_blob, &sendlen, 0);
+ status = socket_send(sock, &tmp_blob, &sendlen, 0);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("socket_send() %s\n",nt_errstr(status)));
return False;
@@ -360,7 +375,7 @@ nodata:
tmp_blob.data = conn->sasl_out_buffer.data;
tmp_blob.length = conn->sasl_out_buffer.length;
- status = socket_send(sock, mem_ctx, &tmp_blob, &sendlen, 0);
+ status = socket_send(sock, &tmp_blob, &sendlen, 0);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("socket_send() %s\n",nt_errstr(status)));
talloc_free(mem_ctx);