Skip to content

Commit

Permalink
Fixed start() failed execute onWorkerStop
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Sep 27, 2014
1 parent cb647b4 commit b2758f3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ modules/*
/examples/.idea
/examples/recv_file.jpg
/modules
/examples/async/test.copy
2 changes: 1 addition & 1 deletion php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "Client.h"
#include "async.h"

#define PHP_SWOOLE_VERSION "1.7.6-beta"
#define PHP_SWOOLE_VERSION "1.7.6"
#define PHP_SWOOLE_CHECK_CALLBACK

/**
Expand Down
20 changes: 15 additions & 5 deletions src/factory/FactoryProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,21 @@ static int swFactoryProcess_manager_start(swFactory *factory)
SwooleG.task_workers.onWorkerStart = swTaskWorker_onWorkerStart;
SwooleG.task_workers.onWorkerStop = swTaskWorker_onWorkerStop;
}

pid = fork();
switch (pid)
{
//创建manager进程
case 0:
//创建子进程
//wait master process
SW_START_SLEEP();
if (SwooleGS->start == 0)
{
return SW_OK;
}
/**
* create worker process
*/
for (i = 0; i < serv->worker_num; i++)
{
//close(worker_pipes[i].pipes[0]);
Expand All @@ -325,16 +334,17 @@ static int swFactoryProcess_manager_start(swFactory *factory)
pid = swFactoryProcess_worker_spawn(factory, i);
if (pid < 0)
{
swError("Fork worker process fail");
swError("fork() failed.");
return SW_ERR;
}
else
{
serv->workers[i].pid = pid;
}
}

/**
* create task worker pool
* create task worker process
*/
if (SwooleG.task_worker_num > 0)
{
Expand Down Expand Up @@ -401,7 +411,7 @@ static int swFactoryProcess_manager_loop(swFactory *factory)
reload_workers = sw_calloc(reload_worker_num, sizeof(swWorker));
if (reload_workers == NULL)
{
swError("[manager] malloc[reload_workers] failed");
swError("malloc[reload_workers] failed");
return SW_ERR;
}

Expand All @@ -417,7 +427,7 @@ static int swFactoryProcess_manager_loop(swFactory *factory)
{
if (ManagerProcess.worker_reloading == 0)
{
swTrace("[Manager] wait failed. Error: %s [%d]", strerror(errno), errno);
swTrace("wait() failed. Error: %s [%d]", strerror(errno), errno);
}
else if (ManagerProcess.reload_flag == 0)
{
Expand Down
26 changes: 13 additions & 13 deletions src/network/Server.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,21 +468,21 @@ static int swServer_start_proxy(swServer *serv)

int swServer_start(swServer *serv)
{
swFactory *factory = &serv->factory;
int ret;
swFactory *factory = &serv->factory;
int ret;

ret = swServer_start_check(serv);
if (ret < 0)
{
return SW_ERR;
}
ret = swServer_start_check(serv);
if (ret < 0)
{
return SW_ERR;
}

if (serv->message_queue_key == 0)
{
char path_buf[128];
char *path_ptr = getcwd(path_buf, 128);
serv->message_queue_key = ftok(path_ptr, 1) + getpid();
}
if (serv->message_queue_key == 0)
{
char path_buf[128];
char *path_ptr = getcwd(path_buf, 128);
serv->message_queue_key = ftok(path_ptr, 1) + getpid();
}

if (serv->ipc_mode == SW_IPC_MSGQUEUE)
{
Expand Down

0 comments on commit b2758f3

Please sign in to comment.