Commit Graph

483 Commits

Author SHA1 Message Date
Sara Golemon de24d7bd4c multi: add curl_multi_wait()
/*
 * Name:     curl_multi_wait()
 *
 * Desc:     Poll on all fds within a CURLM set as well as any
 *           additional fds passed to the function.
 *
 * Returns:  CURLMcode type, general multi error code.
 */
CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
                                      struct curl_waitfd extra_fds[],
                                      unsigned int extra_nfds,
                                      int timeout_ms);
2012-09-01 23:10:53 +02:00
Daniel Stenberg 14afbf361a add_next_timeout: minor restructure of code
By reading the ->head pointer and using that instead of the ->size
number to figure out if there's a list remaining we avoid the (false
positive) clang-analyzer warning that we might dereference of a null
pointer.
2012-08-08 14:50:32 +02:00
Daniel Stenberg 9d11716933 multi_runsingle: added precaution against easy_conn NULL pointer
In many states the easy_conn pointer is referenced and just assumed to
be working. This is an added extra check since analyzing indicates
there's a risk we can end up in these states with a NULL pointer there.
2012-07-15 20:33:11 +02:00
Daniel Stenberg c13af84372 singlesocket: remove dead code
No need to check if 'entry' is non-NULL in a spot where it is already checked
and guaranteed to be non-NULL.

(Spotted by a Coverity scan)
2012-06-12 23:04:04 +02:00
Daniel Stenberg c83de6d076 CONNECT: fix multi interface regression
The refactoring of HTTP CONNECT handling in commit 41b0237834 that
made it protocol independent broke it for the multi interface. This fix
now introduce a better state handling and moved some logic to the
http_proxy.c source file.

Reported by: Yang Tse
Bug: http://curl.haxx.se/mail/lib-2012-03/0162.html
2012-03-22 00:12:37 +01:00
Daniel Stenberg dfdac61522 non-blocking active FTP: cleanup multi state usage
Backpedaled out the funny double-change of state in the multi state
machine by adding a new argument to the do_more() function to signal
completion. This way it can remain in the DO_MORE state properly until
done. Long term, the entire DO_MORE logic should be moved into the FTP
code and be hidden from the multi code as the logic is only used for
FTP.
2011-12-20 20:30:02 +01:00
Gokhan Sengun c834213ad5 FTP: perform active connections non-blocking
1- Two new error codes are introduced.

CURLE_FTP_ACCEPT_FAILED to be set whenever ACCEPTing fails because of
FTP server connected.

CURLE_FTP_ACCEPT_TIMEOUT to be set whenever ACCEPTing timeouts.

Neither of these errors are considered fatal and control connection
remains OK because it could just be a firewall blocking server to
connect to the client.

2- One new setopt option was introduced.

CURLOPT_ACCEPTTIMEOUT_MS

It sets the maximum amount of time FTP client is going to wait for a
server to connect. Internal default accept timeout is 60 seconds.
2011-12-20 20:30:02 +01:00
Gokhan Sengun 2b24dd870e multi interface: fix block when CONNECT_ONLY option is used 2011-12-07 15:37:05 +01:00
Daniel Stenberg d81f5ea3e0 multi interface: only use non-NULL function pointer!
If the socket callback function pointer hasn't been set, we must not
attempt to use it. Commit adc88ca20 made it more likely to occur.
2011-12-02 21:10:28 +01:00
Jason Glasgow adc88ca203 multi: handle timeouts on DNS servers by checking for new sockets
If the first name server is not available, the multi interface does
not invoke the socket_cb when the DNS request to the first name server
timesout.  Ensure that the list of sockets are always updated after
calling Curl_resolver_is_resolved.

This bug can be reproduced if Curl is complied with --enable_ares and
your code uses the multi socket interfaces and the
CURLMOPT_SOCKETFUNCTION option.  To test try:
  iptables -I INPUT \
           -s $(sed -n -e '/name/{s/.* //p;q}' /etc/resolv.conf)/32 \
           -j REJECT
and then run a program which uses the multi-interface.
2011-12-02 10:18:52 +01:00
Yang Tse f7dfe2b87a multi.c: OOM handling fix 2011-11-01 14:38:21 +01:00
Yang Tse ddeab48245 multi.c: OOM handling fix
Fix curl_multi_cleanup() segfault when using weird cleanup sequence.
2011-10-27 17:08:02 +02:00
Daniel Stenberg b0d42da26b multi: start ftp state machine when switching to DO_MORE
This extends the fix from commit d7934b8bd4

When the multi state is changed within the multi_runsingle from DOING to
DO_MORE, we didn't immediately start the FTP state machine again. That
then left the FTP state in FTP_STOP. When curl_multi_fdset() was
subsequently called, the ftp_domore_getsock() function would return the
wrong fd info.

Reported by: Gokhan Sengun
2011-10-27 12:46:29 +02:00
Daniel Stenberg d7934b8bd4 curl_multi_fdset: correct fdset with FTP PORT use
After a PORT has been issued, and the multi handle would switch to the
CURLM_STATE_DO_MORE state (which is unique for FTP), libcurl would
return the wrong fdset to wait for when curl_multi_fdset() is
called. The code would blindly assume that it was waiting for a connect
of the second connection, while that isn't true immediately after the
PORT command.

Also, the function multi.c:domore_getsock() was highly FTP-centric and
therefore ugly to keep in protocol-agnostic code. I solved this problem
by introducing a new function pointer in the Curl_handler struct called
domore_getsock() which is only called during the DOMORE state for
protocols that set that pointer.

The new ftp.c:ftp_domore_getsock() function now returns fdset info about
the control connection's command/response handling while such a state is
in use, and goes over to waiting for a writable second connection first
once the commands are done.

The original problem could be seen by running test 525 and checking the
time stamps in the FTP server log. I can verify that this fix at least
fixes this problem.

Bug: http://curl.haxx.se/mail/lib-2011-10/0250.html
Reported by: Gokhan Sengun
2011-10-21 23:36:54 +02:00
Yang Tse a4758c3276 multi.c: fix segfault 2011-10-21 16:52:16 +02:00
Yang Tse 34770b8ab0 multi.c: OOM handling fixes
Prevent modification of easy handle being added with curl_multi_add_handle()
unless this function actually suceeds.

Run Curl_posttransfer() to allow restoring of SIGPIPE handler when
Curl_connect() fails early in multi_runsingle().
2011-10-13 18:04:56 +02:00
Yang Tse 584dc8b8af OOM handling/cleanup slight adjustments 2011-10-11 19:41:30 +02:00
Yang Tse 17f48fe879 libcurl: some OOM handling fixes 2011-10-07 20:50:57 +02:00
Yang Tse b82bd05354 multi.c: OOM handling fixes making torture tests 560 580 581 pass 2011-10-06 20:30:34 +02:00
Daniel Stenberg 9dd85bced5 multi: progress function abort must close connection
When the progress function returns to cancel the request, we must mark
the connection to get closed and it must do to the DONE state.

do_init() must be called as early as possible so that state variables
for new connections are reset early. We could otherwise see that the old
values were still there when a connection was to be disconnected very
early and it would make it behave wrongly.

Bug: http://curl.haxx.se/mail/lib-2011-10/0006.html
Reported by: Vladimir Grishchenko
2011-10-02 19:28:39 +02:00
Daniel Stenberg 3d19e1eedf multi_runsingle: change state on callback abort
Reported by: Marcin Adamski
Bug: http://curl.haxx.se/mail/lib-2011-09/0329.html
2011-09-30 22:59:50 +02:00
Yang Tse d2a47021c0 Q&D fix header inclusion order 2011-09-25 19:08:12 +02:00
Daniel Stenberg 2d6796aac5 curl_multi_fdset: avoid FD_SET out of bounds
If a socket is larger than FD_SETSIZE, avoid using FD_SET() on the
platforms where this is possible.

Bug: http://curl.haxx.se/bug/view.cgi?id=3413274
Reported by: Tim Starling
2011-09-25 17:34:12 +02:00
Yang Tse a50210710a fix bool variables checking and assignment 2011-09-05 20:46:09 +02:00
Yang Tse 9194e17003 MemoryTracking: fix logging of free() calls done where Curl_safefree is called
Just internal stuff...

Curl_safefree is now a macro defined in memdebug.h instead of a function
prototyped in url.h and implemented in url.c, so inclusion of url.h is no
longer required in order to simply use Curl_safefree.

