s3: Adding TCP_KEEPALIVE_THRESHOLD and TCP_KEEPALIVE_ABORT_THRESHOLD to the list...
[mat/samba.git] / source3 / lib / util_sock.c
index 756ce96abc3d1fe3d42276c9b9a7eda07357252c..6782249bf6e5ad554fe7c22b55b07efca6e56048 100644 (file)
@@ -20,6 +20,9 @@
 */
 
 #include "includes.h"
+#include "memcache.h"
+#include "../lib/async_req/async_sock.h"
+#include "../lib/util/select.h"
 
 /****************************************************************************
  Get a port number in host byte order from a sockaddr_storage.
@@ -285,6 +288,12 @@ static const smb_socket_option socket_options[] = {
 #endif
 #ifdef TCP_QUICKACK
   {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL},
+#endif
+#ifdef TCP_KEEPALIVE_THRESHOLD
+  {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT},
+#endif
+#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD
+  {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT},
 #endif
   {NULL,0,0,0,0}};
 
@@ -442,7 +451,6 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
        ssize_t readret;
        size_t nread = 0;
        struct timeval timeout;
-       int save_errno;
 
        /* just checking .... */
        if (maxcnt <= 0)
@@ -464,7 +472,7 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
                        }
 
                        if (readret == -1) {
-                               return map_nt_error_from_unix(save_errno);
+                               return map_nt_error_from_unix(errno);
                        }
                        nread += readret;
                }
@@ -489,7 +497,7 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
 
                /* Check if error */
                if (selrtn == -1) {
-                       return map_nt_error_from_unix(save_errno);
+                       return map_nt_error_from_unix(errno);
                }
 
                /* Did we timeout ? */
@@ -667,48 +675,6 @@ NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
        return NT_STATUS_OK;
 }
 
-/****************************************************************************
- Read 4 bytes of a smb packet and return the smb length of the packet.
- Store the result in the buffer. This version of the function will
- never return a session keepalive (length of zero).
- Timeout is in milliseconds.
-****************************************************************************/
-
-NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout,
-                        size_t *len)
-{
-       uint8_t msgtype = SMBkeepalive;
-
-       while (msgtype == SMBkeepalive) {
-               NTSTATUS status;
-
-               status = read_smb_length_return_keepalive(fd, inbuf, timeout,
-                                                         len);
-               if (!NT_STATUS_IS_OK(status)) {
-                       if (fd == smbd_server_fd()) {
-                               char addr[INET6_ADDRSTRLEN];
-                               /* Try and give an error message
-                                * saying what client failed. */
-                               DEBUG(0, ("read_fd_with_timeout failed for "
-                                         "client %s read error = %s.\n",
-                                         get_peer_addr(fd,addr,sizeof(addr)),
-                                         nt_errstr(status)));
-                       } else {
-                               DEBUG(0, ("read_fd_with_timeout failed, read "
-                                         "error = %s.\n", nt_errstr(status)));
-                       }
-                       return status;
-               }
-
-               msgtype = CVAL(inbuf, 0);
-       }
-
-       DEBUG(10,("read_smb_length: got smb length of %lu\n",
-                 (unsigned long)len));
-
-       return NT_STATUS_OK;
-}
-
 /****************************************************************************
  Read an smb from a fd.
  The timeout is in milliseconds.