cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Curl-library digest, Vol 1 #201 - 1 msg

From: Vitlay Lipovetsky <vit_at_fuib.com>
Date: Tue, 31 Jul 2001 14:23:27 +0300

I've found a few error using lincurl under win32.

First of all. I had to add these lines to the config-win32.h
to manage to compile libcurl with MSVC.

//** By Lipovetsky
#ifdef _MSC_VER
#include <stdlib.h>
typedef size_t ssize_t;
typedef int socklen_t;
#endif
//** By Lipovetsky

Then LIBCURL doesn't work errors about winsockets properly because it
doesn't use
WIN 32 sockets API.

I offer to use these functions to make error handling clearer.

void WSocketDLL::throwException(_FLPAR_, const char *api)
{
char ErrorMsg[MSG_BUF_SIZE];

Win32Error(ErrorMsg, api, WSAGetLastError());
}

DWORD Win32Error(char *message, const char *api, DWORD dwError)
{
 LPTSTR lpMsgBuf;
 LPTSTR MsgBuf;

 if (dwError == 0) dwError = GetLastError();

 FormatMessage(
   FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
   NULL,
   dwError,
   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
   (LPTSTR)&lpMsgBuf,
   0,
   NULL
 );

 // Copy the string.
 if (lpMsgBuf == NULL || lpMsgBuf[0] == '\0') {
  MsgBuf = "EMPTY";
  }else{
    MsgBuf = lpMsgBuf;
 }//if

 sprintf(message, "API Error %d: %s from %s\n", dwError, MsgBuf, api);

 // Free the buffer.
 if (lpMsgBuf != NULL) LocalFree( lpMsgBuf );

 return dwError;

}//Win32Error

In the URL.C we shouldn't use
select() if sockets are blocking ones.

My best regards,
Vitaly Lipovetsky

_______________________________________________
Curl-library mailing list
http://curl.haxx.se/libcurl/
Received on 2001-07-31