18
18
#include "Http.h"
19
19
#include "Connection.h"
20
20
21
- #ifdef HAVE_INOTIFY
22
- #include <dirent.h>
23
- #include <sys/inotify.h>
24
- #endif
25
-
26
21
#if SW_REACTOR_SCHEDULE == 3
27
22
static sw_inline void swServer_reactor_schedule (swServer * serv )
28
23
{
@@ -45,13 +40,6 @@ static void swServer_signal_hanlder(int sig);
45
40
static int swServer_start_proxy (swServer * serv );
46
41
static void swServer_disable_accept (swReactor * reactor );
47
42
48
- #ifdef HAVE_INOTIFY
49
- static swHashMap * watch_file_map = NULL ;
50
- static int swServer_master_onFileChange (swReactor * reactor , swEvent * event );
51
- static int swServer_master_add_watch (int ifd , char * dirname );
52
- static void swServer_master_check_reload_time ();
53
- #endif
54
-
55
43
static void swHeartbeatThread_loop (swThreadParam * param );
56
44
static int swServer_send1 (swServer * serv , swSendData * resp );
57
45
static int swServer_send2 (swServer * serv , swSendData * resp );
@@ -97,149 +85,6 @@ void swServer_enable_accept(swReactor *reactor)
97
85
}
98
86
}
99
87
100
- #ifdef HAVE_INOTIFY
101
- int swServer_watch_file (swServer * serv , swReactor * reactor )
102
- {
103
- #ifdef HAVE_INOTIFY_INIT1
104
- int ifd = inotify_init1 (IN_NONBLOCK | IN_CLOEXEC );
105
- #else
106
- int ifd = inotify_init ();
107
- #endif
108
- if (ifd < 0 )
109
- {
110
- swSysError ("inotify_init() failed." );
111
- return SW_ERR ;
112
- }
113
- #ifndef HAVE_INOTIFY_INIT1
114
- swSetNonBlock (ifd );
115
- #endif
116
- if (ifd < 0 )
117
- {
118
- return SW_ERR ;
119
- }
120
- if (swServer_master_add_watch (ifd , serv -> watch_path ) < 0 )
121
- {
122
- return SW_ERR ;
123
- }
124
-
125
- reactor -> setHandle (reactor , SW_FD_INOTIFY , swServer_master_onFileChange );
126
- reactor -> atLoopEnd (reactor , swServer_master_check_reload_time );
127
-
128
- return reactor -> add (reactor , ifd , SW_FD_INOTIFY | SW_EVENT_READ );
129
- }
130
-
131
- static void swServer_master_check_reload_time ()
132
- {
133
- swServer * serv = SwooleG .serv ;
134
- if (serv -> reload_time > 0 && SwooleGS -> now > serv -> reload_time )
135
- {
136
- swKill (SwooleGS -> manager_pid , SIGUSR1 );
137
- serv -> reload_time = 0 ;
138
- }
139
- }
140
-
141
- static int swServer_master_add_watch (int ifd , char * dirname )
142
- {
143
- char subdir [512 ];
144
- struct dirent * child_dir ;
145
-
146
- DIR * odir = opendir (dirname );
147
- if (odir == NULL )
148
- {
149
- swSysError ("opendir(%s) failed." , dirname );
150
- return SW_ERR ;
151
- }
152
-
153
- int mask = IN_MODIFY | IN_MOVED_FROM | IN_CREATE | IN_DELETE | IN_ISDIR ;
154
-
155
- int watch_fd = inotify_add_watch (ifd , dirname , mask );
156
- if (watch_fd < 0 )
157
- {
158
- swSysError ("inotify_add_watch(%s) failed." , dirname );
159
- return SW_ERR ;
160
- }
161
-
162
- if (watch_file_map == NULL )
163
- {
164
- watch_file_map = swHashMap_new (16 , NULL );
165
- }
166
- swHashMap_add_int (watch_file_map , watch_fd , strdup (dirname ), NULL );
167
-
168
- errno = 0 ;
169
- while ((child_dir = readdir (odir )) != NULL )
170
- {
171
- if (strcmp (child_dir -> d_name , "." ) == 0 || strcmp (child_dir -> d_name , ".." ) == 0 )
172
- {
173
- continue ;
174
- }
175
- if (child_dir -> d_type == DT_DIR )
176
- {
177
- sprintf (subdir , "%s/%s" , dirname , child_dir -> d_name );
178
- swServer_master_add_watch (ifd , subdir );
179
- }
180
- }
181
-
182
- if (errno != 0 )
183
- {
184
- swSysError ("readdir(%s) failed." , dirname );
185
- }
186
-
187
- closedir (odir );
188
- return watch_fd ;
189
- }
190
-
191
- /**
192
- * Application file is changed.
193
- */
194
- static int swServer_master_onFileChange (swReactor * reactor , swEvent * event )
195
- {
196
- swServer * serv = SwooleG .serv ;
197
- char name [1024 ];
198
- struct inotify_event * ievent ;
199
- char buf [sizeof (struct inotify_event ) * 128 ];
200
- int n , i ;
201
- int ifd = event -> fd ;
202
-
203
- while (1 )
204
- {
205
- n = read (ifd , buf , sizeof (buf ));
206
- if (n <= 0 )
207
- {
208
- break ;
209
- }
210
-
211
- for (i = 0 ; i < n ; i += sizeof (struct inotify_event ) + ievent -> len )
212
- {
213
- ievent = (struct inotify_event * ) & buf [i ];
214
- if (ievent -> mask & IN_ISDIR )
215
- {
216
- if (ievent -> mask & IN_CREATE )
217
- {
218
- char * parent_dir_name = swHashMap_find_int (watch_file_map , ievent -> wd );
219
- snprintf (name , sizeof (name ), "%s/%s" , parent_dir_name , ievent -> name );
220
- swServer_master_add_watch (ifd , name );
221
- }
222
- else
223
- {
224
- inotify_rm_watch (ifd , ievent -> wd );
225
- }
226
- }
227
- else
228
- {
229
- if (ievent -> len > (sizeof (SW_RELOAD_FILE_EXTNAME ) - 1 )
230
- && strcasecmp (ievent -> name + strlen (ievent -> name ) - (sizeof (SW_RELOAD_FILE_EXTNAME ) - 1 ),
231
- SW_RELOAD_FILE_EXTNAME ) == 0 )
232
- {
233
- serv -> reload_time = SwooleGS -> now + SW_RELOAD_AFTER_SECONDS_N ;
234
- swNotice ("Program files is changed, Server will reload after %d seconds." , SW_RELOAD_AFTER_SECONDS_N );
235
- }
236
- }
237
- }
238
- }
239
- return SW_OK ;
240
- }
241
- #endif
242
-
243
88
int swServer_master_onAccept (swReactor * reactor , swEvent * event )
244
89
{
245
90
swServer * serv = reactor -> ptr ;
@@ -526,16 +371,6 @@ static int swServer_start_proxy(swServer *serv)
526
371
main_reactor -> ptr = serv ;
527
372
main_reactor -> setHandle (main_reactor , SW_FD_LISTEN , swServer_master_onAccept );
528
373
529
- #ifdef HAVE_INOTIFY
530
- /**
531
- * inotify, watch the application file update.
532
- */
533
- if (serv -> watch_path )
534
- {
535
- swServer_watch_file (serv , main_reactor );
536
- }
537
- #endif
538
-
539
374
if (serv -> onStart != NULL )
540
375
{
541
376
serv -> onStart (serv );
0 commit comments