[gnutls-devel] Waiting for input data
tim.ruehsen at gmx.de
Fri Feb 8 16:15:19 CET 2013
Am Friday 08 February 2013 schrieb Jaak Ristioja:
> On 08.02.2013 16:38, Tim Ruehsen wrote:
> > Am Friday 08 February 2013 schrieb Jaak Ristioja:
> >> On 08.02.2013 15:54, Tim Ruehsen wrote:
> >>> Maybe this code snippet/example from libmget (License LGPL3+) may help
> >>> you: It assumes a non-blocking socket descriptor set by
> >>> gnutls_transport_set_ptr(session, (void *)(ssize_t)sockfd);
> >> Well I have used (void *)(intptr_t) sockfd, but it doesn't solve the
> >> real issue here, it just silences the compiler. When converted back
> >> using (int)(intptr_t), it might not compare equal to the original.
> > Couldn't you use a pointer to your 'socket'.
> > gnutls_transport_set_ptr(session, &sockfd);
> > and reading back with
> > int sockfd = *(int *)gnutls_transport_get_ptr(session);
> > If your sockfd is of type 'int'. If not, use a different type.
> No I can't. The variable sockfd might go out of scope or get destroyed
> otherwise, effectively invalidating the pointer.
If you don't use threads, just use a static variable to store your sockfd.
With threads, you just malloc a store for sockfd
sockfd_ptr = malloc(sizeof(sockfd));
*sockfd_ptr = sockfd;
when closing the session, you have to free it:
Mit freundlichem Gruß
More information about the Gnutls-devel