@@ -114,10 +114,9 @@ static int ekuiper_plugin_uninit(neu_plugin_t *plugin)
114
114
return rv ;
115
115
}
116
116
117
- static int ekuiper_plugin_start (neu_plugin_t * plugin )
117
+ static inline int start (neu_plugin_t * plugin , const char * url )
118
118
{
119
- int rv = 0 ;
120
- char * url = plugin -> url ? plugin -> url : EKUIPER_PLUGIN_URL ; // default url
119
+ int rv = 0 ;
121
120
122
121
rv = nng_pair0_open (& plugin -> sock );
123
122
if (rv != 0 ) {
@@ -143,16 +142,43 @@ static int ekuiper_plugin_start(neu_plugin_t *plugin)
143
142
return rv ;
144
143
}
145
144
145
+ nng_mtx_lock (plugin -> mtx );
146
+ while (plugin -> receiving ) {
147
+ nng_mtx_unlock (plugin -> mtx );
148
+ nng_msleep (10 );
149
+ nng_mtx_lock (plugin -> mtx );
150
+ }
151
+ plugin -> receiving = true;
146
152
nng_recv_aio (plugin -> sock , plugin -> recv_aio );
153
+ nng_mtx_unlock (plugin -> mtx );
154
+
155
+ return NEU_ERR_SUCCESS ;
156
+ }
157
+
158
+ static int ekuiper_plugin_start (neu_plugin_t * plugin )
159
+ {
160
+ int rv = 0 ;
161
+ char * url = plugin -> url ? plugin -> url : EKUIPER_PLUGIN_URL ; // default url
162
+
163
+ rv = start (plugin , url );
164
+ if (rv != 0 ) {
165
+ return rv ;
166
+ }
167
+
147
168
plugin -> started = true;
148
169
plog_notice (plugin , "start successfully" );
149
170
150
171
return NEU_ERR_SUCCESS ;
151
172
}
152
173
153
- static int ekuiper_plugin_stop (neu_plugin_t * plugin )
174
+ static inline void stop (neu_plugin_t * plugin )
154
175
{
155
176
nng_close (plugin -> sock );
177
+ }
178
+
179
+ static int ekuiper_plugin_stop (neu_plugin_t * plugin )
180
+ {
181
+ stop (plugin );
156
182
plugin -> started = false;
157
183
plog_notice (plugin , "stop successfully" );
158
184
return NEU_ERR_SUCCESS ;
@@ -201,41 +227,6 @@ static int parse_config(neu_plugin_t *plugin, const char *setting,
201
227
return -1 ;
202
228
}
203
229
204
- static inline int check_url_listenable (neu_plugin_t * plugin , const char * url ,
205
- const char * host , uint16_t port )
206
- {
207
- if (NULL != plugin -> host && // already configured and
208
- port == plugin -> port && // port is the same, then if
209
- (0 == strcmp (plugin -> host , host ) // 1. host is the same
210
- || 0 == strcmp ("0.0.0.0" , host ) // 2. to bind to any address
211
- || 0 == strcmp ("0.0.0.0" , plugin -> host ) // 3. bound to any address
212
- )) {
213
- // early return, no need check url is listenable
214
- return 0 ;
215
- }
216
-
217
- nng_socket sock = NNG_SOCKET_INITIALIZER ;
218
- int rv = nng_pair0_open (& sock );
219
- if (0 != rv ) {
220
- plog_error (plugin , "nng_pair0_open: %s" , nng_strerror (rv ));
221
- return NEU_ERR_EINTERNAL ;
222
- }
223
-
224
- if (0 != (rv = nng_listen (sock , url , NULL , 0 ))) {
225
- plog_error (plugin , "nng_listen: %s" , nng_strerror (rv ));
226
- if (NNG_EADDRINVAL == rv ) {
227
- rv = NEU_ERR_IP_ADDRESS_INVALID ;
228
- } else if (NNG_EADDRINUSE == rv ) {
229
- rv = NEU_ERR_IP_ADDRESS_IN_USE ;
230
- } else {
231
- rv = NEU_ERR_EINTERNAL ;
232
- }
233
- }
234
-
235
- nng_close (sock );
236
- return rv ;
237
- }
238
-
239
230
static int ekuiper_plugin_config (neu_plugin_t * plugin , const char * setting )
240
231
{
241
232
int rv = 0 ;
@@ -255,23 +246,31 @@ static int ekuiper_plugin_config(neu_plugin_t *plugin, const char *setting)
255
246
goto error ;
256
247
}
257
248
258
- if (0 != (rv = check_url_listenable (plugin , url , host , port ))) {
249
+ if (plugin -> started ) {
250
+ stop (plugin );
251
+ }
252
+
253
+ // check we could start the plugin with the new setting
254
+ if (0 != (rv = start (plugin , url ))) {
255
+ // recover with old setting
256
+ if (plugin -> started && 0 != start (plugin , plugin -> url )) {
257
+ plog_warn (plugin , "restart host:%s port:%" PRIu16 " fail" ,
258
+ plugin -> host , plugin -> port );
259
+ }
259
260
goto error ;
260
261
}
261
262
263
+ if (!plugin -> started ) {
264
+ stop (plugin );
265
+ }
266
+
262
267
plog_notice (plugin , "config success" );
263
268
264
269
free (plugin -> host );
270
+ free (plugin -> url );
265
271
plugin -> host = host ;
266
272
plugin -> port = port ;
267
- free (plugin -> url );
268
- plugin -> url = url ;
269
-
270
- if (plugin -> started ) {
271
- // restart service
272
- ekuiper_plugin_stop (plugin );
273
- ekuiper_plugin_start (plugin );
274
- }
273
+ plugin -> url = url ;
275
274
276
275
return rv ;
277
276
@@ -310,6 +309,9 @@ static int ekuiper_plugin_request(neu_plugin_t * plugin,
310
309
}
311
310
break ;
312
311
}
312
+ case NEU_REQRESP_NODE_DELETED : {
313
+ break ;
314
+ }
313
315
case NEU_REQ_UPDATE_NODE : {
314
316
break ;
315
317
}
0 commit comments