Loading lib/Makefile.am +2 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,8 @@ escape.h getpass.c netrc.c telnet.h \ getinfo.c getinfo.h transfer.c strequal.c strequal.h easy.c \ security.h security.c krb4.c krb4.h memdebug.c memdebug.h inet_ntoa_r.h \ http_chunks.c http_chunks.h strtok.c strtok.h connect.c connect.h \ llist.c llist.h hash.c hash.h llist.c llist.h hash.c hash.h multi.c multi.h noinst_HEADERS = setup.h transfer.h Loading lib/multi.c +43 −15 Original line number Diff line number Diff line Loading @@ -22,10 +22,16 @@ *****************************************************************************/ #include "setup.h" #include <stdlib.h> #include <string.h> #include <curl/curl.h> #include "multi.h" /* will become <curl/multi.h> soon */ #include "urldata.h" #include "transfer.h" #include "url.h" struct Curl_message { /* the 'CURLMsg' is the part that is visible to the external user */ struct CURLMsg extmsg; Loading @@ -48,7 +54,9 @@ struct Curl_one_easy { struct Curl_one_easy *next; struct Curl_one_easy *prev; CURL *easy_handle; /* this is the easy handle for this unit */ struct SessionHandle *easy_handle; /* the easy handle for this unit */ struct connectdata *easy_conn; /* the "unit's" connection */ CURLMstate state; /* the handle's state */ CURLcode result; /* previous result */ }; Loading Loading @@ -134,7 +142,7 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle, /* increase the node-counter */ multi->num_easy++; return CURLM_OK; return CURLM_CALL_MULTI_PERFORM; } CURLMcode curl_multi_remove_handle(CURLM *multi_handle, Loading Loading @@ -190,23 +198,30 @@ CURLMcode curl_multi_fdset(CURLM *multi_handle, and then we must make sure that is done. */ struct Curl_multi *multi=(struct Curl_multi *)multi_handle; struct Curl_one_easy *easy; int this_max_fd=-1; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; *max_fd = -1; /* so far none! */ easy=multi->easy.next; while(easy) { switch(easy->state) { case CURLM_STATE_INIT: case CURLM_STATE_CONNECT: case CURLM_STATE_DO: case CURLM_STATE_DONE: /* we want curl_multi_perform() to get called, but we don't have any file descriptors to set */ default: break; case CURLM_STATE_PERFORM: /* This should have a set of file descriptors for us to set. */ /* after the transfer is done, go DONE */ Curl_single_fdset(easy->easy_conn, read_fd_set, write_fd_set, exc_fd_set, &this_max_fd); /* remember the maximum file descriptor */ if(this_max_fd > *max_fd) *max_fd = this_max_fd; break; } easy = easy->next; /* check next handle */ Loading @@ -222,6 +237,8 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) bool done; CURLMcode result=CURLM_OK; *running_handles = 0; /* bump this once for every living handle */ if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; Loading @@ -239,8 +256,9 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) } break; case CURLM_STATE_CONNECT: /* connect */ easy->result = Curl_connect(easy->easy_handle); /* Connect. We get a connection identifier filled in. */ easy->result = Curl_connect(easy->easy_handle, &easy->easy_conn); /* after connect, go DO */ if(CURLE_OK == easy->result) { easy->state = CURLM_STATE_DO; Loading @@ -249,15 +267,18 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) break; case CURLM_STATE_DO: /* Do the fetch or put request */ easy->result = Curl_do(easy->easy_handle); easy->result = Curl_do(&easy->easy_conn); /* after do, go PERFORM */ if(CURLE_OK == easy->result) { if(CURLE_OK == Curl_readwrite_init(easy->easy_conn)) { easy->state = CURLM_STATE_PERFORM; result = CURLM_CALL_MULTI_PERFORM; } } break; case CURLM_STATE_PERFORM: /* read/write data if it is ready to do so */ easy->result = Curl_readwrite(easy->easy_handle, &done); easy->result = Curl_readwrite(easy->easy_conn, &done); /* hm, when we follow redirects, we may need to go back to the CONNECT state */ /* after the transfer is done, go DONE */ Loading @@ -265,11 +286,12 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) /* call this even if the readwrite function returned error */ easy->result = Curl_posttransfer(easy->easy_handle); easy->state = CURLM_STATE_DONE; result = CURLM_CALL_MULTI_PERFORM; } break; case CURLM_STATE_DONE: /* post-transfer command */ easy->result = Curl_done(easy->easy_handle); easy->result = Curl_done(easy->easy_conn); /* after we have DONE what we're supposed to do, go COMPLETED */ if(CURLE_OK == easy->result) easy->state = CURLM_STATE_COMPLETED; Loading @@ -280,7 +302,10 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) /* This node should be delinked from the list now and we should post an information message that we are complete. */ break; default: return CURLM_INTERNAL_ERROR; } if((CURLM_STATE_COMPLETED != easy->state) && (CURLE_OK != easy->result)) { /* Loading @@ -289,10 +314,13 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) */ easy->state = CURLM_STATE_COMPLETED; } else if(CURLM_STATE_COMPLETED != easy->state) /* this one still lives! */ (*running_handles)++; easy = easy->next; /* operate on next handle */ } return CURLM_OK; return result; } CURLMcode curl_multi_cleanup(CURLM *multi_handle) Loading lib/multi.h +2 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,7 @@ #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #include <curl/types.h> #include <curl/curl.h> typedef void CURLM; Loading @@ -60,6 +60,7 @@ typedef enum { CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ CURLM_LAST } CURLMcode; Loading lib/transfer.c +759 −703 File changed.Preview size limit exceeded, changes collapsed. Show changes lib/transfer.h +12 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. Loading @@ -24,6 +24,17 @@ *****************************************************************************/ CURLcode Curl_perform(struct SessionHandle *data); CURLcode Curl_pretransfer(struct SessionHandle *data); CURLcode Curl_posttransfer(struct SessionHandle *data); CURLcode Curl_readwrite(struct connectdata *conn, bool *done); void Curl_single_fdset(struct connectdata *conn, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd); CURLcode Curl_readwrite_init(struct connectdata *conn); /* This sets up a forthcoming transfer */ CURLcode Curl_Transfer (struct connectdata *data, Loading Loading
lib/Makefile.am +2 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,8 @@ escape.h getpass.c netrc.c telnet.h \ getinfo.c getinfo.h transfer.c strequal.c strequal.h easy.c \ security.h security.c krb4.c krb4.h memdebug.c memdebug.h inet_ntoa_r.h \ http_chunks.c http_chunks.h strtok.c strtok.h connect.c connect.h \ llist.c llist.h hash.c hash.h llist.c llist.h hash.c hash.h multi.c multi.h noinst_HEADERS = setup.h transfer.h Loading
lib/multi.c +43 −15 Original line number Diff line number Diff line Loading @@ -22,10 +22,16 @@ *****************************************************************************/ #include "setup.h" #include <stdlib.h> #include <string.h> #include <curl/curl.h> #include "multi.h" /* will become <curl/multi.h> soon */ #include "urldata.h" #include "transfer.h" #include "url.h" struct Curl_message { /* the 'CURLMsg' is the part that is visible to the external user */ struct CURLMsg extmsg; Loading @@ -48,7 +54,9 @@ struct Curl_one_easy { struct Curl_one_easy *next; struct Curl_one_easy *prev; CURL *easy_handle; /* this is the easy handle for this unit */ struct SessionHandle *easy_handle; /* the easy handle for this unit */ struct connectdata *easy_conn; /* the "unit's" connection */ CURLMstate state; /* the handle's state */ CURLcode result; /* previous result */ }; Loading Loading @@ -134,7 +142,7 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle, /* increase the node-counter */ multi->num_easy++; return CURLM_OK; return CURLM_CALL_MULTI_PERFORM; } CURLMcode curl_multi_remove_handle(CURLM *multi_handle, Loading Loading @@ -190,23 +198,30 @@ CURLMcode curl_multi_fdset(CURLM *multi_handle, and then we must make sure that is done. */ struct Curl_multi *multi=(struct Curl_multi *)multi_handle; struct Curl_one_easy *easy; int this_max_fd=-1; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; *max_fd = -1; /* so far none! */ easy=multi->easy.next; while(easy) { switch(easy->state) { case CURLM_STATE_INIT: case CURLM_STATE_CONNECT: case CURLM_STATE_DO: case CURLM_STATE_DONE: /* we want curl_multi_perform() to get called, but we don't have any file descriptors to set */ default: break; case CURLM_STATE_PERFORM: /* This should have a set of file descriptors for us to set. */ /* after the transfer is done, go DONE */ Curl_single_fdset(easy->easy_conn, read_fd_set, write_fd_set, exc_fd_set, &this_max_fd); /* remember the maximum file descriptor */ if(this_max_fd > *max_fd) *max_fd = this_max_fd; break; } easy = easy->next; /* check next handle */ Loading @@ -222,6 +237,8 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) bool done; CURLMcode result=CURLM_OK; *running_handles = 0; /* bump this once for every living handle */ if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; Loading @@ -239,8 +256,9 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) } break; case CURLM_STATE_CONNECT: /* connect */ easy->result = Curl_connect(easy->easy_handle); /* Connect. We get a connection identifier filled in. */ easy->result = Curl_connect(easy->easy_handle, &easy->easy_conn); /* after connect, go DO */ if(CURLE_OK == easy->result) { easy->state = CURLM_STATE_DO; Loading @@ -249,15 +267,18 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) break; case CURLM_STATE_DO: /* Do the fetch or put request */ easy->result = Curl_do(easy->easy_handle); easy->result = Curl_do(&easy->easy_conn); /* after do, go PERFORM */ if(CURLE_OK == easy->result) { if(CURLE_OK == Curl_readwrite_init(easy->easy_conn)) { easy->state = CURLM_STATE_PERFORM; result = CURLM_CALL_MULTI_PERFORM; } } break; case CURLM_STATE_PERFORM: /* read/write data if it is ready to do so */ easy->result = Curl_readwrite(easy->easy_handle, &done); easy->result = Curl_readwrite(easy->easy_conn, &done); /* hm, when we follow redirects, we may need to go back to the CONNECT state */ /* after the transfer is done, go DONE */ Loading @@ -265,11 +286,12 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) /* call this even if the readwrite function returned error */ easy->result = Curl_posttransfer(easy->easy_handle); easy->state = CURLM_STATE_DONE; result = CURLM_CALL_MULTI_PERFORM; } break; case CURLM_STATE_DONE: /* post-transfer command */ easy->result = Curl_done(easy->easy_handle); easy->result = Curl_done(easy->easy_conn); /* after we have DONE what we're supposed to do, go COMPLETED */ if(CURLE_OK == easy->result) easy->state = CURLM_STATE_COMPLETED; Loading @@ -280,7 +302,10 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) /* This node should be delinked from the list now and we should post an information message that we are complete. */ break; default: return CURLM_INTERNAL_ERROR; } if((CURLM_STATE_COMPLETED != easy->state) && (CURLE_OK != easy->result)) { /* Loading @@ -289,10 +314,13 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) */ easy->state = CURLM_STATE_COMPLETED; } else if(CURLM_STATE_COMPLETED != easy->state) /* this one still lives! */ (*running_handles)++; easy = easy->next; /* operate on next handle */ } return CURLM_OK; return result; } CURLMcode curl_multi_cleanup(CURLM *multi_handle) Loading
lib/multi.h +2 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,7 @@ #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #include <curl/types.h> #include <curl/curl.h> typedef void CURLM; Loading @@ -60,6 +60,7 @@ typedef enum { CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ CURLM_LAST } CURLMcode; Loading
lib/transfer.h +12 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. Loading @@ -24,6 +24,17 @@ *****************************************************************************/ CURLcode Curl_perform(struct SessionHandle *data); CURLcode Curl_pretransfer(struct SessionHandle *data); CURLcode Curl_posttransfer(struct SessionHandle *data); CURLcode Curl_readwrite(struct connectdata *conn, bool *done); void Curl_single_fdset(struct connectdata *conn, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd); CURLcode Curl_readwrite_init(struct connectdata *conn); /* This sets up a forthcoming transfer */ CURLcode Curl_Transfer (struct connectdata *data, Loading