Provide definition of macro WHILE_FALSE in setup_once.h in order to allow
other macros such as DEBUGF and DEBUGASSERT, and code using it, to compile
without 'conditional expression is constant' warnings.

The WHILE_FALSE stuff fixes 150+ MSVC compiler warnings.
2011-09-02 19:40:53 +02:00
Daniel Stenberg 4a42e5cdaa multi-socks: fix connect to proxy
When connecting to a socks or similar proxy we do the proxy handshake at
once when we know the TCP connect is completed and we only consider the
"connection" complete after the proxy handshake. This fixes test 564
which is now no longer considered disabled.

Reported by: Dmitri Shubin
Bug: http://curl.haxx.se/mail/lib-2011-04/0127.html
2011-04-28 10:06:49 +02:00
Daniel Stenberg 889d1e973f whitespace cleanup: no space first in conditionals
"if(a)" is our style, not "if( a )"
2011-04-27 09:09:35 +02:00
Daniel Stenberg b903186fa0 source cleanup: unify look, style and indent levels
By the use of a the new lib/checksrc.pl script that checks that our
basic source style rules are followed.
2011-04-27 09:09:35 +02:00
Daniel Stenberg 7de2f9271c async resolvers: further cleanups
asyn-ares.c and asyn-thread.c are two separate backends that implement
the same (internal) async resolver API for libcurl to use. Backend is
specified at build time.

The internal resolver API is defined in asyn.h for asynch resolvers.
2011-04-25 19:47:16 +02:00
Fabian Keil 1702a2c08d Fix a couple of spelling errors in lib/
Found with codespell.
2011-04-21 07:55:53 -07:00
Daniel Stenberg 318c5c802b multi: shorten lines
We keep them less than 80 columns
2011-04-03 00:07:32 +02:00
Daniel Stenberg c2459c4328 multi: conn goes bad when data change
Within multi_socket when conn is used as a shorthand, data could be
changed and multi_runsingle could modify the connectdata struct to deal
with. This bug has not been included in a public release.

Using 'conn' like that turned out to be ugly. This change is a partial
revert of commit f1c6cd42f4.

Reported by: Miroslav Spousta
Bug: http://curl.haxx.se/bug/view.cgi?id=3265485
2011-04-02 23:44:11 +02:00
Daniel Stenberg 8831000bc0 protocol handler: added flags field
The protocol handler struct got a 'flags' field for special information
and characteristics of the given protocol.

This now enables us to move away central protocol information such as
CLOSEACTION and DUALCHANNEL from single defines in a central place, out
to each protocol's definition. It also made us stop abusing the protocol
field for other info than the protocol, and we could start cleaning up
other protocol-specific things by adding flags bits to set in the
handler struct.

The "protocol" field connectdata struct was removed as well and the code
now refers directly to the conn->handler->protocol field instead. To
make things work properly, the code now always store a conn->given
pointer that points out the original handler struct so that the code can
learn details from the original protocol even if conn->handler is
modified along the way - for example when switching to go over a HTTP
proxy.
2011-03-14 22:22:22 +01:00
Daniel Stenberg 3eac14b43c SSH: add protocol lock direction
Some protocols have to call the underlying functions without regard to
what exact state the socket signals. For example even if the socket says
"readable", the send function might need to be called while uploading,
or vice versa. This is the case for libssh2 based protocols: SCP and
SFTP and we now introduce a define to set those protocols and we make
the multi interface code aware of this concept.

This is another fix to make test 582 run properly.
2011-03-13 23:21:03 +01:00
Mike Crowe c4369f34b9 multi: close connection on timeout
After a request times out, the connection wasn't properly closed and
prevented to get re-used, so subsequent transfers could still mistakenly
get to use the previously aborted connection.
2011-02-18 23:19:14 +01:00
Daniel Stenberg d85cae9225 multi: better failed connect treatment
When failing to connect the protocol during the CURLM_STATE_PROTOCONNECT
state, Curl_done() has to be called with the premature flag set TRUE as
for the pingpong protocols this can be important.

When Curl_done() is called with premature == TRUE, it needs to call
Curl_disconnect() with its 'dead_connection' argument set to TRUE as
well so that any protocol handler's disconnect function won't attempt to
use the (control) connection for anything.

This problem caused the pingpong protocols to fail to disconnect when
STARTTLS failed.

Reported by: Alona Rossen
Bug: http://curl.haxx.se/mail/lib-2011-02/0195.html
2011-02-18 23:01:55 +01:00
Nicholas Maniscalco 73eb9965cf multi: fix CURLM_STATE_TOOFAST for multi_socket
The code in the toofast state needs to first recalculate the values
before it uses them again since it may have been a while since it last
did it when it reaches this point.
2011-02-02 13:41:22 +01:00
Daniel Stenberg adb49ad8bb Curl_timeleft: s/conn/data in first argument
As the function doesn't really use the connectdata struct but only the
SessionHanadle struct I modified what argument it wants.
2011-01-04 23:13:10 +01:00
Daniel Stenberg be16b227b7 multi: inhibit some verbose outputs
The info about pipe status and expire cleared are clearly debug-related
and not anything mere mortals will or should care about so they are now
ifdef'ed DEBUGBUILD
2010-12-22 15:29:21 +01:00
Daniel Stenberg 0fd439ebac multi_runsingle: don't timeout completed handles
The generic timeout code must not check easy handles that are already
completed. Going to completed (again) within there risked decreasing the
number of alive handles again and thus it could go negative.

This regression bug was added in 7.21.2 in commit ca10e28f06
2010-12-13 12:51:48 +01:00
Kamil Dudka 5c7c9a768d url: provide dead_connection flag in Curl_handler::disconnect
It helps to prevent a hangup with some FTP servers in case idle session
timeout has exceeded.  But it may be useful also for other protocols
that send any quit message on disconnect.  Currently used by FTP, POP3,
IMAP and SMTP.
2010-12-06 14:35:42 +01:00
Yang Tse cbe67a1b71 multi: fix compiler warning: conversion may lose significant bits follow-up 2010-11-28 20:49:40 +01:00
Yang Tse 3590874999 multi: fix compiler warning: conversion may lose significant bits 2010-11-26 19:57:27 +01:00
Yang Tse e39ab6f203 multi: fix compiler warning: enumerated type mixed with another type 2010-11-26 19:34:10 +01:00
Yang Tse 5087f89ac8 curl_multi_info_read: fix compiler warning: conversion may lose significant bits 2010-11-25 02:58:59 +01:00
Daniel Stenberg ed4eecc05e multi: don't expire timeouts at disonnect or done
The functions Curl_disconnect() and Curl_done() are both used within the
scope of a single request so they cannot be allowed to use
Curl_expire(... 0) to kill all timeouts as there are some timeouts that
are set before a request that are supposed to remain until the request
is done.

The timeouts are now instead cleared at curl_easy_cleanup() and when the
multi state machine changes a handle to the complete state.
2010-09-28 23:49:32 +02:00
Dirk Manske 397e61128f multi_runsingle: set timeout error messages
With the latest changes to fix the timeout handling with multi interface
we lost the timeout error messages. This patch brings them back.
2010-09-27 21:12:49 +02:00
Daniel Stenberg ca10e28f06 multi: fixes for timing out handles
Add a timeout check for handles in the state machine so that they will
timeout in all states disregarding what actions that may or may not
happen.

Fixed a bug in socket_action introduced recently when looping over timed
out handles: it wouldn't assign the 'data' variable and thus it wouldn't
properly take care of handles.

In the update_timer function, the code now checks if the timeout has
been removed and then it tells the application. Previously it would
always let the remaining timeout(s) just linger to expire later on.
2010-09-01 16:52:23 +02:00
Daniel Stenberg 0db9140747 multi: make sure the next timeout is used when one expires
Each easy handle has a list of timeouts, so as soon as the main timeout
for a handle expires, we must make sure to get the next entry from the
list and re-add the handle to the splay tree.

