aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-08-29 14:39:33 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-08-29 14:39:33 +0000
commit5acadc9cd7a1ff40ffa8d57214c90d8c788b2b03 (patch)
tree3c417bc272e9a97f8ae763406c8151cea2fa7d74 /lib
parent2ff609dd43cb5c1c0da893c080132a48a2d4c73b (diff)
David McCreedy added CURLOPT_SOCKOPTFUNCTION and CURLOPT_SOCKOPTDATA to
allow applications to set their own socket options.
Diffstat (limited to 'lib')
-rw-r--r--lib/connect.c11
-rw-r--r--lib/setup.h13
-rw-r--r--lib/url.c14
-rw-r--r--lib/urldata.h2
4 files changed, 27 insertions, 13 deletions
diff --git a/lib/connect.c b/lib/connect.c
index 95fdf8119..4e7f4f8ea 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -702,6 +702,17 @@ singleipconnect(struct connectdata *conn,
nosigpipe(conn, sockfd);
+ if(data->set.fsockopt) {
+ /* activate callback for setting socket options */
+ error = data->set.fsockopt(data->set.sockopt_client,
+ sockfd,
+ CURLSOCKTYPE_IPCXN);
+ if (error) {
+ sclose(sockfd); /* close the socket and bail out */
+ return CURL_SOCKET_BAD;
+ }
+ }
+
/* possibly bind the local end to an IP, interface or port */
res = bindlocal(conn, sockfd);
if(res) {
diff --git a/lib/setup.h b/lib/setup.h
index 3538256c4..1e64c928a 100644
--- a/lib/setup.h
+++ b/lib/setup.h
@@ -278,19 +278,6 @@ int fileno( FILE *stream);
#endif /* WIN32 */
-#ifndef curl_socket_typedef
-/* now typedef our socket type */
-#ifdef WIN32
-typedef SOCKET curl_socket_t;
-#define CURL_SOCKET_BAD INVALID_SOCKET
-#else
-typedef int curl_socket_t;
-#define CURL_SOCKET_BAD -1
-#endif
-#define curl_socket_typedef
-#endif /* curl_socket_typedef */
-
-
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(USE_ARES) && \
!defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */
#ifdef ENABLE_IPV6
diff --git a/lib/url.c b/lib/url.c
index c0641c78b..17f543615 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -1551,6 +1551,20 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
data->set.ftp_alternative_to_user = va_arg(param, char *);
break;
+ case CURLOPT_SOCKOPTFUNCTION:
+ /*
+ * socket callback function: called after socket() but before connect()
+ */
+ data->set.fsockopt = va_arg(param, curl_sockopt_callback);
+ break;
+
+ case CURLOPT_SOCKOPTDATA:
+ /*
+ * socket callback data pointer. Might be NULL.
+ */
+ data->set.sockopt_client = va_arg(param, void *);
+ break;
+
default:
/* unknown tag and its companion, just ignore: */
result = CURLE_FAILED_INIT; /* correct this */
diff --git a/lib/urldata.h b/lib/urldata.h
index 33f7ee860..5acac2c53 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1029,6 +1029,8 @@ struct UserDefined {
curl_progress_callback fprogress; /* function for progress information */
curl_debug_callback fdebug; /* function that write informational data */
curl_ioctl_callback ioctl; /* function for I/O control */
+ curl_sockopt_callback fsockopt; /* function for setting socket options */
+ void *sockopt_client; /* pointer to pass to the socket options callback */
/* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
/* function to convert from the network encoding: */