Ejemplo n.º 1
0
static int swFactoryProcess_worker_spawn(swFactory *factory, int writer_pti, int worker_pti)
{
	swFactoryProcess *this = factory->object;
	int i, pid;

	pid = fork();
	if (pid < 0)
	{
		swTrace("[swFactoryProcess_worker_spawn]Fork Worker fail\n");
		return SW_ERR;
	}
	//worker child processor
	else if (pid == 0)
	{
		for (i = 0; i < this->worker_num; i++)
		{
			//非当前
			if (worker_pti != i)
			{
				close(this->workers[i].pipe_fd);
			}
		}
		c_writer_pti = writer_pti;
		swFactoryProcess_worker_loop(factory, this->workers[worker_pti].pipe_fd, worker_pti);
		exit(0);
	}
	//parent,add to writer
	else
	{
		return pid;
	}
}
Ejemplo n.º 2
0
static int swFactoryProcess_worker_spawn(swFactory *factory, int worker_pti)
{
	int pid, ret;

	pid = fork();
	if (pid < 0)
	{
		swWarn("Fork Worker failed. Error: %s [%d]", strerror(errno), errno);
		return SW_ERR;
	}
	//worker child processor
	else if (pid == 0)
	{
		ret = swFactoryProcess_worker_loop(factory, worker_pti);
		exit(ret);
	}
	//parent,add to writer
	else
	{
		return pid;
	}
}
Ejemplo n.º 3
0
static int swFactoryProcess_worker_spawn(swFactory *factory, int worker_pti)
{
	int pid, ret;

	pid = fork();
	if (pid < 0)
	{
		swWarn("Fork Worker failed. Error: %s [%d]", strerror(errno), errno);
		return SW_ERR;
	}
	//worker child processor
	else if (pid == 0)
	{
#if SW_WORKER_IPC_MODE != 2
		swFactoryProcess *object = factory->object;
		int i;

		for (i = 0; i < object->worker_num; i++)
		{
			//非当前的worker_pipe
			if (worker_pti != i)
			{
				close(object->workers[i].pipe_worker);
			}
			//关闭master_pipe
			close(object->workers[i].pipe_master);
		}
#endif
		//标识为worker进程
		SwooleG.process_type = SW_PROCESS_WORKER;
		ret = swFactoryProcess_worker_loop(factory, worker_pti);
		exit(ret);
	}
	//parent,add to writer
	else
	{
		return pid;
	}
}
Ejemplo n.º 4
0
static int swFactoryProcess_worker_spawn(swFactory *factory, int writer_pti, int worker_pti)
{
	swFactoryProcess *this = factory->object;
	int pid;
	int pipes[2];

	if (socketpair(PF_LOCAL, SOCK_DGRAM, 0, pipes) < 0)
	{
		swTrace("[swFactoryProcess_worker_spawn]create unix socket fail\n");
		return SW_ERR;
	}

	pid = fork();
	if (pid < 0)
	{
		swTrace("[swFactoryProcess_worker_spawn]Fork Worker fail\n");
		exit(5);
	}
	//worker child processor
	else if (pid == 0)
	{
		close(pipes[0]);
		swFactoryProcess_worker_loop(factory, pipes[1]);
		exit(0);
	}
	//parent,add to writer
	else
	{
		close(pipes[1]);
		this->writers[writer_pti].reactor.add(&(this->writers[writer_pti].reactor), pipes[0], SW_FD_CONN);
		this->workers[worker_pti].pid = pid;
		this->workers[worker_pti].writer_id = writer_pti;
		this->workers[worker_pti].pipe_fd = pipes[0];
		return pid;
	}
}