GNU libmicrohttpd  0.9.62
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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
30 
33 volatile unsigned int global_init_count = 0;
34 
35 #ifdef MHD_MUTEX_STATIC_DEFN_INIT_
36 
39 MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_);
40 #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
41 
42 #endif
43 
44 #if defined(_WIN32) && ! defined(__CYGWIN__)
45 
48 static int mhd_winsock_inited_ = 0;
49 #endif
50 
60 static void
61 mhd_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 
85 void
86 MHD_init (void)
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 
114 void
115 MHD_fini (void)
116 {
117 #if defined(_WIN32) && ! defined(__CYGWIN__)
118  if (mhd_winsock_inited_)
119  WSACleanup();
120 #endif
122 }
123 
124 #ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
125 
127 
128 #else
129 
134 void
136 {
137 #ifdef MHD_MUTEX_STATIC_DEFN_INIT_
138  MHD_mutex_lock_chk_(&global_init_mutex_);
139 #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
140  if (0 == global_init_count++)
141  MHD_init ();
142 #ifdef MHD_MUTEX_STATIC_DEFN_INIT_
143  MHD_mutex_unlock_chk_(&global_init_mutex_);
144 #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
145 }
146 #endif
static void mhd_panic_std(void *cls, const char *file, unsigned int line, const char *reason)
Definition: init.c:61
#define MHD_PANIC(msg)
Definition: internal.h:68
functions to initialize library
#define MHD_mutex_unlock_chk_(pmutex)
Definition: mhd_locks.h:177
MHD_PanicCallback mhd_panic
Definition: panic.c:31
void MHD_check_global_init_(void)
Definition: init.c:135
void MHD_fini(void)
Definition: init.c:115
internal shared structures
volatile unsigned int global_init_count
Definition: init.c:33
#define NULL
Definition: reason_phrase.c:30
void MHD_monotonic_sec_counter_finish(void)
#define _SET_INIT_AND_DEINIT_FUNCS(FI, FD)
void MHD_monotonic_sec_counter_init(void)
#define MHD_mutex_lock_chk_(pmutex)
Definition: mhd_locks.h:151
#define _(String)
Definition: mhd_options.h:42
void MHD_init(void)
Definition: init.c:86