[libvirt] [PATCH] remote: Fix TLS transport on Windows
Matthias Bolte
matthias.bolte at googlemail.com
Mon Nov 22 21:50:14 UTC 2010
2010/11/22 Eric Blake <eblake at redhat.com>:
> On 11/22/2010 01:42 PM, Matthias Bolte wrote:
>>>> This doesn't entirely make any sense to me. GNUTLS also uses GNULIB,
>>>> including all its socket wrappers for send/recv. If the push/pull
>>>> function is NULL, gnulib does this
>>>>
>>>> if (session->internals._gnutls_push_func == NULL)
>>>> {
>>>> i = send (GNUTLS_POINTER_TO_INT (fd), &ptr[n - left], left, 0);
>>>>
>>
>> Okay, yes GnuTLS uses gnulib, but they explicitly don't use gnulib's
>> replacements for send() and recv() on Windows. See
>> lib/gnutls_buffers.c:
>>
>> /* We need to disable gnulib's replacement wrappers to get native
>> Windows interfaces. */
>> #undef recv
>> #undef send
>>
>> GnuTLS decided to use the native Windows versions of send() and
>> recv(). This cannot be changed, as that would break existing
>> applications using GnuTLS on Windows relying on GnuTLS using the
>> native Windows versions of send() and recv(). Therefore, I think my
>> patch is necessary, as libvirt requires GnuTLS to use gnulib's
>> replacement functions.
>
> Makes sense to me. However, why the double cast?
>
> +#if HAVE_WINSOCK2_H
> +static ssize_t
> +custom_gnutls_push(void *s, const void *buf, size_t len)
> +{
> + return send((int)(long)s, buf, len, 0);
> +}
> +
> +static ssize_t
> +custom_gnutls_pull(void *s, void *buf, size_t len)
> +{
> + return recv((int)(long)s, buf, len, 0);
> +}
> +#endif
>
> Wouldn't send((size_t)s, ...) be better than send((int)(long)s,...)?
>
I just used what'a in curl, as directly casting from void* to int
would give this error on 64bit platform:
error: cast from pointer to integer of different size [-Wpointer-to-int-cast]
(Yes, this is tested on Linux 64bit, as I didn't setup mingw-w64 yet)
Casting to size_t works too.
Here's a v2 that casts to size_t and has an improved commit message.
Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-remote-Fix-TLS-transport-on-Windows_v2.patch
Type: text/x-patch
Size: 2217 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101122/72072e67/attachment-0001.bin>
More information about the libvir-list
mailing list