GNU libmicrohttpd 0.9.77
Loading...
Searching...
No Matches
init.c
Go to the documentation of this file.
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
25#include "internal.h"
26#include "init.h"
27
28
29#ifndef _AUTOINIT_FUNCS_ARE_SUPPORTED
33volatile unsigned int global_init_count = 0;
34
35#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
39MHD_MUTEX_STATIC_DEFN_INIT_ (global_init_mutex_);
40#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
41
42#endif
43
44#if defined(_WIN32) && ! defined(__CYGWIN__)
48static int mhd_winsock_inited_ = 0;
49#endif
50
60static void
61mhd_panic_std (void *cls,
62 const char *file,
63 unsigned int line,
64 const char *reason)
65{
66 (void) cls; /* Mute compiler warning. */
67#ifdef HAVE_MESSAGES
68 fprintf (stderr,
69 _ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
70 file,
71 line,
72 reason);
73#else /* ! HAVE_MESSAGES */
74 (void) file; /* Mute compiler warning. */
75 (void) line; /* Mute compiler warning. */
76 (void) reason; /* Mute compiler warning. */
77#endif
78 abort ();
79}
80
81
85void
87{
88#if defined(_WIN32) && ! defined(__CYGWIN__)
89 WSADATA wsd;
90#endif /* _WIN32 && ! __CYGWIN__ */
91
92 if (NULL == mhd_panic)
94
95#if defined(_WIN32) && ! defined(__CYGWIN__)
96 if (0 != WSAStartup (MAKEWORD (2, 2),
97 &wsd))
98 MHD_PANIC (_ ("Failed to initialize winsock.\n"));
99 mhd_winsock_inited_ = 1;
100 if ( (2 != LOBYTE (wsd.wVersion)) &&
101 (2 != HIBYTE (wsd.wVersion)) )
102 MHD_PANIC (_ ("Winsock version 2.2 is not available.\n"));
103#endif
105#ifdef HAVE_FREEBSD_SENDFILE
106 MHD_conn_init_static_ ();
107#endif /* HAVE_FREEBSD_SENDFILE */
108}
109
110
114void
116{
117#if defined(_WIN32) && ! defined(__CYGWIN__)
118 if (mhd_winsock_inited_)
119 WSACleanup ();
120#endif
122}
123
124
125#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
126
128
129#else
130
135void
137{
138#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
139 MHD_mutex_lock_chk_ (&global_init_mutex_);
140#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
141 if (0 == global_init_count++)
142 MHD_init ();
143#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
144 MHD_mutex_unlock_chk_ (&global_init_mutex_);
145#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
146}
147
148
149#endif
#define _SET_INIT_AND_DEINIT_FUNCS(FI, FD)
void MHD_fini(void)
Definition init.c:115
void MHD_check_global_init_(void)
Definition init.c:136
void MHD_init(void)
Definition init.c:86
volatile unsigned int global_init_count
Definition init.c:33
static void mhd_panic_std(void *cls, const char *file, unsigned int line, const char *reason)
Definition init.c:61
functions to initialize library
MHD_PanicCallback mhd_panic
Definition panic.c:31
#define MHD_PANIC(msg)
Definition internal.h:69
#define MHD_mutex_unlock_chk_(pmutex)
Definition mhd_locks.h:180
#define MHD_mutex_lock_chk_(pmutex)
Definition mhd_locks.h:154
void MHD_monotonic_sec_counter_finish(void)
void MHD_monotonic_sec_counter_init(void)
#define NULL
#define _(String)
Definition mhd_options.h:42
MHD internal shared structures.