Example #1
0
zcThreadSeq*   
zc_threadseq_new (int th)
//zc_threadseq_new (int maxth, int minth, int idle)
{
    zcThreadSeq    *q; 

    q = (zcThreadSeq*)zc_malloc(sizeof(zcThreadSeq));
    memset(q, 0, sizeof(zcThreadSeq));

    q->max_thread  = th;
    q->min_thread  = th;
    q->idle_thread = 0;
    q->status      = ZC_THREADSEQ_RUN;

    q->share = (zcThreadInfo*)zc_malloc(sizeof(zcThreadInfo) * q->max_thread);
    if (NULL == q->share) {
        zc_free(q);
        return NULL;
    }   

    int ret = pthread_mutex_init(&q->lock, NULL);
    if (ret != 0) {
        ZCERROR("pthread_mutex_init error");
        zc_free(q->share);
        zc_free(q);
        return NULL;
    }

    return q;
}
Example #2
0
void
zc_dict_delete(void *h)
{
    zcDict *ht = (zcDict*)h;
    zc_dict_clear(ht);
    zc_free(ht->table);
    zc_free(h);
}
Example #3
0
void    
zc_threadseq_delete (void *x)
{
    zcThreadSeq *q = (zcThreadSeq*)x;
    pthread_mutex_destroy(&q->lock);
    zc_free(q->share);
    zc_free(q);
}
Example #4
0
void
zc_hashset_delete(void *h)
{
    if (NULL == h) {
        ZCERROR("zc_hashset_destroy NULL pointer:%p\n", h);
        return;
    }
    zcHashSet   *ha = (zcHashSet*)h;
    zc_hashset_clear(ha);
    zc_free(ha->bunks);
    zc_free(ha);
}
Example #5
0
zcSocket*
zc_socket_new (int family, int type, int proto, int timeout)
{
    zcSocket *s;
    s = (zcSocket *) zc_malloc (sizeof(zcSocket));
    if (s != NULL) {
        memset(s, 0, sizeof(zcSocket));
        s->fd = socket(family, type, proto);
        //ZCINFO("fd:%d", s->fd);
        if (s->fd == INVALID_SOCKET) {
            zc_free(s);
            //WSACleanup();
            ZCINFO("socket create error! %s\n", strerror(errno));
            return  NULL;
        }
        
        s->family = family;
        s->type = type;
        s->proto = proto;
        s->timeout = timeout; 

        /*if (timeout >= 0) {
            ZCINFO("socket noblock!\n");
            zc_socket_setblock(s, 0);
        }*/

    }
    return s;
}
Example #6
0
void
zc_mysqldb_delete(void *db)
{
    zcMySQLDB *mdb = (zcMySQLDB*)db;
    mysql_close(mdb->_mysql);
    zc_free(mdb);
}
Example #7
0
void	
zc_loop_delete(void* x)
{
    zcLoop *loop = (zcLoop*)x;
    close(loop->efd); 
    zc_free(x);
}
Example #8
0
void
zc_socket_delete (void *x)
{
    zcSocket *s = (zcSocket*)x;
    // 这里是否要检测socket已经关闭?
    zc_socket_close(s);
    zc_free(s);
    //WSACleanup();
}
Example #9
0
zcProtocol* 
zc_protocol_new()
{
    zcProtocol *p = zc_calloct(zcProtocol);
    if (zc_protocol_init(p) != ZC_OK) {
        zc_free(p);
        return NULL;
    }
    return p;
}
Example #10
0
void
zc_mysqlrec_delete(void *rec)
{
    zcMySQLRec *mrec = (zcMySQLRec*)rec;
    if (mrec->res) {
        mysql_free_result(mrec->res);
    }
    zc_dict_delete(mrec->fieldmap);
    zc_free(mrec);
}
Example #11
0
void* my_consumer(void *x)
{
    char *a = (char*)x;

    ZCINFO("consumer %s", a);
    //sleep(1);

    zc_free(a);

    return NULL;
}
Example #12
0
void	  
zc_cookie_delete(void *x)
{
    zcCookie *c = (zcCookie*)x;
    zc_str_destroy(&c->key);
    zc_str_destroy(&c->value);
    zc_str_destroy(&c->domain);
    zc_str_destroy(&c->path);

    zc_free(x);
}
Example #13
0
void
zc_dnsrr_delete(void *x)
{
    zcDNSRR *r = (zcDNSRR*)x;
    zc_str_delete(r->domain);
    
    if (r->data) {
        switch(r->type) {
        case ZC_DNS_T_A:
            break;
        case ZC_DNS_T_NS: {
            zcDNSNS *n = (zcDNSNS*)r->data;
            zc_str_delete(n->name);
            break;
        }
        case ZC_DNS_T_CNAME: {
            zcDNSCNAME *n = (zcDNSCNAME*)r->data;
            zc_str_delete(n->name);
            break;
        }
        case ZC_DNS_T_SOA:
            break;
        case ZC_DNS_T_PTR:
            break;
        case ZC_DNS_T_MX:
            break; 
        case ZC_DNS_T_TXT:
            break;
        case ZC_DNS_T_AAAA:
            break;
        case ZC_DNS_T_SRV:
            break;
        case ZC_DNS_T_SSHFP:
            break;
        case ZC_DNS_T_SPF:
            break;
        }
        zc_free(r->data);
    }
    zc_free(x);
}
Example #14
0
void
zc_hashset_node_delete(void *h, void *n)
{
    if (NULL == n) {
        ZCWARN("zc_hashset_node_destroy NULL pointer\n");
    }
    zcHashSet *hs = (zcHashSet*)h;
    zcHashSetNode *node = (zcHashSetNode*)n;

    if (hs->keydel) {
        hs->keydel(node->key);
    }
    zc_free(node);
}
Example #15
0
static void 
_call_later_ev_timeout(struct ev_loop *loop, ev_timer *t, int events)
{
    struct zc_asyn_callback_value_t *v = t->data;
    
    double repeat_time = (double)t->repeat;
    int ret = v->callback(v->conn, v->data);
    //ZCINFO("repeat:%d, ret:%lf", (double)t->repeat, ret);
    if (ret == ZC_STOP || fabs(repeat_time) <= EPSINON) {
        ZCINFO("stop timer");
        ev_timer_stop(loop, t);
        zc_free(v);
    }
}
Example #16
0
zcLoop* 
zc_loop_create()
{
    zcLoop *loop = zc_calloct(zcLoop);
    if (NULL == loop)
        return NULL;
    loop->efd = epoll_create(1);
    if (loop->efd < 0) {
        ZCERROR("epoll create error:%d", loop->efd);
        zc_free(loop);
        return NULL;
    }
    loop->state = ZC_LOOP_RUN;
    return loop;
}
Example #17
0
zcCookie* 
zc_cookie_new(const char *cookiestr)
{
    zcCookie *c = (zcCookie*)zc_calloc(sizeof(zcCookie));
    zc_str_init(&c->key, 0);
    zc_str_init(&c->value, 0);
    zc_str_init(&c->domain, 0);
    zc_str_init(&c->path, 0);

    if (zc_cookie_init(c, cookiestr) != ZC_OK) {
        zc_free(c);
        return NULL;
    }

    return c;
}
Example #18
0
void
zc_asynio_delete(void* conn)
{
    zcAsynIO *aconn = (zcAsynIO*)conn;
    //ZCINFO("read buffer delete");
    zcBuffer *tmp;
    if (aconn->rbuf_free) {
        zcBuffer *buf = aconn->rbuf;
        while (buf) {
            tmp = buf->next;
            ZCDEBUG("free rbuf:%p", buf);
            zc_buffer_delete(buf);
            buf = tmp;
        }
    }
    //ZCINFO("write buffer delete");
    if (aconn->wbuf_free) {
        zcBuffer *buf = aconn->wbuf;
        while (buf) {
            tmp = buf->next;
            zc_buffer_delete(buf);
            buf = tmp;
        }
    }

    //ZCINFO("stop io in loop");
    ev_io_stop(aconn->loop, &aconn->r);
    ev_io_stop(aconn->loop, &aconn->w);

    ev_timer_stop(aconn->loop, &aconn->rtimer);
    ev_timer_stop(aconn->loop, &aconn->wtimer);

    //if (aconn->read_timeout > 0) {
    if (aconn->timer.pending > 0 || aconn->timer.active > 0) {
        ev_timer_stop(aconn->loop, &aconn->timer);
    }
    if (aconn->sock) {
        zc_socket_delete(aconn->sock);
    }
    /*if (aconn->calls) {
        zc_callchain_safedel(aconn->calls);    
    }*/

    zc_free(conn);
}
Example #19
0
long ffparse(char *string)
{
    //return int(atof(string)*10000);
    
    //this function below isn't working too well yet
    //clean_numeric_string(string);
    double negcheck = atof(string);
    
    //if no decimal point, ascii to int conversion
    char *ptr=strchr(string, '.');
    
    if(!ptr)
    {
        return atoi(string)*10000;
    }
    
    long ret=0;
    char *tempstring1;
    tempstring1=(char *)zc_malloc(strlen(string)+5);
    sprintf(tempstring1, string);
    
    for(int i=0; i<4; ++i)
    {
        tempstring1[strlen(string)+i]='0';
    }
    
    ptr=strchr(tempstring1, '.');
    *ptr=0;
    ret=atoi(tempstring1)*10000;
    
    ++ptr;
    char *ptr2=ptr;
    ptr2+=4;
    *ptr2=0;
    
    if(negcheck<0)
        ret-=atoi(ptr);
    else ret+=atoi(ptr);
    
    zc_free(tempstring1);
    return ret;
}
Example #20
0
zcDB*
zc_mysqldb_new(zcMySQLConf *cf)
{
    zcMySQLDB *mdb = (zcMySQLDB*)zc_malloc(sizeof(zcMySQLDB));
    memset(mdb, 0, sizeof(zcMySQLDB));

    memcpy(&mdb->conf, cf, sizeof(zcMySQLConf));
    mdb->_mysql = mysql_init(NULL);
    if (NULL == mdb->_mysql) {
        ZCERROR("mysql init error!\n");
        zc_free(mdb);
        return NULL;
    }

    if (cf->conn_timeout > 0) {
        mysql_options(mdb->_mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const void*)&cf->conn_timeout);
    }
    if (cf->read_timeout > 0) {
        mysql_options(mdb->_mysql, MYSQL_OPT_READ_TIMEOUT, (const void*)&cf->read_timeout);
    }
    if (cf->write_timeout > 0) {
        mysql_options(mdb->_mysql, MYSQL_OPT_WRITE_TIMEOUT, (const void*)&cf->write_timeout);
    }

    mdb->_isopen = 0;

    mdb->del   = zc_mysqldb_delete;
    mdb->exec  = zc_mysqldb_exec;
    mdb->execf = zc_mysqldb_execf;
    mdb->query = zc_mysqldb_query;
    mdb->start = zc_mysqldb_start;
    mdb->commit   = zc_mysqldb_commit;
    mdb->rollback = zc_mysqldb_rollback;
    mdb->last_insert_id = zc_mysqldb_last_insert_id;

    zc_mysqldb_open((zcDB*)mdb);

    return (zcDB*)mdb;
}
Example #21
0
int
zc_hashset_resize(zcHashSet *h, int newsize)
{
    void **newbunks = (void**)zc_malloc(sizeof(void*) * newsize);
    zcHashSetNode  *node, *nextnode;
    int i;
    for (i = 0; i < h->size; i++) {
        node = (zcHashSetNode*)h->bunks[i];
        while (node) {
            nextnode = (zcHashSetNode*)node->next;
            uint32_t hv = h->hash(node->key, strlen(node->key)) % newsize;
            zcHashSetNode  *root = (zcHashSetNode*)newbunks[hv];
            node->next = root;
            newbunks[hv] = node;
            node = nextnode;
        }
    }
    zc_free(h->bunks);
    h->bunks = newbunks;
    h->size  = newsize;

    return ZC_OK;
}
Example #22
0
int ListQTs(bool edit)
{
    qtlist_dlg[0].dp2=lfont;
    int index=0;
    quest_template *BackupQTs = (quest_template*)zc_malloc(sizeof(quest_template)*MAXQTS);
    
    memcpy(BackupQTs,QuestTemplates,sizeof(quest_template)*qt_count);
    
    int backup_qt_count=qt_count;
    
    while(index>-1)
    {
        bool hasroom=false;
        
        if(qt_count<MAXQTS)
        {
            hasroom=true;
            
            if(edit)
            {
                strcpy(QuestTemplates[qt_count++].name,"<new template>");
            }
        }
        
        if(is_large)
            large_dialog(qtlist_dlg);
            
        qtlist_dlg[2].x=int(qtlist_dlg[0].x+(edit?5:15)*(is_large?1.5:1));
        qtlist_dlg[3].proc=edit?jwin_button_proc:d_dummy_proc;
        qtlist_dlg[4].proc=edit?jwin_button_proc:d_dummy_proc;
        qtlist_dlg[5].proc=edit?jwin_button_proc:d_dummy_proc;
        qtlist_dlg[6].x=int(qtlist_dlg[0].x+(edit?110:80)*(is_large?1.5:1));
        qtlist_dlg[7].x=int(qtlist_dlg[0].x+(edit?190:160)*(is_large?1.5:1));
        qtlist_dlg[8].proc=edit?d_keyboard_proc:d_dummy_proc;
        
        int ret=zc_popup_dialog(qtlist_dlg,2);
        
        index=qtlist_dlg[2].d1;
        
        int doedit=false;
        
        switch(ret)
        {
        case 2:
            if(edit)
            {
                doedit=true;
            }
            else
            {
                if(index>0&&!valid_zqt(QuestTemplates[index].path))
                {
                    jwin_alert("ZQuest","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,lfont);
                }
                else
                {
                    strcpy(header.templatepath, QuestTemplates[index].path);
                    index=-1;
                }
            }
            
            break;
            
        case 5:
            doedit=true;
            break;
            
        case 3:
            if(index>1&&index<qt_count-1)
            {
                zc_swap(QuestTemplates[index],QuestTemplates[index-1]);
                --qtlist_dlg[2].d1;
                index=qtlist_dlg[2].d1;
            }
            
            break;
            
        case 4:
            if(index>0&&index<qt_count-2)
            {
                zc_swap(QuestTemplates[index],QuestTemplates[index+1]);
                ++qtlist_dlg[2].d1;
                index=qtlist_dlg[2].d1;
            }
            
            break;
            
        case 6:
            if(index>0&&!valid_zqt(QuestTemplates[index].path))
            {
                jwin_alert("ZQuest","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,lfont);
            }
            else
            {
                if(!edit)
                {
                    strcpy(header.templatepath, QuestTemplates[index].path);
                }
                
                index=-1;
            }
            
            break;
            
        case 0:
        case 7:
            if(edit)
            {
                qt_count=backup_qt_count+1;
                memcpy(QuestTemplates,BackupQTs,sizeof(quest_template)*qt_count);
            }
            
            index=-2;
            break;
            
        case 8:
            char buf[30];
            strncpy(buf,QuestTemplates[index].name,30);
            
            if(jwin_alert("Confirm Deletion", "Delete this quest template?",buf,"(The file will still exist.)","Yes","No",'y',27,lfont)==1)
            {
                for(int i=index; i<MAXQTS-1; i++)
                    QuestTemplates[i]=QuestTemplates[i+1];
                    
                reset_qt(MAXQTS-1);
                --qt_count;
            }
            
            break;
        }
        
        if(edit&&hasroom)
        {
            //      strcpy(QuestTemplates[--qt_count].name,"              ");
            reset_qt(--qt_count);
            sprintf(QuestTemplates[qt_count].name,"Untitled");
        }
        
        if(index>0 && doedit)
        {
            edit_qt(index);
        }
    }
    
    zc_free(BackupQTs);
    return index;
}
Example #23
0
void
zc_sockaddr_delete(void *x)
{
    zc_free(x);
}
Example #24
0
void		 
zc_callchain_delete(void *x)
{
    zc_free(x);
}
Example #25
0
/* jwin_file_select_ex:
  *  Displays the JWin file selector, with the message as caption.
  *  Allows the user to select a file, and stores the selection in the
  *  path buffer, whose length in bytes is given by size and should have
  *  room for at least 80 characters. The files are filtered according to
  *  the file extensions in ext. Passing NULL includes all files, "PCX;BMP"
  *  includes only files with .PCX or .BMP extensions. Returns zero if it
  *  was closed with the Cancel button or non-zero if it was OK'd.
  */
int jwin_file_select_ex(AL_CONST char *message, char *path, AL_CONST char *ext, int size, int width, int height, FONT *title_font)
{
    static attrb_state_t default_attrb_state[ATTRB_MAX] = DEFAULT_ATTRB_STATE;
    int ret;
    char *p;
    char tmp[32];
    ASSERT(message);
    ASSERT(path);
    
    if(title_font)
    {
        file_selector[0].dp2=title_font;
    }
    
    if(width == OLD_FILESEL_WIDTH)
        width = 304;
        
#ifdef HAVE_DIR_LIST
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 160;
        
#else
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 188;
        
#endif
        
    /* for fs_dlist_proc() */
    ASSERT(size >= 4 * uwidth_max(U_CURRENT));
    
    usetc(updir, 0);
    file_selector[FS_WIN].dp = (char *)message;
    file_selector[FS_EDIT].d1 = size/uwidth_max(U_CURRENT) - 1;
    file_selector[FS_EDIT].dp = path;
    file_selector[FS_OK].dp = (void*)get_config_text("OK");
    file_selector[FS_CANCEL].dp = (void*)get_config_text("Cancel");
    
    /* Set default attributes. */
    memcpy(attrb_state, default_attrb_state, sizeof(default_attrb_state));
    
    /* Parse extension string. */
//  if (ext)// && ugetc(ext))
    {
        parse_extension_string(ext);
    }
    
    if(!ugetc(path))
    {
    
#ifdef HAVE_DIR_LIST
    
        int drive = _al_getdrive();
        
#else
        
        int drive = 0;
#endif
        
        _al_getdcwd(drive, path, size - ucwidth(OTHER_PATH_SEPARATOR));
        fix_filename_case(path);
        fix_filename_slashes(path);
        put_backslash(path);
    }
    
    clear_keybuf();
    
    do
    {
    }
    while(gui_mouse_b());
    
    file_selector[FS_TYPES].proc = fs_dummy_proc;
    enlarge_file_selector(width, height);
    ret = popup_zqdialog(file_selector, FS_EDIT);
    
    if(fext)
    {
        zc_free(fext);
        fext = NULL;
    }
    
    if(fext_p)
    {
        _al_free(fext_p);
        fext_p = NULL;
    }
    
    if((ret == FS_CANCEL) || (ret == FS_WIN) || (!ugetc(get_filename(path))))
        return FALSE;
        
    p = get_extension(path);
    
    if((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", tmp))))
    {
        size -= ((long)(size_t)p - (long)(size_t)path + ucwidth('.'));
        
        if(size >= uwidth_max(U_CURRENT) + ucwidth(0))          /* do not end with '.' */
        {
            p += usetc(p, '.');
            ustrzcpy(p, size, ext);
        }
    }
    
    return TRUE;
}
Example #26
0
/* fs_flist_proc:
  *  Dialog procedure for the file selector list.
  */
static int fs_flist_proc(int msg, DIALOG *d, int c)
{
    static int recurse_flag = 0;
    char *s = (char *) file_selector[FS_EDIT].dp;
    char tmp[32];
    /* of s (in bytes) */
    int size = (file_selector[FS_EDIT].d1 + 1) * uwidth_max(U_CURRENT);
    int sel = d->d1;
    int i, ret;
    int ch, count;
    
    if(msg == MSG_START)
    {
        if(!flist)
        {
            flist = (FLIST *) zc_malloc(sizeof(FLIST));
            
            if(!flist)
            {
                *allegro_errno = ENOMEM;
                return D_CLOSE;
            }
        }
        else
        {
            for(i=0; i<flist->size; i++)
                if(flist->name[i])
                    zc_free(flist->name[i]);
        }
        
        flist->size = 0;
        
        replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir));
        
        /* The semantics of the attributes passed to file_select_ex() is
          * different from that of for_each_file_ex() in one case: when
          * the 'd' attribute is not mentioned in the set of characters,
          * the other attributes are not taken into account for directories,
          * i.e the directories are all included. So we can't filter with
          * for_each_file_ex() in that case.
          */
        if(attrb_state[ATTRB_DIREC] == ATTRB_ABSENT)
            /* accept all dirs */
            for_each_file_ex(flist->dir, 0 , FA_LABEL, fs_flist_putter, (void *)1UL /* check */);
        else
            /* don't check */
            for_each_file_ex(flist->dir, build_attrb_flag(ATTRB_SET), build_attrb_flag(ATTRB_UNSET) | FA_LABEL, fs_flist_putter, (void *)0UL);
            
        usetc(get_filename(flist->dir), 0);
        d->d1 = d->d2 = 0;
        sel = 0;
    }
    
    if(msg == MSG_END)
    {
        if(flist)
        {
            for(i=0; i<flist->size; i++)
                if(flist->name[i])
                    zc_free(flist->name[i]);
                    
            zc_free(flist);
            flist = NULL;
        }
    }
    
    recurse_flag++;
    ret = jwin_abclist_proc(msg,d,c);                         /* call the parent procedure */
    
    recurse_flag--;
    
    if(((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0))
    {
        replace_filename(s, flist->dir, flist->name[d->d1], size);
        
        /* check if we want to `cd ..' */
        if((!ustrncmp(flist->name[d->d1], uconvert_ascii("..", tmp), 2)) && (ret == D_CLOSE))
        {
            /* let's remember the previous directory */
            usetc(updir, 0);
            i = ustrlen(flist->dir);
            count = 0;
            
            while(i>0)
            {
                ch = ugetat(flist->dir, i);
                
                if((ch == '/') || (ch == OTHER_PATH_SEPARATOR))
                {
                    if(++count == 2)
                        break;
                }
                
                uinsert(updir, 0, ch);
                i--;
            }
            
            /* ok, we have the dirname in updir */
        }
        else
        {
            usetc(updir, 0);
        }
        
        object_message(file_selector+FS_EDIT, MSG_START, 0);
        object_message(file_selector+FS_EDIT, MSG_DRAW, 0);
        
        if(ret == D_CLOSE)
            return object_message(file_selector+FS_EDIT, MSG_KEY, 0);
    }
    
    return ret;
}