summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/libcli/raw/clisocket.c31
-rw-r--r--source4/libcli/raw/clitransport.c56
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 &&