]> granicus.if.org Git - apache/blob - server/mpm/winnt/mpm_winnt.h
Externalize the functions to manage the mpm's queue of completion_contexts.
[apache] / server / mpm / winnt / mpm_winnt.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #ifndef APACHE_MPM_WINNT_H
60 #define APACHE_MPM_WINNT_H
61
62 #include "ap_listen.h"
63
64 /* From registry.c: */
65
66 apr_status_t ap_registry_create_key(const char *key);
67 apr_status_t ap_registry_delete_key(const char *key);
68
69 apr_status_t ap_registry_store_value(const char *key, const char *name, 
70                                     const char *value);
71 apr_status_t ap_registry_get_value(apr_pool_t *p, const char *key, 
72                                   const char *name, char **ppValue);
73 apr_status_t ap_registry_store_array(apr_pool_t *p, const char *key, 
74                                     const char *name, int nelts, 
75                                     char const* const* elts);
76 apr_status_t ap_registry_get_array(apr_pool_t *p, const char *key, 
77                                   const char *name, 
78                                   apr_array_header_t **parray);
79 apr_status_t ap_registry_delete_value(const char *key, const char *name);
80
81
82 /* From service.c: */
83
84 #define SERVICE_APACHE_RESTART 128
85
86 #ifndef AP_DEFAULT_SERVICE_NAME
87 #define AP_DEFAULT_SERVICE_NAME "Apache2"
88 #endif
89
90 #define SERVICECONFIG9X "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices"
91 #define SERVICECONFIG "System\\CurrentControlSet\\Services\\%s"
92 #define SERVICEPARAMS "System\\CurrentControlSet\\Services\\%s\\Parameters"
93
94 apr_status_t mpm_service_set_name(apr_pool_t *p, const char **display_name, 
95                                                  const char *set_name);
96 apr_status_t mpm_merge_service_args(apr_pool_t *p, apr_array_header_t *args, 
97                                    int fixed_args);
98
99 apr_status_t mpm_service_to_start(const char **display_name);
100 apr_status_t mpm_service_started(void);
101 apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, 
102                                 char const* const* argv);
103 apr_status_t mpm_service_uninstall(void);
104
105 apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, 
106                               char const* const* argv);
107
108 void mpm_signal_service(apr_pool_t *ptemp, int signal);
109
110 void mpm_service_stopping(void);
111
112 void mpm_start_console_handler(void);
113 void mpm_start_child_console_handler(void);
114
115 /* From winnt.c: */
116
117 extern OSVERSIONINFO osver;
118 extern void clean_child_exit(int);
119
120 void setup_signal_names(char *prefix);
121
122 typedef enum {
123     SIGNAL_PARENT_SHUTDOWN,
124     SIGNAL_PARENT_RESTART,
125     SIGNAL_PARENT_RESTART_GRACEFUL
126 } ap_signal_parent_e;
127 AP_DECLARE(void) ap_signal_parent(ap_signal_parent_e type);
128
129 /* This code is stolen from the apr_private.h and misc/win32/misc.c
130  * Please see those sources for detailed documentation.
131  */
132 typedef enum {
133     DLL_WINBASEAPI = 0,    // kernel32 From WinBase.h
134     DLL_WINADVAPI = 1,     // advapi32 From WinBase.h
135     DLL_WINSOCKAPI = 2,    // mswsock  From WinSock.h
136     DLL_WINSOCK2API = 3,   // ws2_32   From WinSock2.h
137     DLL_defined = 4        // must define as last idx_ + 1
138 } ap_dlltoken_e;
139
140 FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char *fnName, int ordinal);
141
142 #define AP_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
143     typedef rettype (calltype *ap_winapi_fpt_##fn) args; \
144     static ap_winapi_fpt_##fn ap_winapi_pfn_##fn = NULL; \
145     __inline rettype ap_winapi_##fn args \
146     {   if (!ap_winapi_pfn_##fn) \
147             ap_winapi_pfn_##fn = (ap_winapi_fpt_##fn) ap_load_dll_func(lib, #fn, ord); \
148         return (*(ap_winapi_pfn_##fn)) names; }; \
149
150 /* WinNT kernel only */
151 AP_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
152     IN HANDLE hFile),
153     (hFile));
154 #define CancelIo ap_winapi_CancelIo
155
156 /* Win9x kernel only */
157 AP_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, DWORD, WINAPI, RegisterServiceProcess, 0, (
158     DWORD dwProcessId,
159     DWORD dwType),
160     (dwProcessId, dwType));
161 #define RegisterServiceProcess ap_winapi_RegisterServiceProcess
162
163 /*
164  * The Windoes MPM uses a queue of completion contexts that it passes
165  * between the accept threads and the worker threads. Declare the
166  * functions to access the queue and the structures passed on the
167  * queue in the header file to enable modules to access them
168  * if necessary. The queue resides in the MPM.
169  */
170 #ifdef CONTAINING_RECORD
171 #undef CONTAINING_RECORD
172 #endif
173 #define CONTAINING_RECORD(address, type, field) ((type *)( \
174                                                   (PCHAR)(address) - \
175                                                   (PCHAR)(&((type *)0)->field)))
176 #define PADDED_ADDR_SIZE sizeof(SOCKADDR_IN)+16
177 typedef struct CompContext {
178     struct CompContext *next;
179     OVERLAPPED Overlapped;
180     apr_socket_t *sock;
181     SOCKET accept_socket;
182     char buff[2*PADDED_ADDR_SIZE];
183     struct sockaddr *sa_server;
184     int sa_server_len;
185     struct sockaddr *sa_client;
186     int sa_client_len;
187     apr_pool_t *ptrans;
188 } COMP_CONTEXT, *PCOMP_CONTEXT;
189
190 typedef enum {
191     IOCP_CONNECTION_ACCEPTED = 1,
192     IOCP_WAIT_FOR_RECEIVE = 2,
193     IOCP_WAIT_FOR_TRANSMITFILE = 3,
194     IOCP_SHUTDOWN = 4
195 } io_state_e;
196
197 AP_DECLARE(PCOMP_CONTEXT) mpm_get_completion_context(void);
198 AP_DECLARE(void)          mpm_recycle_completion_context(PCOMP_CONTEXT pCompContext);
199 AP_DECLARE(apr_status_t)  mpm_post_completion_context(PCOMP_CONTEXT pCompContext, io_state_e state);
200 #endif /* APACHE_MPM_WINNT_H */