svn commit: samba r15349 - in branches/SAMBA_4_0/source/lib: socket util

jelmer at samba.org jelmer at samba.org
Sun Apr 30 01:33:05 GMT 2006


Author: jelmer
Date: 2006-04-30 01:32:59 +0000 (Sun, 30 Apr 2006)
New Revision: 15349

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15349

Log:
Integrate set_socket_options() into the socket library

Removed:
   branches/SAMBA_4_0/source/lib/util/util_sock.c
Modified:
   branches/SAMBA_4_0/source/lib/socket/socket.c
   branches/SAMBA_4_0/source/lib/socket/socket.h
   branches/SAMBA_4_0/source/lib/util/config.mk


Changeset:
Modified: branches/SAMBA_4_0/source/lib/socket/socket.c
===================================================================
--- branches/SAMBA_4_0/source/lib/socket/socket.c	2006-04-30 01:08:52 UTC (rev 15348)
+++ branches/SAMBA_4_0/source/lib/socket/socket.c	2006-04-30 01:32:59 UTC (rev 15349)
@@ -1,6 +1,8 @@
 /* 
    Unix SMB/CIFS implementation.
    Socket functions
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Tim Potter      2000-2001
    Copyright (C) Stefan Metzmacher 2004
    
    This program is free software; you can redistribute it and/or modify
@@ -21,6 +23,7 @@
 #include "includes.h"
 #include "lib/socket/socket.h"
 #include "system/filesys.h"
+#include "system/network.h"
 
 /*
   auto-close sockets on free
@@ -429,3 +432,108 @@
 
 	return NULL;
 }
+
+enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
+
+static const struct {
+	const char *name;
+	int level;
+	int option;
+	int value;
+	int opttype;
+} socket_options[] = {
+  {"SO_KEEPALIVE",      SOL_SOCKET,    SO_KEEPALIVE,    0,                 OPT_BOOL},
+  {"SO_REUSEADDR",      SOL_SOCKET,    SO_REUSEADDR,    0,                 OPT_BOOL},
+  {"SO_BROADCAST",      SOL_SOCKET,    SO_BROADCAST,    0,                 OPT_BOOL},
+#ifdef TCP_NODELAY
+  {"TCP_NODELAY",       IPPROTO_TCP,   TCP_NODELAY,     0,                 OPT_BOOL},
+#endif
+#ifdef IPTOS_LOWDELAY
+  {"IPTOS_LOWDELAY",    IPPROTO_IP,    IP_TOS,          IPTOS_LOWDELAY,    OPT_ON},
+#endif
+#ifdef IPTOS_THROUGHPUT
+  {"IPTOS_THROUGHPUT",  IPPROTO_IP,    IP_TOS,          IPTOS_THROUGHPUT,  OPT_ON},
+#endif
+#ifdef SO_REUSEPORT
+  {"SO_REUSEPORT",      SOL_SOCKET,    SO_REUSEPORT,    0,                 OPT_BOOL},
+#endif
+#ifdef SO_SNDBUF
+  {"SO_SNDBUF",         SOL_SOCKET,    SO_SNDBUF,       0,                 OPT_INT},
+#endif
+#ifdef SO_RCVBUF
+  {"SO_RCVBUF",         SOL_SOCKET,    SO_RCVBUF,       0,                 OPT_INT},
+#endif
+#ifdef SO_SNDLOWAT
+  {"SO_SNDLOWAT",       SOL_SOCKET,    SO_SNDLOWAT,     0,                 OPT_INT},
+#endif
+#ifdef SO_RCVLOWAT
+  {"SO_RCVLOWAT",       SOL_SOCKET,    SO_RCVLOWAT,     0,                 OPT_INT},
+#endif
+#ifdef SO_SNDTIMEO
+  {"SO_SNDTIMEO",       SOL_SOCKET,    SO_SNDTIMEO,     0,                 OPT_INT},
+#endif
+#ifdef SO_RCVTIMEO
+  {"SO_RCVTIMEO",       SOL_SOCKET,    SO_RCVTIMEO,     0,                 OPT_INT},
+#endif
+  {NULL,0,0,0,0}};
+
+
+/**
+ Set user socket options.
+**/
+_PUBLIC_ void set_socket_options(int fd, const char *options)
+{
+	const char **options_list = str_list_make(NULL, options, " \t,");
+	int j;
+
+	if (!options_list)
+		return;
+
+	for (j = 0; options_list[j]; j++) {
+		const char *tok = options_list[j];
+		int ret=0,i;
+		int value = 1;
+		char *p;
+		BOOL got_value = False;
+
+		if ((p = strchr(tok,'='))) {
+			*p = 0;
+			value = atoi(p+1);
+			got_value = True;
+		}
+
+		for (i=0;socket_options[i].name;i++)
+			if (strequal(socket_options[i].name,tok))
+				break;
+
+		if (!socket_options[i].name) {
+			DEBUG(0,("Unknown socket option %s\n",tok));
+			continue;
+		}
+
+		switch (socket_options[i].opttype) {
+		case OPT_BOOL:
+		case OPT_INT:
+			ret = setsockopt(fd,socket_options[i].level,
+						socket_options[i].option,(char *)&value,sizeof(int));
+			break;
+
+		case OPT_ON:
+			if (got_value)
+				DEBUG(0,("syntax error - %s does not take a value\n",tok));
+
+			{
+				int on = socket_options[i].value;
+				ret = setsockopt(fd,socket_options[i].level,
+							socket_options[i].option,(char *)&on,sizeof(int));
+			}
+			break;	  
+		}
+      
+		if (ret != 0)
+			DEBUG(0,("Failed to set socket option %s (Error %s)\n",tok, strerror(errno) ));
+	}
+
+	talloc_free(options_list);
+}
+

