Example #1
0
zval * php_yar_packager_msgpack_unpack(yar_packager_t *self, char *content, size_t len, char **msg, zval *rret) /* {{{ */ {
	zval *return_value;
	ZVAL_NULL(rret);
	php_msgpack_unserialize(rret, content, len);
	return_value = rret;
	return return_value;
} /* }}} */
Example #2
0
static int cpWorker_loop(int worker_id, int group_id)
{
    cpWorker_init(worker_id, group_id);
    cpGroup *G = &CPGS->G[group_id];
    cpShareMemory *sm_obj = &(G->workers[worker_id].sm_obj);

    int ret;
    cpSettitle(G->name);
    cpSignalSet(SIGALRM, cpWorker_do_ping, 1, 0);
    cpSignalSet(SIGTERM, cpWorker_do_stop, 1, 0);
    alarm(CP_PING_SLEEP);
    while (CPGS->running)
    {
        zval *ret_value;
        ALLOC_INIT_ZVAL(ret_value);
        bzero(&CPWG.event, sizeof (cpWorkerInfo));
        ret = cpFifoRead(CPWG.pipe_fd_read, &CPWG.event, sizeof (cpWorkerInfo));
        if (ret < 0)
        {
            cpLog("fifo read Error: %s [%d]", strerror(errno), errno);
        }
        CPWG.working = 1;
        php_msgpack_unserialize(ret_value, sm_obj->mem, CPWG.event.len);
        worker_onReceive(ret_value);
        CPWG.working = 0;
    }
    return SUCCESS;
}
Example #3
0
static int cpWorker_loop(int worker_id)
{
    CPWG.id = worker_id;
    char fifo_name[CP_FIFO_NAME_LEN] = {0};
    sprintf(fifo_name, "%s_%d", CP_FIFO_NAME_PRE, CPGC.group_id * CP_GROUP_LEN + worker_id); //client 2 worker
    int pipe_fd_read = cpCreateFifo(fifo_name);

    sprintf(fifo_name, "%s_%d_1", CP_FIFO_NAME_PRE, CPGC.group_id * CP_GROUP_LEN + worker_id); //worker 2 client
    int pipe_fd_write = cpCreateFifo(fifo_name);
    CPGS->workers[worker_id].pipe_fd_write = pipe_fd_write;
    cpShareMemory *sm_obj = &(CPGS->workers[worker_id].sm_obj);

    cpWorkerInfo event;
    bzero(&event, sizeof (event));
    int ret, len = 0;
    int event_len = sizeof (event);
    while (CPGS->running) {
        zval *ret_value;
        ALLOC_INIT_ZVAL(ret_value);
        if (CPGS->workers[worker_id].pre_len) {
            len = CPGS->workers[worker_id].pre_len;
            CPGS->workers[worker_id].pre_len = 0;
            CPWG.clientPid = CPGS->workers[worker_id].pre_pid;
        } else {
            do {
                ret = cpFifoRead(pipe_fd_read, &event, event_len);
                if (ret < 0) {
                    cpLog("fifo read Error: %s [%d]", strerror(errno), errno);
                }
            } while (event.pid != CPGS->workers[worker_id].CPid); //有可能有脏数据  读出来
            if (!CPGS->workers[worker_id].run) {
                CPGS->workers[worker_id].pre_len = event.len; //啊~~我要挂了,赶紧存起来 下次再用
                CPGS->workers[worker_id].pre_pid = event.pid;
                break;
            }
            len = event.len;
//            cpLog("worker %d len",len);
            CPWG.clientPid = event.pid;
        }
        if (sm_obj->mem == NULL) {
            if ((sm_obj->mem = shmat(sm_obj->shmid, NULL, 0)) < 0) {
                cpLog("attach sys mem error Error: %s [%d]", strerror(errno), errno);
            }
        }
        if (ret < 0) {
            cpLog("fifo read Error: %s [%d]", strerror(errno), errno);
        }
        php_msgpack_unserialize(ret_value, sm_obj->mem, len);
        worker_onReceive(ret_value);
    }
    return SUCCESS;
}
Example #4
0
static int cpWorker_loop(int worker_id, int group_id)
{
    CPWG.id = worker_id;
    CPWG.gid = group_id;
    cpGroup *G = &CPGS->G[group_id];
    char fifo_name[CP_FIFO_NAME_LEN] = {0};
    sprintf(fifo_name, "%s_%d", CP_FIFO_NAME_PRE, group_id * CP_GROUP_LEN + worker_id); //client 2 worker
    int pipe_fd_read = cpCreateFifo(fifo_name);

    sprintf(fifo_name, "%s_%d_1", CP_FIFO_NAME_PRE, group_id * CP_GROUP_LEN + worker_id); //worker 2 client
    int pipe_fd_write = cpCreateFifo(fifo_name);
    G->workers[worker_id].pipe_fd_write = pipe_fd_write;
    cpShareMemory *sm_obj = &(G->workers[worker_id].sm_obj);

    cpWorkerInfo event;
    bzero(&event, sizeof (event));
    int ret, len = 0;
    int event_len = sizeof (event);
    cpSettitle(G->name);
    cpSignalSet(SIGALRM, cpWorker_do_ping, 1, 0);
    alarm(CP_PING_SLEEP);
    while (CPGS->running)
    {
        zval *ret_value;
        ALLOC_INIT_ZVAL(ret_value);
        do
        {
            ret = cpFifoRead(pipe_fd_read, &event, event_len);
            if (ret < 0)
            {
                cpLog("fifo read Error: %s [%d]", strerror(errno), errno);
            }
        } while (event.pid != G->workers[worker_id].CPid); //有可能有脏数据  读出来
        CPWG.working = 1;
        len = event.len;
        CPWG.clientPid = event.pid;
        if (ret < 0)
        {
            cpLog("fifo read Error: %s [%d]", strerror(errno), errno);
        }
        php_msgpack_unserialize(ret_value, sm_obj->mem, len);
        worker_onReceive(ret_value);
        CPWG.working = 0;
    }
    return SUCCESS;
}
static int cli_real_recv(cpMasterInfo *info) {
    int pipe_fd_read = get_readfd(info->worker_id);
    cpWorkerInfo event;
    int ret = 0;
    do {
        ret = cpFifoRead(pipe_fd_read, &event, sizeof (event));
        if (ret < 0) {
            zend_error(E_ERROR, "fifo read Error: %s [%d]", strerror(errno), errno);
        }
    } while (event.pid != cpPid); //有可能有脏数据  读出来

    zval *ret_value;
    ALLOC_INIT_ZVAL(ret_value);
    php_msgpack_unserialize(ret_value, get_attach_buf(info->worker_id,info->semid), event.len);
    RecvData.type = event.type;
    RecvData.ret_value = ret_value;
    return SUCCESS;
}