This was attempted previously but was done poorly in my commit
232ad6549a.
2010-08-31 00:10:44 +02:00
Ben Greear bed311eda2 multi: Fix compile warning on 64-bit systems 2010-08-24 18:30:26 +02:00
Dan Fandrich ab81f6c7c4 Fixed a memory leak during OOM in the multi timeout code 2010-08-18 23:08:18 -07:00
Daniel Stenberg 280d2cff2e multi: avoid sending multiple complete messages
I fell over this bug report that mentioned that libcurl could wrongly
send more than one complete messages at the end of a transfer. Reading
the code confirmed this, so I've added a new multi state to make it not
happen. The mentioned bug report was made by Brad Jorsch but is (oddly
enough) filed in Debian's bug tracker for the "wmweather+" tool.

Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593390
2010-08-18 19:59:46 +02:00
Daniel Stenberg 9124bfba45 multi: use timeouts properly for MAX_RECV/SEND_SPEED
When detecting that the send or recv speed, the multi interface changes
state to TOOFAST and previously there was no timeout set that would
force a recheck but it would rely on the application to somehow call
libcurl anyway. This now sets a timeout for a suitable future time to
check again if the average transfer speed is then below the threshold
again.
2010-08-15 13:16:39 +02:00
Daniel Stenberg 232ad6549a multi: support timeouts
Curl_expire() is now expanded to hold a list of timeouts for each easy
handle. Only the closest in time will be the one used as the primary
timeout for the handle and will be used for the splay tree (which sorts
and lists all handles within the multi handle).

When the main timeout has triggered/expired, the next timeout in time
that is kept in the list will be moved to the main timeout position and
used as the key to splay with. This way, all timeouts that are set with
Curl_expire() internally will end up as a proper timeout. Previously any
Curl_expire() that set a _later_ timeout than what was already set was
just silently ignored and thus missed.

Setting Curl_expire() with timeout 0 (zero) will cancel all previously
added timeouts.

Corrects known bug #62.
2010-08-15 13:16:39 +02:00
Daniel Stenberg 4d53dc5d80 multi: make curl_multi_info_read perform O(1)
Instead of looping over all attached easy handles, this now keeps a list
of messages in the multi handle. It allows curl_multi_info_read() to
perform O(1) no matter how many easy handles that are handled. This is
of importance since this function may be polled very frequently by apps
using the multi interface.
2010-08-15 13:16:39 +02:00
Daniel Stenberg 6ccbd1bee4 typo: remove duplicate semicolon 2010-08-08 22:51:37 +02:00
Daniel Stenberg 1267719735 multi: avoid a malloc() when a transfer is complete
The struct used for storing the message for a completed transfer is now
no longer allocated separatly but is kept within the main struct kept
for each easy handle so that we avoid one malloc (and the subsequent
free).
2010-08-08 22:50:09 +02:00
Constantine Sapuntzakis d4e6404135 multi: fix condition that remove timers before trigger
curl_multi perform has two phases: run through every easy handle calling
multi_runsingle and remove expired timers (timer removal).

If a small timer (e.g. 1-10ms) is set during multi_runsingle, then it's
possible that the timer has passed by when the timer removal runs. The
timer which was just added is then removed. This will potentially cause
the timer list to be empty and cause the next call to curl_multi_timeout
to return -1. Ideally, curl_multi_timeout should return 0 in this case.

One way to fix this is to move the struct timeval now = Curl_tvnow(); to
the top of curl_multi_perform. The change does that.
2010-07-12 19:19:31 +02:00
Daniel Stenberg 9be951a415 multi: CURLINFO_LASTSOCKET doesn't work after remove_handle
When curl_multi_remove_handle() is called and an easy handle is returned
to the connection cache held in the multi handle, then we cannot allow
CURLINFO_LASTSOCKET to extract it since that will more or less encourage
that the user uses the socket while it can get used by libcurl again.

Without this fix, we'd get a segfault in Curl_getconnectinfo() trying to
dereference the NULL pointer in 'data->state.connc'.

Bug: http://curl.haxx.se/bug/view.cgi?id=3023840
2010-07-01 23:32:20 +02:00
Daniel Stenberg e6d85923c1 multi: prevent NULL pointer dereference
My additional call to Curl_pgrsUpdate() would sometimes get
called even though there's no connection (left) so a NULL pointer
would get passed, causing a segfault.
2010-06-18 23:46:09 +02:00
Krister Johansen 43edcc4a2e multi: unmark handle as used when no longer head of pipeline 2010-06-17 15:46:27 +02:00
Daniel Stenberg 01c2b397aa multi: call the progress function only once and allow abort
1) no need to call the progress function twice when in the
CURLM_STATE_TOOFAST state.

2) Make sure that the progress callback's return code is
acknowledged when used
2010-06-17 15:19:30 +02:00
Daniel Stenberg 51a757c11b multi: call the progress callback in all states
As long as no error is reported, the progress function can get
called. This may be a little TOO often so we should keep an eye
on this and possibly make this conditional somehow.
2010-06-17 15:10:08 +02:00
Kamil Dudka c072bd4609 lib: eliminate some dead code 2010-06-02 23:50:38 +02:00
Daniel Stenberg 2c72732ebf multi_socket: handles timer inaccuracy better for timeouts
Igor Novoseltsev reported a problem with the multi socket API and
using timeouts and timers. It boiled down to a problem with
libcurl's use of GetTickCount() interally to figure out the
current time, while Igor's own application code used another
function call.

It made his app call the socket API timeout function a bit
_before_ libcurl would consider the timeout to trigger, and that
could easily lead to timeouts or stalls in the app. It seems
GetTickCount() in general often has no better resolution than
16ms and switching to the alternative function
QueryPerformanceCounter has its share of problems:
http://www.virtualdub.org/blog/pivot/entry.php?id=106

We address this problem by simply having libcurl treat timers
that already has occured or will occur within 40ms subject for
treatment. I'm confident that there are other implementations and
operating systems with similarly in accurate timer functions so
it makes sense to have applied generically and I don't believe we
sacrifice much by adding a 40ms inaccuracy on these timeouts.
2010-06-01 23:20:16 +02:00
Tor Arntsen dcc061543a lib: Change some CRLF line endings to LF
An update had added a couple of lines with DOS line endings,
and some compilers will choke on that (e.g. the Tru64 compiler).
2010-05-16 22:34:02 +02:00
Pavel Raiskup 0825cd80a6 FTP: WILDCARDMATCH/CHUNKING/FNMATCH added 2010-05-12 23:17:51 +02:00
Daniel Stenberg 2309b4e330 remove the CVSish $Id$ lines 2010-03-24 11:02:54 +01:00
Daniel Stenberg 2a94293efd delayed easy handle kill caused double Curl_close() call
Hauke Duden provided an example program that made the multi
interface crash.  His example simply used the multi interface and
did first one FTP transfer and after completion it used a second
easy handle and did another FTP transfer on the same FTP server.

