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/smb_server/smb_server.c | |
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/smb_server/smb_server.c')
-rw-r--r-- | source4/smb_server/smb_server.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index b7d54c8dee..d6022ef63e 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -64,17 +64,19 @@ static struct smbsrv_request *receive_smb_request(struct smbsrv_connection *smb_ ssize_t len, len2; DATA_BLOB tmp_blob; struct smbsrv_request *req; + char hdr[4]; + size_t nread; - status = socket_recv(smb_conn->connection->socket, smb_conn, &tmp_blob, 4, SOCKET_FLAG_BLOCK|SOCKET_FLAG_PEEK); + status = socket_recv(smb_conn->connection->socket, hdr, + 4, &nread, SOCKET_FLAG_BLOCK|SOCKET_FLAG_PEEK); if (!NT_STATUS_IS_OK(status)) { return NULL; } - if (tmp_blob.length != 4) { + if (nread != 4) { return NULL; } - len = smb_len(tmp_blob.data); - talloc_free(tmp_blob.data); + len = smb_len(hdr); req = init_smb_request(smb_conn); @@ -83,11 +85,18 @@ static struct smbsrv_request *receive_smb_request(struct smbsrv_connection *smb_ len2 = len + NBT_HDR_SIZE; - status = socket_recv(smb_conn->connection->socket, req, &tmp_blob, len2, SOCKET_FLAG_BLOCK); + tmp_blob = data_blob_talloc(req, NULL, len2); + if (tmp_blob.data == NULL) { + return NULL; + } + + status = socket_recv(smb_conn->connection->socket, + tmp_blob.data, len2, + &nread, SOCKET_FLAG_BLOCK); if (!NT_STATUS_IS_OK(status)) { return NULL; } - if (tmp_blob.length != len2) { + if (nread != len2) { return NULL; } |