[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.5 Setting up the transport layer
The next step is to setup the underlying transport layer details. The Berkeley sockets are implicitly used by GnuTLS, thus a call to gnutls_transport_set_int would be sufficient to specify the socket descriptor.
void gnutls_transport_set_int (gnutls_session_t session, int i)
void gnutls_transport_set_int2 (gnutls_session_t session, int recv_int, int send_int)
If however another transport layer than TCP is selected, then a pointer should be used instead to express the parameter to be passed to custom functions. In that case the following functions should be used instead.
void gnutls_transport_set_ptr (gnutls_session_t session, gnutls_transport_ptr_t ptr)
void gnutls_transport_set_ptr2 (gnutls_session_t session, gnutls_transport_ptr_t recv_ptr, gnutls_transport_ptr_t send_ptr)
Moreover all of the following push and pull callbacks should be set.
- Function: void gnutls_transport_set_push_function (gnutls_session_t session, gnutls_push_func push_func)
session: is a
gnutls_session_t
structure.push_func: a callback function similar to
write()
This is the function where you set a push function for gnutls to use in order to send data. If you are going to use berkeley style sockets, you do not need to use this function since the default send(2) will probably be ok. Otherwise you should specify this function for gnutls to be able to send data. The callback should return a positive number indicating the bytes sent, and -1 on error.
push_func
is of the form, ssize_t (*gnutls_push_func)(gnutls_transport_ptr_t, const void*, size_t);
- Function: void gnutls_transport_set_vec_push_function (gnutls_session_t session, gnutls_vec_push_func vec_func)
session: is a
gnutls_session_t
structure.vec_func: a callback function similar to
writev()
Using this function you can override the default writev(2) function for gnutls to send data. Setting this callback instead of
gnutls_transport_set_push_function()
is recommended since it introduces less overhead in the TLS handshake process.vec_func
is of the form, ssize_t (*gnutls_vec_push_func) (gnutls_transport_ptr_t, const giovec_t * iov, int iovcnt);Since: 2.12.0
- Function: void gnutls_transport_set_pull_function (gnutls_session_t session, gnutls_pull_func pull_func)
session: is a
gnutls_session_t
structure.pull_func: a callback function similar to
read()
This is the function where you set a function for gnutls to receive data. Normally, if you use berkeley style sockets, do not need to use this function since the default recv(2) will probably be ok. The callback should return 0 on connection termination, a positive number indicating the number of bytes received, and -1 on error.
gnutls_pull_func
is of the form, ssize_t (*gnutls_pull_func)(gnutls_transport_ptr_t, void*, size_t);
- Function: void gnutls_transport_set_pull_timeout_function (gnutls_session_t session, gnutls_pull_timeout_func func)
session: is a
gnutls_session_t
structure.func: a callback function
This is the function where you set a function for gnutls to know whether data are ready to be received. It should wait for data a given time frame in milliseconds. The callback should return 0 on timeout, a positive number if data can be received, and -1 on error. You’ll need to override this function if
select()
is not suitable for the provided transport calls.As with
select()
, if the timeout value is zero the callback should return zero if no data are immediately available.gnutls_pull_timeout_func
is of the form, int (*gnutls_pull_timeout_func)(gnutls_transport_ptr_t, unsigned int ms);Since: 3.0
The functions above accept a callback function which
should return the number of bytes written, or -1 on
error and should set errno
appropriately.
In some environments, setting errno
is unreliable. For example
Windows have several errno variables in different CRTs, or in other
systems it may be a non thread-local variable. If this is a concern to
you, call gnutls_transport_set_errno with the intended errno
value instead of setting errno
directly.
- Function: void gnutls_transport_set_errno (gnutls_session_t session, int err)
session: is a
gnutls_session_t
structure.err: error value to store in session-specific errno variable.
Store
err
in the session-specific errno variable. Useful values forerr
is EAGAIN and EINTR, other values are treated will be treated as real errors in the push/pull function.This function is useful in replacement push and pull functions set by
gnutls_transport_set_push_function()
andgnutls_transport_set_pull_function()
under Windows, where the replacements may not have access to the sameerrno
variable that is used by GnuTLS (e.g., the application is linked to msvcr71.dll and gnutls is linked to msvcrt.dll).
GnuTLS currently only interprets the EINTR, EAGAIN and EMSGSIZE errno values and returns the corresponding GnuTLS error codes:
-
GNUTLS_E_INTERRUPTED
-
GNUTLS_E_AGAIN
-
GNUTLS_E_LARGE_PACKET
The EINTR and EAGAIN values are returned by interrupted system calls, or when non blocking IO is used. All GnuTLS functions can be resumed (called again), if any of the above error codes is returned. The EMSGSIZE value is returned when attempting to send a large datagram.
In the case of DTLS it is also desirable to override the generic
transport functions with functions that emulate the operation
of recvfrom
and sendto
. In addition
DTLS requires timers during the receive of a handshake
message, set using the gnutls_transport_set_pull_timeout_function
function. To check the retransmission timers the function
gnutls_dtls_get_timeout is provided, which returns the time
remaining until the next retransmission, or better the time until
gnutls_handshake should be called again.
- Function: void gnutls_transport_set_pull_timeout_function (gnutls_session_t session, gnutls_pull_timeout_func func)
session: is a
gnutls_session_t
structure.func: a callback function
This is the function where you set a function for gnutls to know whether data are ready to be received. It should wait for data a given time frame in milliseconds. The callback should return 0 on timeout, a positive number if data can be received, and -1 on error. You’ll need to override this function if
select()
is not suitable for the provided transport calls.As with
select()
, if the timeout value is zero the callback should return zero if no data are immediately available.gnutls_pull_timeout_func
is of the form, int (*gnutls_pull_timeout_func)(gnutls_transport_ptr_t, unsigned int ms);Since: 3.0
- Function: unsigned int gnutls_dtls_get_timeout (gnutls_session_t session)
session: is a
gnutls_session_t
structure.This function will return the milliseconds remaining for a retransmission of the previously sent handshake message. This function is useful when DTLS is used in non-blocking mode, to estimate when to call
gnutls_handshake()
if no packets have been received.Returns: the remaining time in milliseconds.
Since: 3.0
6.5.1 Asynchronous operation | ||
6.5.2 DTLS sessions |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February 9, 2014 using texi2html 5.0.