aboutsummaryrefslogtreecommitdiff
path: root/hiper/hipev.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-07-26 22:19:42 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-07-26 22:19:42 +0000
commit6f6b93da02019141812b81bfdbb6bcda430c3b4d (patch)
treeb7c63e529d88edfbfebd5aaeb4570bd26f2b1cef /hiper/hipev.c
parent45b1843dc9d5b283e5fd892dd74415e0e2a426a7 (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/hipev.c')
-rw-r--r--hiper/hipev.c53
1 files changed, 19 insertions, 34 deletions
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));