Skip to content

Commit

Permalink
Fixed dispatch_func no effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Mar 22, 2017
1 parent f10e0a5 commit 305948c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
22 changes: 13 additions & 9 deletions include/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,9 @@ static sw_inline swWorker* swServer_get_worker(swServer *serv, uint16_t worker_i
swWarn("worker#%d is not exist.", worker_id);
return NULL;
}

static sw_inline uint32_t swServer_worker_schedule(swServer *serv, uint32_t schedule_key)
static sw_inline int swServer_worker_schedule(swServer *serv, int fd, swEventData *data)
{
uint32_t target_worker_id = 0;
uint16_t target_worker_id = 0;

//polling mode
if (serv->dispatch_mode == SW_DISPATCH_ROUND)
Expand All @@ -742,16 +741,16 @@ static sw_inline uint32_t swServer_worker_schedule(swServer *serv, uint32_t sche
//Using the FD touch access to hash
else if (serv->dispatch_mode == SW_DISPATCH_FDMOD)
{
target_worker_id = schedule_key % serv->worker_num;
target_worker_id = fd % serv->worker_num;
}
//Using the IP touch access to hash
else if (serv->dispatch_mode == SW_DISPATCH_IPMOD)
{
swConnection *conn = swServer_connection_get(serv, schedule_key);
swConnection *conn = swServer_connection_get(serv, fd);
//UDP
if (conn == NULL)
{
target_worker_id = schedule_key % serv->worker_num;
target_worker_id = fd % serv->worker_num;
}
//IPv4
else if (conn->socket_type == SW_SOCK_TCP)
Expand All @@ -771,20 +770,25 @@ static sw_inline uint32_t swServer_worker_schedule(swServer *serv, uint32_t sche
}
else if (serv->dispatch_mode == SW_DISPATCH_UIDMOD)
{
swConnection *conn = swServer_connection_get(serv, schedule_key);
swConnection *conn = swServer_connection_get(serv, fd);
if (conn == NULL)
{
target_worker_id = schedule_key % serv->worker_num;
target_worker_id = fd % serv->worker_num;
}
else if (conn->uid)
{
target_worker_id = conn->uid % serv->worker_num;
}
else
{
target_worker_id = schedule_key % serv->worker_num;
target_worker_id = fd % serv->worker_num;
}
}
//schedule by dispatch function
else if (serv->dispatch_mode == SW_DISPATCH_USERFUNC)
{
return serv->dispatch_func(serv, swServer_connection_get(serv, fd), data);
}
//Preemptive distribution
else
{
Expand Down
29 changes: 8 additions & 21 deletions src/factory/FactoryProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,19 @@ static int swFactoryProcess_notify(swFactory *factory, swDataHead *ev)
*/
static int swFactoryProcess_dispatch(swFactory *factory, swDispatchData *task)
{
uint32_t schedule_key;
uint32_t send_len = sizeof(task->data.info) + task->data.info.len;
uint16_t target_worker_id;
int target_worker_id;
swServer *serv = SwooleG.serv;
int fd = task->data.info.fd;

if (task->target_worker_id < 0)
{
schedule_key = fd;
#ifndef SW_USE_RINGBUFFER
if (SwooleTG.factory_lock_target)
{
if (SwooleTG.factory_target_worker < 0)
{
target_worker_id = swServer_worker_schedule(serv, schedule_key);
target_worker_id = swServer_worker_schedule(serv, fd, &task->data);
SwooleTG.factory_target_worker = target_worker_id;
}
else
Expand All @@ -140,29 +138,18 @@ static int swFactoryProcess_dispatch(swFactory *factory, swDispatchData *task)
else
#endif
{
if (serv->dispatch_mode == SW_DISPATCH_USERFUNC)
{
int ret = serv->dispatch_func(serv, swServer_connection_get(serv, fd), &task->data);
//discard the data packet.
if (ret < 0)
{
return SW_OK;
}
else
{
target_worker_id = ret;
}
}
else
{
target_worker_id = swServer_worker_schedule(serv, schedule_key);
}
target_worker_id = swServer_worker_schedule(serv, fd, &task->data);
}
}
else
{
target_worker_id = task->target_worker_id;
}
//discard the data packet.
if (target_worker_id < 0)
{
return SW_OK;
}

if (swEventData_is_stream(task->data.info.type))
{
Expand Down

0 comments on commit 305948c

Please sign in to comment.