2 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 * 2009, 2010, 2011 Free Software Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GnuTLS.
9 * The GnuTLS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 3 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>
24 /* This file contains function that will override the
25 * default berkeley sockets API per session.
28 #include <gnutls_int.h>
29 #include <gnutls_errors.h>
30 #include <gnutls_num.h>
31 #include <gnutls_record.h>
32 #include <gnutls_buffers.h>
33 #include <gnutls_mbuffers.h>
34 #include <gnutls_state.h>
35 #include <gnutls_dtls.h>
44 * gnutls_transport_set_errno:
45 * @session: is a #gnutls_session_t structure.
46 * @err: error value to store in session-specific errno variable.
48 * Store @err in the session-specific errno variable. Useful values
49 * for @err is EAGAIN and EINTR, other values are treated will be
50 * treated as real errors in the push/pull function.
52 * This function is useful in replacement push and pull functions set by
53 * gnutls_transport_set_push_function() and
54 * gnutls_transport_set_pull_function() under Windows, where the
55 * replacements may not have access to the same @errno
56 * variable that is used by GnuTLS (e.g., the application is linked to
57 * msvcr71.dll and gnutls is linked to msvcrt.dll).
61 gnutls_transport_set_errno (gnutls_session_t session
, int err
)
63 session
->internals
.errnum
= err
;
67 * gnutls_transport_set_pull_function:
68 * @session: is a #gnutls_session_t structure.
69 * @pull_func: a callback function similar to read()
71 * This is the function where you set a function for gnutls to receive
72 * data. Normally, if you use berkeley style sockets, do not need to
73 * use this function since the default recv(2) will probably be ok.
74 * The callback should return 0 on connection termination, a positive
75 * number indicating the number of bytes received, and -1 on error.
77 * @gnutls_pull_func is of the form,
78 * ssize_t (*gnutls_pull_func)(gnutls_transport_ptr_t, void*, size_t);
81 gnutls_transport_set_pull_function (gnutls_session_t session
,
82 gnutls_pull_func pull_func
)
84 session
->internals
.pull_func
= pull_func
;
88 * gnutls_transport_set_pull_timeout_function:
89 * @session: is a #gnutls_session_t structure.
90 * @func: a callback function
92 * This is the function where you set a function for gnutls to know
93 * whether data are ready to be received. It should wait for data a
94 * given time frame in milliseconds. The callback should return 0 on
95 * timeout, a positive number if data can be received, and -1 on error.
96 * You'll need to override this function if select() is not suitable
97 * for the provided transport calls.
98 * The callback function is used in DTLS only.
100 * @gnutls_pull_timeout_func is of the form,
101 * ssize_t (*gnutls_pull_timeout_func)(gnutls_transport_ptr_t, unsigned int ms);
106 gnutls_transport_set_pull_timeout_function (gnutls_session_t session
,
107 gnutls_pull_timeout_func func
)
109 session
->internals
.pull_timeout_func
= func
;
113 * gnutls_transport_set_push_function:
114 * @session: is a #gnutls_session_t structure.
115 * @push_func: a callback function similar to write()
117 * This is the function where you set a push function for gnutls to
118 * use in order to send data. If you are going to use berkeley style
119 * sockets, you do not need to use this function since the default
120 * send(2) will probably be ok. Otherwise you should specify this
121 * function for gnutls to be able to send data.
122 * The callback should return a positive number indicating the
123 * bytes sent, and -1 on error.
125 * @push_func is of the form,
126 * ssize_t (*gnutls_push_func)(gnutls_transport_ptr_t, const void*, size_t);
130 gnutls_transport_set_push_function (gnutls_session_t session
,
131 gnutls_push_func push_func
)
133 session
->internals
.push_func
= push_func
;
134 session
->internals
.vec_push_func
= NULL
;
138 * gnutls_transport_set_vec_push_function:
139 * @session: is a #gnutls_session_t structure.
140 * @vec_func: a callback function similar to writev()
142 * Using this function you can override the default writev(2)
143 * function for gnutls to send data. Setting this callback
144 * instead of gnutls_transport_set_push_function() is recommended
145 * since it introduces less overhead in the TLS handshake process.
147 * @vec_func is of the form,
148 * ssize_t (*gnutls_vec_push_func) (gnutls_transport_ptr_t, const giovec_t * iov, int iovcnt);
153 gnutls_transport_set_vec_push_function (gnutls_session_t session
,
154 gnutls_vec_push_func vec_func
)
156 session
->internals
.push_func
= NULL
;
157 session
->internals
.vec_push_func
= vec_func
;
161 * gnutls_transport_set_errno_function:
162 * @session: is a #gnutls_session_t structure.
163 * @errno_func: a callback function similar to write()
165 * This is the function where you set a function to retrieve errno
166 * after a failed push or pull operation.
168 * @errno_func is of the form,
169 * int (*gnutls_errno_func)(gnutls_transport_ptr_t);
170 * and should return the errno.
175 gnutls_transport_set_errno_function (gnutls_session_t session
,
176 gnutls_errno_func errno_func
)
178 session
->internals
.errno_func
= errno_func
;