aboutsummaryrefslogtreecommitdiff
path: root/src/include/w32functions.h
blob: 508778c954244784bacb350411c49581d9d12178 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
  This file is part of libmicrohttpd
  Copyright (C) 2014 Karlson2k (Evgeny Grin)

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library.
  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file include/w32functions.h
 * @brief  internal functions for W32 systems
 * @author Karlson2k (Evgeny Grin)
 */

#ifndef MHD_W32FUNCTIONS_H
#define MHD_W32FUNCTIONS_H
#ifndef _WIN32
#error w32functions.h is designed only for W32 systems
#endif

#include "platform.h"
#include <errno.h>
#include <winsock2.h>
#include "platform_interface.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define MHDW32ERRBASE 3300

#ifndef EWOULDBLOCK
#define EWOULDBLOCK (MHDW32ERRBASE+1)
#endif
#ifndef EINPROGRESS
#define EINPROGRESS (MHDW32ERRBASE+2)
#endif
#ifndef EALREADY
#define EALREADY (MHDW32ERRBASE+3)
#endif
#ifndef ENOTSOCK
#define ENOTSOCK (MHDW32ERRBASE+4)
#endif
#ifndef EDESTADDRREQ
#define EDESTADDRREQ (MHDW32ERRBASE+5)
#endif
#ifndef EMSGSIZE
#define EMSGSIZE (MHDW32ERRBASE+6)
#endif
#ifndef EPROTOTYPE
#define EPROTOTYPE (MHDW32ERRBASE+7)
#endif
#ifndef ENOPROTOOPT
#define ENOPROTOOPT (MHDW32ERRBASE+8)
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT (MHDW32ERRBASE+9)
#endif
#ifndef EOPNOTSUPP
#define EOPNOTSUPP (MHDW32ERRBASE+10)
#endif
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT (MHDW32ERRBASE+11)
#endif
#ifndef EADDRINUSE
#define EADDRINUSE (MHDW32ERRBASE+12)
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL (MHDW32ERRBASE+13)
#endif
#ifndef ENETDOWN
#define ENETDOWN (MHDW32ERRBASE+14)
#endif
#ifndef ENETUNREACH
#define ENETUNREACH (MHDW32ERRBASE+15)
#endif
#ifndef ENETRESET
#define ENETRESET (MHDW32ERRBASE+16)
#endif
#ifndef ECONNABORTED
#define ECONNABORTED (MHDW32ERRBASE+17)
#endif
#ifndef ECONNRESET
#define ECONNRESET (MHDW32ERRBASE+18)
#endif
#ifndef ENOBUFS
#define ENOBUFS (MHDW32ERRBASE+19)
#endif
#ifndef EISCONN
#define EISCONN (MHDW32ERRBASE+20)
#endif
#ifndef ENOTCONN
#define ENOTCONN (MHDW32ERRBASE+21)
#endif
#ifndef ETOOMANYREFS
#define ETOOMANYREFS (MHDW32ERRBASE+22)
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED (MHDW32ERRBASE+23)
#endif
#ifndef ELOOP
#define ELOOP (MHDW32ERRBASE+24)
#endif
#ifndef EHOSTDOWN
#define EHOSTDOWN (MHDW32ERRBASE+25)
#endif
#ifndef EHOSTUNREACH
#define EHOSTUNREACH (MHDW32ERRBASE+26)
#endif
#ifndef EPROCLIM
#define EPROCLIM (MHDW32ERRBASE+27)
#endif
#ifndef EUSERS
#define EUSERS (MHDW32ERRBASE+28)
#endif
#ifndef EDQUOT
#define EDQUOT (MHDW32ERRBASE+29)
#endif
#ifndef ESTALE
#define ESTALE (MHDW32ERRBASE+30)
#endif
#ifndef EREMOTE
#define EREMOTE (MHDW32ERRBASE+31)
#endif
#ifndef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT (MHDW32ERRBASE+32)
#endif
#ifndef EPFNOSUPPORT
#define EPFNOSUPPORT (MHDW32ERRBASE+33)
#endif
#ifndef ESHUTDOWN
#define ESHUTDOWN (MHDW32ERRBASE+34)
#endif
#ifndef ENODATA
#define ENODATA (MHDW32ERRBASE+35)
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT (MHDW32ERRBASE+36)
#endif

/**
 * Return errno equivalent of last winsock error
 * @return errno equivalent of last winsock error
 */
int MHD_W32_errno_from_winsock_(void);

/**
 * Return pointer to string description of errnum error
 * Works fine with both standard errno errnums
 * and errnums from MHD_W32_errno_from_winsock_
 * @param errnum the errno or value from MHD_W32_errno_from_winsock_()
 * @return pointer to string description of error
 */
const char* MHD_W32_strerror_(int errnum);

/**
 * Return pointer to string description of last winsock error
 * @return pointer to string description of last winsock error
 */
const char* MHD_W32_strerror_last_winsock_(void);

/**
 * Set last winsock error to equivalent of given errno value
 * @param errnum the errno value to set
 */
void MHD_W32_set_last_winsock_error_(int errnum);

/**
 * Create pair of mutually connected TCP/IP sockets on loopback address
 * @param sockets_pair array to receive resulted sockets
 * @return zero on success, -1 otherwise
 */
int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]);

/**
 * Generate 31-bit pseudo random number.
 * Function initialize itself at first call to current time.
 * @return 31-bit pseudo random number.
 */
int MHD_W32_random_(void);

/* Emulate snprintf function on W32 */
int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...);

#ifdef __cplusplus
}
#endif
#endif /* MHD_W32FUNCTIONS_H */