diff options
author | Daniel Stenberg <daniel@haxx.se> | 2006-07-26 22:19:42 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2006-07-26 22:19:42 +0000 |
commit | 6f6b93da02019141812b81bfdbb6bcda430c3b4d (patch) | |
tree | b7c63e529d88edfbfebd5aaeb4570bd26f2b1cef /hiper | |
parent | 45b1843dc9d5b283e5fd892dd74415e0e2a426a7 (diff) |
[Hiper-related work] Added a function called curl_multi_assign() that will
set a private pointer added to the internal libcurl hash table for the
particular socket passed in to this function.
Diffstat (limited to 'hiper')
-rw-r--r-- | hiper/STATUS | 22 | ||||
-rw-r--r-- | hiper/hipev.c | 53 |
2 files changed, 41 insertions, 34 deletions
diff --git a/hiper/STATUS b/hiper/STATUS index df8f4515c..6b3e511f4 100644 --- a/hiper/STATUS +++ b/hiper/STATUS @@ -267,3 +267,25 @@ April 20, 2006 using the same socket. I've cleaned up and simplified code now to adjust to this. +--------------------------------------------------------------------------- + +July 9, 2006 + + TODO: We need to alter how we use c-ares for getting info about its sockets, + as c-ares now provides a callback approach very similar to how libcurl is + about to work. + + I'm adding a function called curl_multi_assign() that will set a private + pointer added to the internal libcurl hash table for the particular socket + passed in to this function: + + CURLMcode curl_multi_assign(CURLM *multi_handle, + curl_socket_t sockfd, + void *sockp); + + 'sockp' being a custom pointer set by the application to be associated with + this socket. The socket has to be already existing and in-use by libcurl, + like having already called the callback telling about its existance. + + The set hashp pointer will then be passed on to the callback in upcoming + calls when this same socket is used (in the brand new 'socketp' argument). diff --git a/hiper/hipev.c b/hiper/hipev.c index d82d7349f..b5a015918 100644 --- a/hiper/hipev.c +++ b/hiper/hipev.c @@ -88,36 +88,16 @@ struct fdinfo { static struct fdinfo *allsocks; -static struct fdinfo *findsock(curl_socket_t s) +static void remsock(struct fdinfo *f) { - /* return the struct for the given socket */ - struct fdinfo *fdp = allsocks; - - while(fdp) { - if(fdp->sockfd == s) - break; - fdp = fdp->next; - } - return fdp; /* a struct pointer or NULL */ -} - -static void remsock(curl_socket_t s) -{ - struct fdinfo *fdp = allsocks; - - while(fdp) { - if(fdp->sockfd == s) - break; - fdp = fdp->next; - } - if(!fdp) + if(!f) /* did not find socket to remove! */ return; - if(fdp->prev) - fdp->prev->next = fdp->next; - if(fdp->next) - fdp->next->prev = fdp->prev; + if(f->prev) + f->prev->next = f->next; + if(f->next) + f->next->prev = f->prev; else /* this was the last entry */ allsocks = NULL; @@ -131,7 +111,7 @@ static void setsock(struct fdinfo *fdp, curl_socket_t s, CURL *easy, fdp->easy = easy; } -static void addsock(curl_socket_t s, CURL *easy, int action) +static void addsock(curl_socket_t s, CURL *easy, int action, CURLM *multi) { struct fdinfo *fdp = calloc(sizeof(struct fdinfo), 1); @@ -146,6 +126,9 @@ static void addsock(curl_socket_t s, CURL *easy, int action) } else allsocks = fdp; + + /* Set this association in libcurl */ + curl_multi_assign(multi, s, fdp); } static void fdinfo2fdset(fd2_set *fdread, fd2_set *fdwrite, int *maxfd) @@ -201,18 +184,20 @@ static void fdinfo2fdset(fd2_set *fdread, fd2_set *fdwrite, int *maxfd) static int socket_callback(CURL *easy, /* easy handle */ curl_socket_t s, /* socket */ int what, /* see above */ - void *userp) /* "private" pointer */ + void *cbp, /* callback pointer */ + void *socketp) /* socket pointer */ { - struct fdinfo *fdp; + struct fdinfo *fdp = (struct fdinfo *)socketp; + printf("socket %d easy %p what %d\n", s, easy, what); if(what == CURL_POLL_REMOVE) - remsock(s); + remsock(fdp); else { - fdp = findsock(s); - if(!fdp) { - addsock(s, easy, what); + /* not previously known, add it and set association */ + printf("Add info for socket %d (%d)\n", s, what); + addsock(s, easy, what, cbp); } else { /* we already know about it, just change action/timeout */ @@ -443,7 +428,7 @@ int main(int argc, char **argv) } curl_multi_setopt(multi_handle, CURLMOPT_SOCKETFUNCTION, socket_callback); - curl_multi_setopt(multi_handle, CURLMOPT_SOCKETDATA, NULL); + curl_multi_setopt(multi_handle, CURLMOPT_SOCKETDATA, multi_handle); /* we start the action by calling *socket() right away */ while(CURLM_CALL_MULTI_PERFORM == curl_multi_socket_all(multi_handle)); |