diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-07-13 03:01:26 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:22:58 -0500 |
commit | 562498c5260108c17add1e1a392644d188ff5c79 (patch) | |
tree | bd24a9c836a7a5bdac262004c501c3610f8e717a /source4/libcli/raw | |
parent | e2881aca86936ef4712c431b01dfab11427aea89 (diff) | |
download | samba-562498c5260108c17add1e1a392644d188ff5c79.tar.gz samba-562498c5260108c17add1e1a392644d188ff5c79.tar.bz2 samba-562498c5260108c17add1e1a392644d188ff5c79.zip |
r8407: fixed a bug left over from our old socket code.
Thanks to lha for giving me a login on a netbsd machine to see this
(This used to be commit 4e66f682e4f1c31bbe9441a13af2c245db31433d)
Diffstat (limited to 'source4/libcli/raw')
-rw-r--r-- | source4/libcli/raw/clisocket.c | 31 | ||||
-rw-r--r-- | source4/libcli/raw/clitransport.c | 56 |
2 files changed, 41 insertions, 46 deletions
diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index d6007ec8ba..b325fa473e 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -273,48 +273,33 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, size_t len) +NTSTATUS smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, + size_t len, size_t *nsent) { - NTSTATUS status; DATA_BLOB blob; - size_t nsent; if (sock->sock == NULL) { - errno = EIO; - return -1; + return NT_STATUS_CONNECTION_DISCONNECTED; } blob.data = discard_const(data); blob.length = len; - status = socket_send(sock->sock, &blob, &nsent, 0); - if (NT_STATUS_IS_ERR(status)) { - return -1; - } - - return nsent; + return socket_send(sock->sock, &blob, nsent, 0); } /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) +NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, + size_t len, size_t *nread) { - NTSTATUS status; - size_t nread; - if (sock->sock == NULL) { - errno = EIO; - return -1; - } - - status = socket_recv(sock->sock, data, len, &nread, 0); - if (NT_STATUS_IS_ERR(status)) { - return -1; + return NT_STATUS_CONNECTION_DISCONNECTED; } - return nread; + return socket_recv(sock->sock, data, len, nread, 0); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index f286eff0ea..d70d333039 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -346,17 +346,19 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport) { while (transport->pending_send) { struct smbcli_request *req = transport->pending_send; - ssize_t ret; - ret = smbcli_sock_write(transport->socket, req->out.buffer, req->out.size); - if (ret == -1) { - if (errno == EAGAIN || errno == EINTR) { - return; - } + NTSTATUS status; + size_t nwritten; + + status = smbcli_sock_write(transport->socket, req->out.buffer, + req->out.size, &nwritten); + if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + } + if (!NT_STATUS_IS_OK(status)) { return; } - req->out.buffer += ret; - req->out.size -= ret; + req->out.buffer += nwritten; + req->out.size -= nwritten; if (req->out.size == 0) { DLIST_REMOVE(transport->pending_send, req); if (req->one_way_request) { @@ -529,17 +531,21 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) 4 byte header, which tells us how much more is coming. Then we read the rest */ if (transport->recv_buffer.received < NBT_HDR_SIZE) { - ssize_t ret; - ret = smbcli_sock_read(transport->socket, - transport->recv_buffer.header + - transport->recv_buffer.received, - NBT_HDR_SIZE - transport->recv_buffer.received); - if (ret == -1) { + NTSTATUS status; + size_t nread; + status = smbcli_sock_read(transport->socket, + transport->recv_buffer.header + + transport->recv_buffer.received, + NBT_HDR_SIZE - transport->recv_buffer.received, + &nread); + if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + } + if (!NT_STATUS_IS_OK(status)) { return; } - transport->recv_buffer.received += ret; + transport->recv_buffer.received += nread; if (transport->recv_buffer.received == NBT_HDR_SIZE) { /* we've got a full header */ @@ -555,17 +561,21 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) } if (transport->recv_buffer.received < transport->recv_buffer.req_size) { - ssize_t ret; - ret = smbcli_sock_read(transport->socket, - transport->recv_buffer.buffer + - transport->recv_buffer.received, - transport->recv_buffer.req_size - - transport->recv_buffer.received); - if (ret == -1) { + NTSTATUS status; + size_t nread; + status = smbcli_sock_read(transport->socket, + transport->recv_buffer.buffer + + transport->recv_buffer.received, + transport->recv_buffer.req_size - + transport->recv_buffer.received, + &nread); + if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + } + if (!NT_STATUS_IS_OK(status)) { return; } - transport->recv_buffer.received += ret; + transport->recv_buffer.received += nread; } if (transport->recv_buffer.received != 0 && |