Modified: branches/SAMBA_4_0/source/lib/socket/socket.h
===================================================================
--- branches/SAMBA_4_0/source/lib/socket/socket.h	2006-04-30 01:08:52 UTC (rev 15348)
+++ branches/SAMBA_4_0/source/lib/socket/socket.h	2006-04-30 01:32:59 UTC (rev 15349)
@@ -185,5 +185,6 @@
 			      struct event_context *event_ctx,
 			      struct socket_context **result,
 			      uint16_t *port);
+void set_socket_options(int fd, const char *options);
 
 #endif /* _SAMBA_SOCKET_H */

Modified: branches/SAMBA_4_0/source/lib/util/config.mk
===================================================================
--- branches/SAMBA_4_0/source/lib/util/config.mk	2006-04-30 01:08:52 UTC (rev 15348)
+++ branches/SAMBA_4_0/source/lib/util/config.mk	2006-04-30 01:32:59 UTC (rev 15349)
@@ -22,7 +22,6 @@
 		util_file.o \
 		data_blob.o \
 		util.o \
-		util_sock.o \
 		substitute.o \
 		fsusage.o \
 		ms_fnmatch.o \

Deleted: branches/SAMBA_4_0/source/lib/util/util_sock.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/util_sock.c	2006-04-30 01:08:52 UTC (rev 15348)
+++ branches/SAMBA_4_0/source/lib/util/util_sock.c	2006-04-30 01:32:59 UTC (rev 15349)
@@ -1,133 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   Samba utility functions
-   Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Tim Potter      2000-2001
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-#include "system/network.h"
-
-/**
- * @file
- * @brief Socket utility functions
- */
-
-enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
-
-static const struct {
-	const char *name;
-	int level;
-	int option;
-	int value;
-	int opttype;
-} socket_options[] = {
-  {"SO_KEEPALIVE",      SOL_SOCKET,    SO_KEEPALIVE,    0,                 OPT_BOOL},
-  {"SO_REUSEADDR",      SOL_SOCKET,    SO_REUSEADDR,    0,                 OPT_BOOL},
-  {"SO_BROADCAST",      SOL_SOCKET,    SO_BROADCAST,    0,                 OPT_BOOL},
-#ifdef TCP_NODELAY
-  {"TCP_NODELAY",       IPPROTO_TCP,   TCP_NODELAY,     0,                 OPT_BOOL},
-#endif
-#ifdef IPTOS_LOWDELAY
-  {"IPTOS_LOWDELAY",    IPPROTO_IP,    IP_TOS,          IPTOS_LOWDELAY,    OPT_ON},
-#endif
-#ifdef IPTOS_THROUGHPUT
-  {"IPTOS_THROUGHPUT",  IPPROTO_IP,    IP_TOS,          IPTOS_THROUGHPUT,  OPT_ON},
-#endif
-#ifdef SO_REUSEPORT
-  {"SO_REUSEPORT",      SOL_SOCKET,    SO_REUSEPORT,    0,                 OPT_BOOL},
-#endif
-#ifdef SO_SNDBUF
-  {"SO_SNDBUF",         SOL_SOCKET,    SO_SNDBUF,       0,                 OPT_INT},
-#endif
-#ifdef SO_RCVBUF
-  {"SO_RCVBUF",         SOL_SOCKET,    SO_RCVBUF,       0,                 OPT_INT},
-#endif
-#ifdef SO_SNDLOWAT
-  {"SO_SNDLOWAT",       SOL_SOCKET,    SO_SNDLOWAT,     0,                 OPT_INT},
-#endif
-#ifdef SO_RCVLOWAT
-  {"SO_RCVLOWAT",       SOL_SOCKET,    SO_RCVLOWAT,     0,                 OPT_INT},
-#endif
-#ifdef SO_SNDTIMEO
-  {"SO_SNDTIMEO",       SOL_SOCKET,    SO_SNDTIMEO,     0,                 OPT_INT},
-#endif
-#ifdef SO_RCVTIMEO
-  {"SO_RCVTIMEO",       SOL_SOCKET,    SO_RCVTIMEO,     0,                 OPT_INT},
-#endif
-  {NULL,0,0,0,0}};
-
-
-/**
- Set user socket options.
-**/
-_PUBLIC_ void set_socket_options(int fd, const char *options)
-{
-	const char **options_list = str_list_make(NULL, options, " \t,");
-	int j;
-
-	if (!options_list)
-		return;
-
-	for (j = 0; options_list[j]; j++) {
-		const char *tok = options_list[j];
-		int ret=0,i;
-		int value = 1;
-		char *p;
-		BOOL got_value = False;
-
-		if ((p = strchr(tok,'='))) {
-			*p = 0;
-			value = atoi(p+1);
-			got_value = True;
-		}
-
-		for (i=0;socket_options[i].name;i++)
-			if (strequal(socket_options[i].name,tok))
-				break;
-
-		if (!socket_options[i].name) {
-			DEBUG(0,("Unknown socket option %s\n",tok));
-			continue;
-		}
-
-		switch (socket_options[i].opttype) {
-		case OPT_BOOL:
-		case OPT_INT:
-			ret = setsockopt(fd,socket_options[i].level,
-						socket_options[i].option,(char *)&value,sizeof(int));
-			break;
-
-		case OPT_ON:
-			if (got_value)
-				DEBUG(0,("syntax error - %s does not take a value\n",tok));
-
-			{
-				int on = socket_options[i].value;
-				ret = setsockopt(fd,socket_options[i].level,
-							socket_options[i].option,(char *)&on,sizeof(int));
-			}
-			break;	  
-		}
-      
-		if (ret != 0)
-			DEBUG(0,("Failed to set socket option %s (Error %s)\n",tok, strerror(errno) ));
-	}
-
-	talloc_free(options_list);
-}
-



More information about the samba-cvs mailing list