Skip to content

Commit b2758f3

Browse files
committed
Fixed start() failed execute onWorkerStop
1 parent cb647b4 commit b2758f3

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ modules/*
4747
/examples/.idea
4848
/examples/recv_file.jpg
4949
/modules
50+
/examples/async/test.copy

php_swoole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "Client.h"
3838
#include "async.h"
3939

40-
#define PHP_SWOOLE_VERSION "1.7.6-beta"
40+
#define PHP_SWOOLE_VERSION "1.7.6"
4141
#define PHP_SWOOLE_CHECK_CALLBACK
4242

4343
/**

src/factory/FactoryProcess.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,21 @@ static int swFactoryProcess_manager_start(swFactory *factory)
311311
SwooleG.task_workers.onWorkerStart = swTaskWorker_onWorkerStart;
312312
SwooleG.task_workers.onWorkerStop = swTaskWorker_onWorkerStop;
313313
}
314+
314315
pid = fork();
315316
switch (pid)
316317
{
317318
//创建manager进程
318319
case 0:
319-
//创建子进程
320+
//wait master process
321+
SW_START_SLEEP();
322+
if (SwooleGS->start == 0)
323+
{
324+
return SW_OK;
325+
}
326+
/**
327+
* create worker process
328+
*/
320329
for (i = 0; i < serv->worker_num; i++)
321330
{
322331
//close(worker_pipes[i].pipes[0]);
@@ -325,16 +334,17 @@ static int swFactoryProcess_manager_start(swFactory *factory)
325334
pid = swFactoryProcess_worker_spawn(factory, i);
326335
if (pid < 0)
327336
{
328-
swError("Fork worker process fail");
337+
swError("fork() failed.");
329338
return SW_ERR;
330339
}
331340
else
332341
{
333342
serv->workers[i].pid = pid;
334343
}
335344
}
345+
336346
/**
337-
* create task worker pool
347+
* create task worker process
338348
*/
339349
if (SwooleG.task_worker_num > 0)
340350
{
@@ -401,7 +411,7 @@ static int swFactoryProcess_manager_loop(swFactory *factory)
401411
reload_workers = sw_calloc(reload_worker_num, sizeof(swWorker));
402412
if (reload_workers == NULL)
403413
{
404-
swError("[manager] malloc[reload_workers] failed");
414+
swError("malloc[reload_workers] failed");
405415
return SW_ERR;
406416
}
407417

@@ -417,7 +427,7 @@ static int swFactoryProcess_manager_loop(swFactory *factory)
417427
{
418428
if (ManagerProcess.worker_reloading == 0)
419429
{
420-
swTrace("[Manager] wait failed. Error: %s [%d]", strerror(errno), errno);
430+
swTrace("wait() failed. Error: %s [%d]", strerror(errno), errno);
421431
}
422432
else if (ManagerProcess.reload_flag == 0)
423433
{

src/network/Server.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,21 @@ static int swServer_start_proxy(swServer *serv)
468468

469469
int swServer_start(swServer *serv)
470470
{
471-
swFactory *factory = &serv->factory;
472-
int ret;
471+
swFactory *factory = &serv->factory;
472+
int ret;
473473

474-
ret = swServer_start_check(serv);
475-
if (ret < 0)
476-
{
477-
return SW_ERR;
478-
}
474+
ret = swServer_start_check(serv);
475+
if (ret < 0)
476+
{
477+
return SW_ERR;
478+
}
479479

480-
if (serv->message_queue_key == 0)
481-
{
482-
char path_buf[128];
483-
char *path_ptr = getcwd(path_buf, 128);
484-
serv->message_queue_key = ftok(path_ptr, 1) + getpid();
485-
}
480+
if (serv->message_queue_key == 0)
481+
{
482+
char path_buf[128];
483+
char *path_ptr = getcwd(path_buf, 128);
484+
serv->message_queue_key = ftok(path_ptr, 1) + getpid();
485+
}
486486

487487
if (serv->ipc_mode == SW_IPC_MSGQUEUE)
488488
{

0 commit comments

Comments
 (0)