Thanks for the kind comments :-) I haven't touched any C since my
University days!
On Sun, 24 Feb 2008, Danny Backx wrote:
> Hi John,
>
> Very nice work you did !
>
> On Sun, 2008-02-24 at 09:23 +0000, john wrote:
>> I'm now trying to tie up a few loose ends, and one thing I couldn't sort
>> out was an error when trying to build the socket extensions for Ruby - one
>> the functions that they use is h_errno; the code compiles cleanly, but
>> when it comes to linking the final binary it falls over with an undefined
>> reference to "__h_errno_location". I can't find this symbol anywhere.
>
> Well, when you say "sockets" and "Windows" then you need to think
> winsock. Combine this with the fact that "errno" is a posix thing which
> Windows API doesn't support, and here we are.
>
> That said, I'm sure we can get through this. Usually when people use
> sockets/winsock, the better thing to do is to replace all use of errno
> by the winsock equivalent WSAGetLastError().
>
> An example of how to do such things is in the tools/errno directory of
> our SVN : Pedro built a small errno emulation library there. It also
> contains a function static char *strwinerror (char* buf, DWORD error)
> which you can use as sample code to write something similar to the
> gai_strerror function that you miss.
>
Ok, I *think* I've got it...
The code in question in the Ruby socket library (ext/socket/getaddrinfo.c)
is this:
h_error = h_errno;
if (hp == NULL) {
switch (h_error) {
case HOST_NOT_FOUND:
case NO_DATA:
error = EAI_NODATA;
break;
case TRY_AGAIN:
error = EAI_AGAIN;
break;
case NO_RECOVERY:
default:
error = EAI_FAIL;
break;
}
goto bad;
}
If we build liberrno.a from the svn/tools area and include the provided
"errno.h" header, then I could do something like:
h_error = strwinerror();
if (hp == NULL) {
switch (h_error) {
case ENETDOWN:
case ENODATA:
error = EAI_NODATA;
break;
case ETIMEDOUT:
error = EAI_AGAIN;
break;
case ECONNREFUSED:
error = EAI_FAIL;
break;
default:
error = EAI_FAIL;
break;
}
goto bad;
}
Or whatever the most suitable windows error codes would be to map to the
Ruby error codes.
... and it would be the same sort of thing again for
ext/socket/getnameinfo.c?
-John
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Cegcc-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cegcc-devel