cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker mailing list Archives

[ curl-Bugs-1481217 ] Curl_ourerrno implementation, GetLastError, WSAGetLastError

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Wed, 03 May 2006 09:11:54 -0700

Bugs item #1481217, was opened at 2006-05-03 09:11
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1481217&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: libcurl
Group: portability problem
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Daniel Stenberg (bagder)
Summary: Curl_ourerrno implementation, GetLastError, WSAGetLastError

Initial Comment:

Hi,

I've compiled and used libcurl version 7.15.3 on the
Windows platform and I think I found a bug.

It has to do with the Curl_ourerrno() function in
connect.c.

This function exists to abstract from platform
differences to make the code more portable.

For the windows platform, Curl_ourerrno() returns the
return value of the GetLastError() function, while for
other platforms it returns the value of the errno
variable.

However, on the windows platform, I think that
Curl_ourerrno() should return the return value of the
WSAGetLastError() function instead of the return value
of the GetLastError() function.

MSDN documentation states that GetLastError() will not
return error information about socket operations,
WSAGetLastError() should be called instead.

I've tested this and this is indeed the case. One
occurrence of the issue is in singleipconnect() in
connect.c:

  if(-1 == rc) {

    error = Curl_ourerrno();

    switch (error) {
    case EINPROGRESS:
    case EWOULDBLOCK:
      rc = waitconnect(sockfd, timeout_ms);
    .
    .

There is a piece of code here that in the case of an
error (-1 == rc), retrieves the error value using
Curl_ourerrno() and performs an action based on its
value (the switch statement).

In the case of a non-blocking socket, EWOULDBLOCK
might occur, but this is not fatal, the library just
should try again. The code in the EWOULDBLOCK case
does exactly that, but on the windows platform, the
Curl_ourerrno() function will never return
EWOULDBLOCK, because it is implemented using a
GetLastError() call instead of a WSAGetLastError()
call. I replaced GetLastError() with WSAGetLastError()
and then it does work.

I haven't explored other occurrences, but it might be
an issue in more places.

Can someone confirm if this is indeed a bug, and
whether it has been noticed before?

My proposed fix is to replace GetLastError() with
WSAGetLastError(), but I'm not sure whether
Curl_ourerrno() is also used to retrieve non-socket
related errors (in those cases GetLastError() should
be called).

I'm using Windows 2000 professional
version 5.0 (Build 2195: Service Pack 4),
but I assume the issue will occur on all windows
platforms.

With kind regards,

Roland Blom
Triple IT, Netherlands
curl_at_roland.triple-it.nl

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1481217&group_id=976
Received on 2006-05-03

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET