documented fix
[gnutls.git] / lib / system_override.c
blobdf8c094197b8c6a8267858c60633f3ef958d10f3
1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 /* This file contains function that will override the
24 * default berkeley sockets API per session.
27 #include <gnutls_int.h>
28 #include <gnutls_errors.h>
29 #include <gnutls_num.h>
30 #include <gnutls_record.h>
31 #include <gnutls_buffers.h>
32 #include <gnutls_mbuffers.h>
33 #include <gnutls_state.h>
34 #include <gnutls_dtls.h>
35 #include <system.h>
37 #include <errno.h>
38 #ifdef _WIN32
39 # include <windows.h>
40 #endif
42 /**
43 * gnutls_transport_set_errno:
44 * @session: is a #gnutls_session_t structure.
45 * @err: error value to store in session-specific errno variable.
47 * Store @err in the session-specific errno variable. Useful values
48 * for @err is EAGAIN and EINTR, other values are treated will be
49 * treated as real errors in the push/pull function.
51 * This function is useful in replacement push and pull functions set by
52 * gnutls_transport_set_push_function() and
53 * gnutls_transport_set_pull_function() under Windows, where the
54 * replacements may not have access to the same @errno
55 * variable that is used by GnuTLS (e.g., the application is linked to
56 * msvcr71.dll and gnutls is linked to msvcrt.dll).
58 **/
59 void
60 gnutls_transport_set_errno (gnutls_session_t session, int err)
62 session->internals.errnum = err;
65 /**
66 * gnutls_transport_set_pull_function:
67 * @session: is a #gnutls_session_t structure.
68 * @pull_func: a callback function similar to read()
70 * This is the function where you set a function for gnutls to receive
71 * data. Normally, if you use berkeley style sockets, do not need to
72 * use this function since the default recv(2) will probably be ok.
73 * The callback should return 0 on connection termination, a positive
74 * number indicating the number of bytes received, and -1 on error.
76 * @gnutls_pull_func is of the form,
77 * ssize_t (*gnutls_pull_func)(gnutls_transport_ptr_t, void*, size_t);
78 **/
79 void
80 gnutls_transport_set_pull_function (gnutls_session_t session,
81 gnutls_pull_func pull_func)
83 session->internals.pull_func = pull_func;
86 /**
87 * gnutls_transport_set_pull_timeout_function:
88 * @session: is a #gnutls_session_t structure.
89 * @func: a callback function
91 * This is the function where you set a function for gnutls to know
92 * whether data are ready to be received. It should wait for data a
93 * given time frame in milliseconds. The callback should return 0 on
94 * timeout, a positive number if data can be received, and -1 on error.
95 * You'll need to override this function if select() is not suitable
96 * for the provided transport calls.
97 * The callback function is used in DTLS only.
99 * @gnutls_pull_timeout_func is of the form,
100 * ssize_t (*gnutls_pull_timeout_func)(gnutls_transport_ptr_t, unsigned int ms);
102 * Since: 3.0
104 void
105 gnutls_transport_set_pull_timeout_function (gnutls_session_t session,
106 gnutls_pull_timeout_func func)
108 session->internals.pull_timeout_func = func;
112 * gnutls_transport_set_push_function:
113 * @session: is a #gnutls_session_t structure.
114 * @push_func: a callback function similar to write()
116 * This is the function where you set a push function for gnutls to
117 * use in order to send data. If you are going to use berkeley style
118 * sockets, you do not need to use this function since the default
119 * send(2) will probably be ok. Otherwise you should specify this
120 * function for gnutls to be able to send data.
121 * The callback should return a positive number indicating the
122 * bytes sent, and -1 on error.
124 * @push_func is of the form,
125 * ssize_t (*gnutls_push_func)(gnutls_transport_ptr_t, const void*, size_t);
128 void
129 gnutls_transport_set_push_function (gnutls_session_t session,
130 gnutls_push_func push_func)
132 session->internals.push_func = push_func;
133 session->internals.vec_push_func = NULL;
137 * gnutls_transport_set_vec_push_function:
138 * @session: is a #gnutls_session_t structure.
139 * @vec_func: a callback function similar to writev()
141 * Using this function you can override the default writev(2)
142 * function for gnutls to send data. Setting this callback
143 * instead of gnutls_transport_set_push_function() is recommended
144 * since it introduces less overhead in the TLS handshake process.
146 * @vec_func is of the form,
147 * ssize_t (*gnutls_vec_push_func) (gnutls_transport_ptr_t, const giovec_t * iov, int iovcnt);
149 * Since: 2.12.0
151 void
152 gnutls_transport_set_vec_push_function (gnutls_session_t session,
153 gnutls_vec_push_func vec_func)
155 session->internals.push_func = NULL;
156 session->internals.vec_push_func = vec_func;
160 * gnutls_transport_set_errno_function:
161 * @session: is a #gnutls_session_t structure.
162 * @errno_func: a callback function similar to write()
164 * This is the function where you set a function to retrieve errno
165 * after a failed push or pull operation.
167 * @errno_func is of the form,
168 * int (*gnutls_errno_func)(gnutls_transport_ptr_t);
169 * and should return the errno.
171 * Since: 2.12.0
173 void
174 gnutls_transport_set_errno_function (gnutls_session_t session,
175 gnutls_errno_func errno_func)
177 session->internals.errno_func = errno_func;