This triggered a bug in the "delayed easy handle kill" system
that curl uses: when an FTP connection is left alive it must keep
an easy handle around internally - only for the purpose of having
an easy handle when it later disconnects it. The code assumed
that when the easy handle was removed and an internal reference
was made, that version could be killed later on when a new easy
handle came using the same connection. This was wrong as Hauke's
example showed that the removed handle wasn't killed for real
until later. This caused a double close attempt => segfault.
2010-03-23 13:18:30 +01:00
Daniel Stenberg 733f794cb8 - Constantine Sapuntzakis brought a patch:
The problem mentioned on Dec 10 2009
  (http://curl.haxx.se/bug/view.cgi?id=2905220) was only partially fixed.
  Partially because an easy handle can be associated with many connections in
  the cache (e.g. if there is a redirect during the lifetime of the easy
  handle).  The previous patch only cleaned up the first one. The new fix now
  removes the easy handle from all connections, not just the first one.
2010-03-15 22:40:42 +00:00
Yang Tse 7aef172a34 fix printf-style format strings 2010-02-04 19:44:31 +00:00
Yang Tse 839b61c32a Fix compiler warnings: conversion from 'const int ' to 'unsigned char ', possible loss of data 2010-02-02 16:23:01 +00:00
Daniel Stenberg 55f1e787f3 We introduce a loop in lib/multi.c around all calls to multi_runsingle() and
simply check for CURLM_CALL_MULTI_PERFORM internally. This has the added
benefit that this goes in line with my long-term wishes to get rid of the
CURLM_CALL_MULTI_PERFORM all together from the public API.
2010-02-01 21:42:44 +00:00
Yang Tse d65cf7889b fix printf-style format strings 2010-01-28 15:34:18 +00:00
Daniel Stenberg 2158e234aa After the TCP connect is confirmed in CURLM_STATE_WAITCONNECT and it changes
state, we return CURLM_CALL_MULTI_PERFORM unconditionally then so that we
can act faster like in the case the protocol-specific connect doesn't block
on anything and we can just persue on the next action immediately. It also
then avoids a case where curl_multi_fdset() would return -1.
2010-01-11 23:05:35 +00:00
Daniel Stenberg b90703f594 struct Curl_sh_entry's 'inuse' member was no longer used and is now removed 2010-01-09 00:03:33 +00:00
Kamil Dudka fd903eb6be - Julien Chaffraix eliminated a duplicated initialization in singlesocket(). 2010-01-03 13:46:37 +00:00
Daniel Stenberg 315253b367 - Constantine Sapuntzakis figured out a case which would lead to libcurl
accessing alredy freed memory and thus crash when using HTTPS (with
  OpenSSL), multi interface and the CURLOPT_DEBUGFUNCTION and a certain order
  of cleaning things up. I fixed it.

  (http://curl.haxx.se/bug/view.cgi?id=2891591)
2009-12-10 20:20:15 +00:00
Yang Tse 59939313f8 Make usage of calloc()'s arguments consistent with rest of code base 2009-11-18 10:33:54 +00:00
Daniel Stenberg 6ede4ce79d clarify the code by initing newurl to NULL 2009-08-24 08:41:17 +00:00
Daniel Stenberg 8b5102ca83 - Andre Guibert de Bruet pointed out a missing return code check for a
strdup() that could lead to segfault if it returned NULL. I extended his
  suggest patch to now have Curl_retry_request() return a regular return code
  and better check that.
2009-08-21 12:01:36 +00:00
Daniel Stenberg 1048043963 - Lots of good work by Krister Johansen, mostly related to pipelining:
Fix SIGSEGV on free'd easy_conn when pipe unexpectedly breaks
  Fix data corruption issue with re-connected transfers
  Fix use after free if we're completed but easy_conn not NULL
2009-08-21 07:11:20 +00:00
Daniel Stenberg 3a9c03bef3 indentation fixes only 2009-08-03 11:32:55 +00:00
Yang Tse 4ea513cc38 fix compiler warning 2009-06-12 02:41:16 +00:00
Yang Tse 2c16681225 Adjusted to take in account that...
With the curl memory tracking feature decoupled from the debug build feature,
CURLDEBUG and DEBUGBUILD preprocessor symbol definitions are used as follows:

CURLDEBUG used for curl debug memory tracking specific code (--enable-curldebug)

DEBUGBUILD used for debug enabled specific code (--enable-debug)
2009-06-10 02:49:42 +00:00
Daniel Stenberg 3aa3d7e629 Internal cleanup: KEEP_WRITE and KEEP_READ are now called KEEP_SEND and
KEEP_RECV to better match the general terminology: receive and send is what we
do from the (remote) servers. We read and write from and to the local fs.
2009-05-11 07:53:38 +00:00
Daniel Stenberg e84c7db049 - Constantine Sapuntzakis fixed bug report #2784055
(http://curl.haxx.se/bug/view.cgi?id=2784055) identifying a problem to
  connect to SOCKS proxies when using the multi interface. It turned out to
  almost not work at all previously. We need to wait for the TCP connect to
  be properly verified before doing the SOCKS magic.

  There's still a flaw in the FTP code for this.
2009-05-08 10:59:40 +00:00
Yang Tse 33a3753c3f libcurl's memory.h renamed to curl_memory.h 2009-04-21 11:46:16 +00:00
Daniel Stenberg af91ff0e06 - Linus Nielsen Feltzing reported and helped me repeat and fix a problem with
FTP with the multi interface: when a transfer fails, like when aborted by a
  write callback, the control connection was wrongly closed and thus not
  re-used properly.

  This change is also an attempt to cleanup the code somewhat in this area, as
  now the FTP code attempts to keep (better) track on pending responses
  necessary to get read in ftp_done().
2009-02-20 08:16:03 +00:00
Daniel Stenberg f0332c0b58 minor comment fix 2009-02-02 21:20:59 +00:00
Daniel Stenberg 452e52f958 - Emil Romanus fixed:
When using the multi interface over HTTP and the server returns a Location
  header, the running easy handle will get stuck in the CURLM_STATE_PERFORM
  state, leaving the external event loop stuck waiting for data from the
  ingoing socket (when using the curl_multi_socket_action stuff). While this
  bug was pretty hard to find, it seems to require only a one-line fix. The
  break statement on line 1374 in multi.c caused the function to skip the call
  to multistate().

  How to reproduce this bug? Well, that's another question.  evhiperfifo.c in
  the examples directory chokes on this bug only _sometimes_, probably
  depending on how fast the URLs are added. One way of testing the bug out is
  writing to hiper.fifo from more than one source at the same time.
2009-01-10 22:10:57 +00:00
Daniel Stenberg 216ad2680b - Igor Novoseltsev fixed a bad situation for the multi_socket() API when doing
pipelining, as libcurl could then easily get confused and A) work on the
  handle that was not "first in queue" on a pipeline, or even B) tell the app
  to REMOVE a socket while it was in use by a second handle in a pipeline. Both
  errors caused hanging or stalling applications.
2008-12-20 22:03:22 +00:00
Daniel Stenberg ffd08df863 - curl_multi_timeout() could return a timeout value of 0 even though nothing
was actually ready to get done, as the internal time resolution is higher
  than the returned millisecond timer. Therefore it could cause applications
  running on fast processors to do short bursts of busy-loops.
  curl_multi_timeout() will now only return 0 if the timeout is actually
  alreay triggered.
2008-12-19 22:58:22 +00:00
Daniel Stenberg 07416b61e3 - Using the libssh2 0.19 function libssh2_session_block_directions(), libcurl
now has an improved ability to do right when the multi interface (both
  "regular" and multi_socket) is used for SCP and SFTP transfers. This should
  result in (much) less busy-loop situations and thus less CPU usage with no
  speed loss.
2008-12-19 21:14:52 +00:00
Daniel Stenberg 792279581b - More work with Igor Novoseltsev to first fix the remaining stuff for
removing easy handles from multi handles when the easy handle is/was within
  a HTTP pipeline. His bug report #2351653
  (http://curl.haxx.se/bug/view.cgi?id=2351653) was also related and was
  eventually fixed by a patch by Igor himself.
2008-12-12 12:21:11 +00:00
Daniel Stenberg 479ddb1fee - Igor Novoseltsev filed bug #2351645
(http://curl.haxx.se/bug/view.cgi?id=2351645) that identified a problem with
  the multi interface that occured if you removed an easy handle while in
  progress and the handle was used in a HTTP pipeline.
2008-12-03 15:20:27 +00:00
Yang Tse 0ce97f77e0 Use our Curl_addrinfo definition even when an addrinfo struct is available.
Use a wrapper function to call system's getaddrinfo().
2008-10-30 13:45:25 +00:00
Yang Tse 417bac4055 add missing header inclusions 2008-10-25 16:15:21 +00:00
Yang Tse 5779283a52 attempt to fix or allow further detection of an elusive icc SIGSEGV 2008-10-19 20:17:16 +00:00
Daniel Stenberg 544f2f74df - Igor filed bug #2111613 (http://curl.haxx.se/bug/view.cgi?id=2111613) that
eventually identified a flaw in how the multi_socket interface in some cases
  missed to call the timeout callback when easy interfaces are removed and
  added within the same millisecond.
2008-10-08 21:42:29 +00:00
Daniel Stenberg 0a305eb79f - Bug #2107803 (http://curl.haxx.se/bug/view.cgi?id=2107803) "no
CURLINFO_REDIRECT_URL in multi mode" also contained a patch that fixed the
  problem.
2008-09-29 12:22:10 +00:00
Yang Tse f591ab3ba0 fix compiler warning: defined but not used 2008-09-13 15:59:14 +00:00
Yang Tse 61c0bdb09c fix compiler warning: external declaration in primary source file 2008-09-13 03:49:33 +00:00
Dan Fandrich 6cea51585f Checked in some code improvements and minor fixes that I discovered in the
FreeBSD ports system.
2008-09-10 20:05:45 +00:00
Daniel Stenberg 2816902f0e Dmitry Kurochkin fixed pipelining over proxy using the multi interface 2008-09-08 12:15:09 +00:00
Yang Tse 59e378f48f remove unnecessary typecasting of malloc() 2008-09-06 05:29:05 +00:00
Yang Tse a622fd90b4 remove unnecessary typecasting of calloc() 2008-09-06 04:47:14 +00:00
Daniel Stenberg 13dc82b9d4 - Constantine Sapuntzakis fixed a bug when doing proxy CONNECT with the multi
interface, and the proxy would send Connection: close during the
  authentication phase.  http://curl.haxx.se/bug/view.cgi?id=2069047
2008-08-23 12:11:38 +00:00
Dan Fandrich e54209d643 Fixed an uninitialized variable in multi_runsingle() that could cause a
request to prematurely end.
2008-08-08 01:52:08 +00:00
Daniel Stenberg d09b6ecaa5 - Christopher Palow fixed a curl_multi_socket() issue which previous caused
libcurl to not tell the app properly when a socket was closed (when the name
  resolve done by c-ares is done) and then immediately re-created and put to
  use again (for the actual connection). Since the closure will make the
  "watch status" get lost in several event-based systems libcurl will need to
  tell the app about this close/re-create case.
2008-06-19 21:32:51 +00:00
Daniel Stenberg 2597020d22 In checkPendPipeline() we can't be setting the TIMER_CONNECT correctly as that
is for the TCP connect. I changed it to TIMER_PRETRANSFER which seems to be
what was intended here.
2008-06-13 21:16:10 +00:00
Daniel Stenberg ec4f6e93c2 - Emil Romanus found a problem and helped me repeat it. It occured when using
the curl_multi_socket() API with HTTP pipelining enabled and could lead to
  the pipeline basically stalling for a very long period of time until it took
  off again.
2008-05-28 20:56:19 +00:00
Daniel Stenberg ae45a462e0 with pipelining disabled, the state should never be set to WAITDO but rather
go straight to DO

we had multiple states for which the internal function returned no socket at
all to wait for, with the effect that libcurl calls the socket callback (when
curl_multi_socket() is used) with REMOVE prematurely (as it would be added
again within very shortly)
2008-05-19 20:58:01 +00:00
Daniel Stenberg 0510759bc4 - Stefan Krause reported a busy-looping case when using the multi interface
and doing CONNECT to a proxy. The app would then busy-loop until the proxy
  completed its response.
2008-05-09 12:59:24 +00:00
Yang Tse eb68aa38e3 Christopher Palow provided the patch (edited by me) that introduces
the use of microsecond resolution keys for internal splay trees.

http://curl.haxx.se/mail/lib-2008-04/0513.html
2008-05-07 15:41:41 +00:00
Daniel Stenberg 852989856d - To make it easier for applications that want lots of magic stuff done on
redirections and thus cannot use CURLOPT_FOLLOWLOCATION easily, we now
  introduce the new CURLINFO_REDIRECT_URL option that lets applications
  extract the URL libcurl would've redirected to if it had been told to. This
  then enables the application to continue to that URL as it thinks is
  suitable, without having to re-implement the magic of creating the new URL
  from the Location: header etc. Test 1029 verifies it.
2008-04-30 21:20:08 +00:00
Michal Marek 6f3166c15b - Added curl_easy_getinfo typechecker.
- Added macros for curl_share_setopt and curl_multi_setopt to check at least
  the correct number of arguments.
2008-03-18 08:14:37 +00:00
Daniel Stenberg 55700cb01f - We no longer support setting the CURLOPT_URL option from inside a callback
such as the CURLOPT_SSL_CTX_FUNCTION one treat that as if it was a Location:
  following. The patch that introduced this feature was done for 7.11.0, but
  this code and functionality has been broken since about 7.15.4 (March 2006)
  with the introduction of non-blocking OpenSSL "connects".

  It was a hack to begin with and since it doesn't work and hasn't worked
  correctly for a long time and nobody has even noticed, I consider it a very
  suitable subject for plain removal. And so it was done.
2008-02-20 08:28:02 +00:00
Daniel Stenberg 0e73361a06 added a comment about the ignoring of the Curl_done() return code 2008-02-17 13:38:19 +00:00
Daniel Stenberg ffae4f6b48 - Dmitry Kurochkin cleaned up the pipelining code and removed the need for and
use of the "is_in_pipeline" struct field.
2008-02-03 12:31:35 +00:00
Daniel Stenberg 87fdfe770d Dmitry Kurochkin: In "real world" testing I found more bugs in
pipelining. Broken connection is not restored and we get into infinite
loop. It happens because of wrong is_in_pipeline values.
2008-01-27 22:53:09 +00:00
Daniel Stenberg 79cb74f03a Dmitry Kurochkin's pipelining close-down segfault fix 2008-01-23 12:22:04 +00:00
Daniel Stenberg ef0ed9b720 Dmitry Kurochkin removed the cancelled state for pipelining, as we agreed
that it is bad anyway. Starting now, removing a handle that is in used in a
pipeline will break the pipeline - it'll be set back up again but still...
2008-01-21 23:48:58 +00:00
Daniel Stenberg 62df0ff025 Lau Hang Kin found and fixed a problem with the multi interface when doing
CONNECT over a proxy. curl_multi_fdset() didn't report back the socket
properly during that state, due to a missing case in the switch in the
multi_getsock() function.
2008-01-18 21:51:10 +00:00
Daniel Stenberg ddaa78f08b Dmitry Kurochkin's additional pipelining bugfix 2008-01-16 21:33:52 +00:00
Daniel Stenberg b3de497d83 Dmitry Kurochkin worked a lot on improving the HTTP Pipelining support that
previously had a number of flaws, perhaps most notably when an application
fired up N transfers at once as then they wouldn't pipeline at all that
nicely as anyone would think... Test case 530 was also updated to take the
improved functionality into account.
2008-01-16 12:24:00 +00:00
Daniel Stenberg de23b98522 Introducing curl_easy_pause() and new magic return codes for both the read
and the write callbacks that now can make a connection's reading and/or
writing get paused.
2008-01-08 14:52:05 +00:00
Daniel Stenberg 13648f8ccd struct HandleData is now called struct SingleRequest, and is only for data that
is inited at the start of the DO action. I removed the Curl_transfer_keeper
struct completely, and I had to move out a few struct members (that had to
be set before DO or used after DONE) to the UrlState struct. The SingleRequest
struct is accessed with SessionHandle->req.

One of the biggest reasons for doing this was the bunch of duplicate struct
members in HandleData and Curl_transfer_keeper since it was really messy to
keep track of two variables with the same name and basically the same purpose!
2007-11-24 23:16:55 +00:00
Daniel Stenberg 50feea3eef Rearranged code and changed Curl_readwrite_init() and Curl_pre_readwrite() into
do_init() and do_complete() which now are called first and last in the DO
function. It simplified the flow in multi.c and the functions got more
sensible names!
2007-11-15 21:45:45 +00:00
Daniel Stenberg ad6e28073c removed space after if and while before the parenthesis for better source code
consistency
2007-11-05 09:45:09 +00:00
Daniel Stenberg 51009a40b4 make sure the code deals with failures on the DO_MORE state properly 2007-11-03 14:44:38 +00:00
Dan Fandrich 16b95fc773 Enabled a few more gcc warnings with --enable-debug. Renamed a few
variables to avoid shadowing global declarations.
2007-09-27 01:45:22 +00:00
Dan Fandrich 4f17c58315 Fixed an invalid returned error code added in my last submission. 2007-08-31 17:54:01 +00:00
Dan Fandrich 5d4c981e13 Fixed a few compiler warnings. Try to do a slightly better job of
cleaning up after an OOM condition in curl_multi_add_handle
2007-08-30 18:26:19 +00:00
Dan Fandrich 523767660c Fixed some minor mismatched types found by splint. 2007-08-26 05:53:26 +00:00
Daniel Stenberg 62f0f5571d Robert Iakobashvili re-arranged the internal hash code to work with a custom
hash function for different hashes, and also expanded the default size for
the socket hash table used in multi handles to greatly enhance speed when
very many connections are added and the socket API is used.
2007-06-26 21:09:28 +00:00
Daniel Stenberg b691102ec7 Shmulik Regev fixed a flaw in the multi interface that occurred when doing
HTTP CONNECT over a proxy
2007-06-14 14:42:21 +00:00
Daniel Stenberg b10ff9791b ouch, two conditionals were turned backwards! 2007-06-01 21:24:34 +00:00
Daniel Stenberg 86a25239ec do the update timer stuff even when CURLM_CALL_MULTI_PERFORM is returned 2007-06-01 21:01:57 +00:00
Daniel Stenberg a49e78d9b7 Added CURLMOPT_MAXCONNECTS which is a curl_multi_setopt() option for setting
the maximum size of the connection cache maximum size of the multi handle.
2007-05-30 20:04:44 +00:00
Daniel Stenberg ad19f95f15 James Bursa fixed a bug in the multi handle code that made the connection
cache grow a bit too much, beyond the normal 4 * easy_handles.
2007-05-07 07:07:55 +00:00
Dan Fandrich 9f72db13c4 Fixed an out of memory handling issue with HTTP pipelines. 2007-05-02 19:13:56 +00:00
Daniel Stenberg 2f0539d880 - Set the timeout for easy handles to expire really soon after addition or
when CURLM_CALL_MULTI_PERFORM is returned from curl_multi_socket*/perform,
  to make applications using only curl_multi_socket() to properly function
  when adding easy handles "on the fly". Bug report and test app provided by
  Michael Wallner.
2007-05-02 13:47:56 +00:00
Daniel Stenberg 76627b322e - Robert Iakobashvil added curl_multi_socket_action() to libcurl, which is a
function that deprecates the curl_multi_socket() function. Using the new
  function the application tell libcurl what action that was found in the
  socket that it passes in. This gives a significant performance boost as it
  allows libcurl to avoid a call to poll()/select() for every call to
  curl_multi_socket*().
2007-04-16 16:34:08 +00:00
Yang Tse 038fe54e21 fix compiler warning 2007-04-13 07:57:31 +00:00
Daniel Stenberg 5daa6b9367 Ravi Pratap provided fixes for HTTP pipelining 2007-04-10 20:46:40 +00:00
Yang Tse a11374d994 fix out of memory handling issue 2007-04-07 17:25:19 +00:00
Daniel Stenberg 6c6e4710b5 Robert Iakobashvili made curl_multi_remove_handle() a lot faster when many
easy handles are added to a multi handle, by avoiding the looping over all
the handles to find which one to remove.
2007-04-01 08:24:23 +00:00
Daniel Stenberg b9e5fecf5f Check for a NULL easy->easy_conn in multi_getsock() since it can in fact
happen when curl_multi_remove_handle() is called.
CID 13. coverity.com scan
2007-03-31 10:56:07 +00:00
Daniel Stenberg 6c56b5301f - Daniel Johnson fixed multi code to traverse the easy handle list properly.
A left-over bug from the February 21 fix.
2007-03-25 08:16:16 +00:00
Daniel Stenberg 3d528e1b15 add missing state name for the debug state switch output 2007-03-23 22:25:04 +00:00
Yang Tse 82d310d0d9 Do not remove CURLM_STATE_WAITPROXYCONNECT from the CURLMstate enum
in builds with HTTP support disabled to keep consistent enum values
for CURLMstate in all kind of builds.
2007-03-01 12:02:17 +00:00
Yang Tse acc4cf87cd no proxy support if libcurl is built with HTTP disabled 2007-02-27 02:24:13 +00:00
Gisle Vanem c514a2a89a Removed inclusion of <sys/types.h> and <sys/stat.h> in .c-files
since they're already included through "setup.h".
2007-02-26 04:24:26 +00:00
Daniel Stenberg b819c72700 - Adam D. Moss made the HTTP CONNECT procedure less blocking when used from
the multi interface. Note that it still does a part of the connection in a
  blocking manner.
2007-02-25 11:38:13 +00:00
Daniel Stenberg f19d333ef6 - Ravi Pratap provided work on libcurl making pipelining more robust and
fixing some bugs:
  o Don't mix GET and POST requests in a pipeline
  o Fix the order in which requests are dispatched from the pipeline
  o Fixed several curl bugs with pipelining when the server is returning
    chunked encoding:
    * Added states to chunked parsing for final CRLF
    * Rewind buffer after parsing chunk with data remaining
    * Moved chunked header initializing to a spot just before receiving
      headers
2007-02-21 21:59:40 +00:00
Daniel Stenberg cbf58d88d0 - Jeff Pohlmeyer identified two problems: first a rather obscure problem with
the multi interface and connection re-use that could make a
  curl_multi_remove_handle() ruin a pointer in another handle.

  The second problem was less of an actual problem but more of minor quirk:
  the re-using of connections wasn't properly checking if the connection was
  marked for closure.
2007-02-18 23:02:42 +00:00
Daniel Stenberg c7d0966201 - Jeff Pohlmeyer fixed a flaw in curl_multi_add_handle() when adding a handle
that has an easy handle present in the "closure" list pending closure.
2007-02-12 12:15:41 +00:00
Yang Tse cdbbb7d900 Compiler warning fix 2007-01-27 03:14:25 +00:00
Daniel Stenberg 385e612fa5 - Armel Asselin improved libcurl to behave a lot better when an easy handle
doing an FTP transfer is removed from a multi handle before completion. The
  fix also fixed the "alive counter" to be correct on "premature removal" for
  all protocols.
2007-01-16 22:22:10 +00:00
Daniel Stenberg e4505aefd9 Jared Lundell filed bug report #1604956
(http://curl.haxx.se/bug/view.cgi?id=1604956) which identified setting
CURLOPT_MAXCONNECTS to zero caused libcurl to SIGSEGV. Starting now, libcurl
will always internally use no less than 1 entry in the connection cache.
2006-12-05 15:36:26 +00:00
Daniel Stenberg e1edd41e1b Ravi Pratap provided a major update with pipelining fixes. We also no longer
re-use connections (for pipelining) before the name resolving is done.
2006-10-23 20:34:56 +00:00
Daniel Stenberg 4bdd7596d3 the expire timer is a bit too annoying to see all the time ;-) 2006-10-18 15:11:24 +00:00
Daniel Stenberg 86f93a53d6 print the actual (externally known) easy handle and not the internal container
for it
2006-10-13 14:54:36 +00:00
Daniel Stenberg efe3cb6e1a Added curl_multi_dump() when built with CURLDEBUG - this is not a stable public
function, this is only meant to allow easier tracking of the internal handle's
state and what sockets they use. Only for research and development.
2006-10-13 07:11:26 +00:00
Daniel Stenberg ab60a12465 Starting now, adding an easy handle to a multi stack that was already added
to a multi stack will cause CURLM_BAD_EASY_HANDLE to get returned.
2006-10-12 14:30:47 +00:00
Daniel Stenberg b61c06384a Jeff Pohlmeyer has been working with the hiperfifo.c example source code,
and while doing so it became apparent that the current timeout system for
the socket API really was a bit awkward since it become quite some work to
be sure we have the correct timeout set.

Jeff then provided the new CURLMOPT_TIMERFUNCTION that is yet another
callback the app can set to get to know when the general timeout time
changes and thus for an application like hiperfifo.c it makes everything a
lot easier and nicer. There's a CURLMOPT_TIMERDATA option too of course in
good old libcurl tradition.
2006-10-12 08:36:47 +00:00
Daniel Stenberg 1ce7b48057 mark the handle as no longer having a broken pipe when a transfer has failed 2006-10-10 14:23:34 +00:00
Daniel Stenberg 7d0c58a285 when going to completed due to error, mark the handle as not in a pipeline
anymore
2006-10-09 21:24:34 +00:00
Yang Tse 15e3dfe1d3 Compiler warning fix 2006-10-09 11:21:40 +00:00
Daniel Stenberg a1de9367ec Bogdan Nicula's second test case (posted Sun, 08 Oct 2006) converted to test
case 535 and it now runs fine. Again a problem with the pipelining code not
taking all possible (error) conditions into account.
2006-10-09 06:58:05 +00:00
Daniel Stenberg 1128029599 don't display or act on state changes that doesn't actually change state 2006-10-07 21:04:57 +00:00
Daniel Stenberg befc30bc55 Bogdan Nicula's hanging test case was converted to test case 533 and the test
now runs fine.
2006-10-06 21:19:57 +00:00
Daniel Stenberg 552b963e6d Dmitriy Sergeyev provided an example source code that crashed CVS libcurl
but that worked nicely in 7.15.5. I converted it into test case 532 and
fixed the problem.
2006-10-04 21:11:08 +00:00
Daniel Stenberg ae13c93b7d Reported in #1561470 (http://curl.haxx.se/bug/view.cgi?id=1561470), libcurl
would crash if a bad function sequence was used when shutting down after
using the multi interface (i.e using easy_cleanup after multi_cleanup) so
precautions have been added to make sure it doesn't any more - test case 529
was added to verify.
2006-09-28 21:26:06 +00:00
Yang Tse b2ca777a08 Compiler warning fix 2006-09-25 00:16:23 +00:00
Daniel Stenberg ab798fe5ba (FTP) a failed upload does not invalidate the control connection 2006-09-21 20:52:58 +00:00
Daniel Stenberg 71920d61e6 Michael Wallner's test program again help me track down a problem. This time
it basically was that we didn't remove the current connection from the pipe
list when following a redirect. Also in this commit: several cases of
additional debug code for debug builds helping to check and track down some
signs of run-time trouble.
2006-09-20 12:03:50 +00:00
Daniel Stenberg 2d5fc39d35 Resize the connection cache upwards when adding more handles than what
currently fits in the cache, to make the cache work better especially for
pipelining cases but also for "mere" (persistent) connection re-use.
2006-09-16 21:50:29 +00:00
Yang Tse 733a184ce0 Compiler warning fix 2006-09-12 23:51:01 +00:00
Daniel Stenberg 29dc39fce1 - Fixed my breakage from earlier today so that doing curl_easy_cleanup() on a
handle that is part of a multi handle first removes the handle from the
  stack.

- Added CURLOPT_SSL_SESSIONID_CACHE and --no-sessionid to disable SSL
  session-ID re-use on demand since there obviously are broken servers out
  there that misbehave with session-IDs used.
2006-09-11 17:18:18 +00:00
Daniel Stenberg 8240cea628 Jeff Pohlmeyer presented a *multi_socket()-using program that exposed a
problem with it (SIGSEGV-style). It clearly showed that the existing
  socket-state and state-difference function wasn't good enough so I rewrote
  it and could then re-run Jeff's program without any crash. The previous
  version clearly could miss to tell the application when a handle changed
  from using one socket to using another.

  While I was at it (as I could use this as a means to track this problem
  down), I've now added a 'magic' number to the easy handle struct that is
  inited at curl_easy_init() time and cleared at curl_easy_cleanup() time that
  we can use internally to detect that an easy handle seems to be fine, or at
  least not closed or freed (freeing in debug builds fill the area with 0x13
  bytes but in normal builds we can of course not assume any particular data
  in the freed areas).
2006-09-10 22:15:32 +00:00
Yang Tse bb87b65f08 Compiler warning fix 2006-09-09 13:24:42 +00:00
Yang Tse dc7c915553 Compilation fix 2006-09-08 05:18:07 +00:00
Daniel Stenberg b7eeb6e67f Major overhaul introducing http pipelining support and shared connection
cache within the multi handle.
2006-09-07 21:49:20 +00:00
Daniel Stenberg d7168a82e2 Dmitriy Sergeyev found and fixed a multi interface flaw when using asynch
name resolves. It could get stuck in the wrong state.
2006-08-31 12:53:39 +00:00
Daniel Stenberg 2ff609dd43 Armel Asselin reported that the 'running_handles' counter wasn't updated
properly if you removed a "live" handle from a multi handle with
curl_multi_remove_handle().
2006-08-25 13:53:20 +00:00
Daniel Stenberg 8709f6c4b3 oops, the previous commit was incomplete as we made an unconditional call
to multi_runsingle() without it being really necessary or good
2006-08-04 14:39:19 +00:00
Daniel Stenberg 2ac560e58b even when we get a single connection to deal with, we must still check for
timeout'ed connections and possibly deal with them too
2006-08-04 13:06:36 +00:00
Daniel Stenberg 01a79be2c9 removed running_handles argument from multi_runsingle() since it wasn't really
used anymore since multi->num_alive was introduced
2006-08-03 11:47:42 +00:00
Yang Tse d211fcd34f Silence compiler warning 'unused parameter running_handles' in function multi_runsingle(). This is done here returning multi->num_alive in the running_handles parameter even when functions that call multi_runsingle() at this moment overwrite the returned value with the one that is valid when those functions curl_multi_perform() and multi_socket() have removed expired timers from the splay. Most probably, parameter 'running_handles' in function multi_runsingle() should be just removed. 2006-08-03 11:41:49 +00:00
Daniel Stenberg 159834171e keep count of the number of "alive" handles in a struct member, as otherwise
*multi_socket*() can't return the proper number
2006-08-02 22:29:29 +00:00
Daniel Stenberg 9f579f12fc spell-fixed a comment 2006-08-01 09:38:35 +00:00
Daniel Stenberg 01b2cf82ec curl_multi_socket() and curl_multi_socket_all() got modified prototypes: they
both now provide the number of running handles back to the calling function.
2006-07-30 22:44:07 +00:00
Daniel Stenberg 6f6b93da02 [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.
2006-07-26 22:19:42 +00:00
Daniel Stenberg 06d05b18b2 Jari Sundell did some excellent research and bug tracking, figured out that
we did wrong and patched it: When nodes were removed from the splay tree,
and we didn't properly remove it from the splay tree when an easy handle was
removed from a multi stack and thus we could wrongly leave a node in the
splay tree pointing to (bad) memory.
2006-07-17 18:35:58 +00:00
Yang Tse 700cd5805c Oops, missing "u" 2006-07-13 18:57:34 +00:00
Yang Tse 73f407b7ae Fix compiler warning. 2006-07-13 18:44:24 +00:00
Yang Tse 34f5e8ad0e DNS cache must use the multi DNS cache if the easy handle's one is not using anyone in curl_multi_add_handle. 2006-07-10 16:14:36 +00:00
Daniel Stenberg ca319f63ad Ingmar Runge provided a source snippet that caused a crash. The reason for
the crash was that libcurl internally was a bit confused about who owned the
DNS cache at all times so if you created an easy handle that uses a shared
DNS cache and added that to a multi handle it would crash. Now we keep more
careful internal track of exactly what kind of DNS cache each easy handle
uses: None, Private (allocated for and used only by this single handle),
Shared (points to a cache held by a shared object), Global (points to the
global cache) or Multi (points to the cache within the multi handle that is
automatically shared between all easy handles that are added with private
caches).
2006-07-07 22:58:06 +00:00
Yang Tse b01286d280 fix better minor compiler warning 2006-06-28 05:22:47 +00:00
Yang Tse 64f72c22b9 fix minor compiler warning 2006-06-28 04:17:04 +00:00
Daniel Stenberg a8ac6f1dc1 Arve Knudsen found a flaw in curl_multi_fdset() for systems where
curl_socket_t is unsigned (like Windows) that could cause it to wrongly
return a max fd of -1.
2006-06-23 22:07:06 +00:00
Daniel Stenberg dfe1884c25 Peter Silva introduced CURLOPT_MAX_SEND_SPEED_LARGE and
CURLOPT_MAX_RECV_SPEED_LARGE that limit tha maximum rate libcurl is allowed
to send or receive data. This kind of adds the the command line tool's
option --limit-rate to the library.

The rate limiting logic in the curl app is now removed and is instead
provided by libcurl itself. Transfer rate limiting will now also work for -d
and -F, which it didn't before.
2006-06-22 21:36:53 +00:00
Daniel Stenberg 405d98ee63 adapted to the new Curl_splayremovebyaddr() proto 2006-05-27 22:26:16 +00:00
Daniel Stenberg 482b3ba702 long/int cleanup to silence picky compiler warnings 2006-05-26 11:26:42 +00:00
Daniel Stenberg 73daf8ce33 Robson Braga Araujo fixed a memory leak when you added an easy handle to a
multi stack and that easy handle had already been used to do one or more
easy interface transfers, as then the code threw away the previously used
DNS cache without properly freeing it.
2006-05-09 11:33:00 +00:00
Gisle Vanem 12db20be4e Fixed signed/unsigned convertion errors in Salford-C.
#ifdef around WSAEDISCON in strerror.c.
2006-04-26 17:26:22 +00:00
Daniel Stenberg ecc6c1f501 prevent signed/unsigned warnings 2006-04-25 05:32:05 +00:00
Daniel Stenberg 0ec96e4279 each socket is used by exactly one easy handle, but of course each easy handle
can and will use more than one socket
2006-04-21 13:40:07 +00:00
Daniel Stenberg 48f56d9600 attempt to silence the MIPSPro compiler warning 2006-04-18 10:55:41 +00:00
Daniel Stenberg 686d90745b First curl_multi_socket() commit. Should primarily be considered as an internal
code rearrange to fit the future better.
2006-04-10 15:00:53 +00:00
Daniel Stenberg 4486d336a6 argh, forgot the check for a connection before we call Curl_done 2006-02-23 21:29:48 +00:00
Daniel Stenberg 6fdbb01194 Lots of work and analysis by "xbx___" in bug #1431750
(http://curl.haxx.se/bug/view.cgi?id=1431750) helped me identify and fix two
different but related bugs:

1) Removing an easy handle from a multi handle before the transfer is done
   could leave a connection in the connection cache for that handle that is
   in a state that isn't suitable for re-use. A subsequent re-use could then
   read from a NULL pointer and segfault.

2) When an easy handle was removed from the multi handle, there could be an
   outstanding c-ares DNS name resolve request. When the response arrived,
   it caused havoc since the connection struct it "belonged" to could've
   been freed already.

Now Curl_done() is called when an easy handle is removed from a multi handle
pre-maturely (that is, before the transfer was complteted). Curl_done() also
makes sure to cancel all (if any) outstanding c-ares requests.
2006-02-23 12:20:48 +00:00
Daniel Stenberg 87bcb6f377 Karl M added the CURLOPT_CONNECT_ONLY and CURLINFO_LASTSOCKET options that
an app can use to let libcurl only connect to a remote host and then extract
the socket from libcurl. libcurl will then not attempt to do any transfer at
all after the connect is done.
2006-02-11 22:35:16 +00:00
Daniel Stenberg b7ffc6bb45 remove old printf() debug leftover 2005-03-08 22:21:59 +00:00
Daniel Stenberg 6a2e21ec8c FTP code turned into state machine. Not completely yet, but a good start.
The tag 'before_ftp_statemachine' was set just before this commit in case
of future need.
2005-02-09 13:06:40 +00:00
Daniel Stenberg 686d767053 if the DO operation returns failure, bail out and close down nicely to
prevent memory leakage
2005-01-30 22:54:06 +00:00
Daniel Stenberg 8dbaf534c8 Using the multi interface, and doing a requsted a re-used connection that
gets closed just after the request has been sent failed and did not re-issue
a request on a fresh reconnect like the easy interface did. Now it does!
(define CURL_MULTIEASY, run test case 160)
2005-01-29 22:31:06 +00:00
Daniel Stenberg 59b45a90cc multi interface: when a request is denied due to "Maximum redirects followed"
libcurl leaked the last Location: URL.
2005-01-29 12:01:20 +00:00
Daniel Stenberg 043d70fcdf Use plain structs and not typedef'ed ones in the hash and linked-list code. 2005-01-25 00:06:29 +00:00
Daniel Stenberg e3fa7d021e Renamed easy.h and multi.h to easyif.h and multiif.h to make sure they don't
shadow our public headers with the former names.
2005-01-11 15:25:29 +00:00
Daniel Stenberg 29102befa6 Cyrill Osterwalder posted a detailed analysis about a bug that occurs when
using a custom Host: header and curl fails to send a request on a re-used
persistent connection and thus creates a new connection and resends it. It
then sent two Host: headers. Cyrill's analysis was posted here:
http://curl.haxx.se/mail/archive-2005-01/0022.html
2005-01-11 14:00:45 +00:00
Daniel Stenberg 065e466f1a Use Curl_easy_addmulti() to clear associations from easy handles to multi
handles. Include multi.h to get proto.
2005-01-10 11:42:20 +00:00
Daniel Stenberg 21bb852750 Pavel Orehov reported memory problems with the multi interface in bug report
#1098843. In short, a shared DNS cache was setup for a multi handle and when
the shared cache was deleted before the individual easy handles, the latter
cleanups caused read/writes to already freed memory.
2005-01-10 10:07:07 +00:00
Daniel Stenberg 92637303db fix the return code for curl_multi_add_handle() 2004-08-31 06:04:43 +00:00
Daniel Stenberg 6ed5feda2b First attempt at making the multi interface work when connecting to a host
that resolves to multiple IP addresses.
2004-06-29 11:20:07 +00:00
Daniel Stenberg d70a335dce new Curl_done() proto 2004-05-17 08:07:07 +00:00
Daniel Stenberg d7cb09bd18 better bailing out on memory failure 2004-05-17 08:04:42 +00:00
Daniel Stenberg de279099e5 bail out nicely if strdup() returns NULL, removed trailing whitespace 2004-05-17 06:53:41 +00:00
Daniel Stenberg 1c69b15c7c return on memory alloc fail 2004-05-13 15:17:49 +00:00
Daniel Stenberg d60c22572b Curl_done() and the protocol-specific conn->curl_done() functions now all
take a CURLcode as a second argument, that is non-zero when Curl_done()
is called after an error was returned from Curl_do() (or similar).
2004-05-12 12:06:39 +00:00
Daniel Stenberg bbafb2eb27 curl_global_init_mem() allows the memory functions to be replaced.
memory.h is included everywhere for this.
2004-05-11 11:30:23 +00:00
Daniel Stenberg 648e82f05d Major hostip.c cleanup and split into multiple files and easier #ifdef
usage.
2004-04-26 07:20:11 +00:00
Daniel Stenberg 7ea837a18c adjusted to the new dns cache function to hide more hostip internals 2004-03-30 13:02:31 +00:00
Daniel Stenberg 6950aeafcc init the dns pointer to NULL for clarity 2004-03-30 08:14:37 +00:00
Daniel Stenberg e545e33d5f Gisle Vanem's fixes to use CURL_SOCKET_BAD more instead of -1 for sockets. 2004-03-11 13:13:35 +00:00
Daniel Stenberg 7225b14002 curl_socket_t mistakes cleanup 2004-03-10 16:01:47 +00:00
Daniel Stenberg ce5805a955 Use curl_socket_t instead of int for holding sockets. The typedefs and
defines are in setup.h.
2004-03-09 22:52:50 +00:00
Daniel Stenberg 465753c2de When following to a new URL, we must make sure to call Curl_done() first,
since the current connection must be taken care of properly before we move
on. Christopher R. Palmer reported a problem he found due to this mistake.
2004-03-04 16:13:33 +00:00
Daniel Stenberg 4816294f52 compiler warning fix, compare struct pointers of the same type 2004-02-05 09:37:04 +00:00
Daniel Stenberg 3a61c98b65 Peter Sylvester brought code that now allows a callback to modified the URL
even when the multi interface is used, and then libcurl will simulate a
"follow location" to that new URL. Test 509 was added to test this feature.
2004-01-12 15:26:32 +00:00
Daniel Stenberg 053f6c85ef updated year in the copyright string 2004-01-07 09:19:33 +00:00
Daniel Stenberg 1e98727c55 FTPS support added as RFC2228 and the murray-ftp-auth-ssl draft describe it 2003-11-24 07:15:37 +00:00
Daniel Stenberg 381c6c5d52 minor fix to not shadow a variable 2003-10-18 20:38:18 +00:00
Daniel Stenberg 8341e8e502 Clear the connection pointer after the async resolve has failed.
This cures the problem reported by Giuseppe Attardi on October 12, 2003.
2003-10-13 12:21:56 +00:00
Daniel Stenberg 343291ce37 Based on a patch provided by Siddhartha Prakash Jain. In Curl_resolv() when
my_getaddrinfo() has been called (and wait has been set to TRUE), we check
if the name already is resolved and if so don't return wait status to the
parent. This can happen with IP-only names.
2003-10-04 14:50:45 +00:00
Daniel Stenberg 8aa2894bfb failing to resolve a name using ares must Curl_disconnect() the handle
properly or risk getting into trouble!
2003-09-21 23:10:47 +00:00
Daniel Stenberg 0efcb57623 For easy handles within multi handles, we share the DNS cache always. 2003-09-11 22:14:29 +00:00
Daniel Stenberg 61629d2c86 made curl_multi_info_read() set 'msgs_in_queue' to 0 even when it returns
NULL!
2003-08-20 13:49:46 +00:00