r8407: fixed a bug left over from our old socket code.
authorAndrew Tridgell <tridge@samba.org>
Wed, 13 Jul 2005 03:01:26 +0000 (03:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:22:58 +0000 (13:22 -0500)
Thanks to lha for giving me a login on a netbsd machine to see this

source/libcli/raw/clisocket.c
source/libcli/raw/clitransport.c

index d6007ec8ba3977cced1eae05df0e093d865b6f13..b325fa473e9b82ab87429f8647150bc8d1ef44ec 100644 (file)
@@ -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);
 }
 
 
index f286eff0ea16fd11cad4452298225bae5e2c792f..d70d33303917a8354726cf2111d7eba364e94cf7 100644 (file)
@@ -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 &&