quicwind/quicwind_proc.c
int quicwind_add_work_item(quicwind_work_item_enum item_type,
    int sel_cid, char const * name, char const *port_number, char const * doc_name, char const * alpn, char const *sni)
{
    int ret = 0;
    DWORD w_ret = 0;
    quicwind_work_item_t * w = NULL;

    if (work_item_mutex == NULL) {
        AppendText(_T("Background thread is not ready.\r\n"));
        ret = -1;
    }
    else {
        w = (quicwind_work_item_t *)malloc(sizeof(quicwind_work_item_t));

        if (w == NULL) {
            AppendText(_T("Out of memory.\r\n"));
            ret = -1;
        }
        else {
            w->next = NULL;
            w->item_type = item_type;
            w->sel_cid = sel_cid;

            w->name[0] = 0;
            w->port[0] = 0;
            w->doc[0] = 0;
            w->alpn[0] = 0;
            w->sni[0] = 0;

            if (ret == 0 && name != NULL) {
                ret = memcpy_s(w->name, sizeof(w->name), name, sizeof(w->name));
            }

            if (ret == 0 && port_number != NULL) {
                ret = memcpy_s(w->port, sizeof(w->port), port_number, sizeof(w->port));
            }

            if (ret == 0 && doc_name != NULL) {
                ret = memcpy_s(w->doc, sizeof(w->doc), doc_name, sizeof(w->doc));
            }

            if (ret == 0 && alpn != NULL) {
                ret = memcpy_s(w->alpn, sizeof(w->alpn), alpn, sizeof(w->alpn));
            }

            if (ret == 0 && sni != NULL) {
                ret = memcpy_s(w->sni, sizeof(w->sni), sni, sizeof(w->sni));
            }

            if (ret != 0) {
                AppendText(_T("Cannot copy the work item.\r\n"));
            } else {
                w_ret = WaitForSingleObject(work_item_mutex, 1000);
                switch (w_ret) {
                case WAIT_OBJECT_0: {
                    quicwind_work_item_t * next = work_item_first;
                    quicwind_work_item_t * last = NULL;

                    while (next) {
                        last = next;
                        next = next->next;
                    }

                    if (last) {
                        last->next = w;
                    }
                    else {
                        work_item_first = w;
                    }
                    if (!ReleaseMutex(work_item_mutex)) {
                        AppendText(_T("Cannot release the work item mutex.\r\n"));
                    }

                    quicwind_wake_up_network();

                    break;
                }
                default:
                    AppendText(_T("Cannot obtain the work item mutex.\r\n"));
                    ret = -1;
                    break;
                }
            }

            if (ret != 0) {
                free(w);
            }
        }
    }

    return ret;
}
/* Add a message to the work queue 
 */
Add a message to the work queue
Add a message to the work queue
int quicwind_add_work_item(quicwind_work_item_enum item_type,
    int sel_cid, char const * name, char const *port_number, char const * doc_name, char const * alpn, char const *sni)
{
    int ret = 0;
    DWORD w_ret = 0;
    quicwind_work_item_t * w = NULL;
    if (work_item_mutex == NULL) {
        AppendText(_T("Background thread is not ready.\r\n"));
        ret = -1;
    }
    else {
        w = (quicwind_work_item_t *)malloc(sizeof(quicwind_work_item_t));
        if (w == NULL) {
            AppendText(_T("Out of memory.\r\n"));
            ret = -1;
        }
        else {
            w->next = NULL;
            w->item_type = item_type;
            w->sel_cid = sel_cid;
            w->name[0] = 0;
            w->port[0] = 0;
            w->doc[0] = 0;
            w->alpn[0] = 0;
            w->sni[0] = 0;
            if (ret == 0 && name != NULL) {
                ret = memcpy_s(w->name, sizeof(w->name), name, sizeof(w->name));
            }
            if (ret == 0 && port_number != NULL) {
                ret = memcpy_s(w->port, sizeof(w->port), port_number, sizeof(w->port));
            }
            if (ret == 0 && doc_name != NULL) {
                ret = memcpy_s(w->doc, sizeof(w->doc), doc_name, sizeof(w->doc));
            }
            if (ret == 0 && alpn != NULL) {
                ret = memcpy_s(w->alpn, sizeof(w->alpn), alpn, sizeof(w->alpn));
            }
            if (ret == 0 && sni != NULL) {
                ret = memcpy_s(w->sni, sizeof(w->sni), sni, sizeof(w->sni));
            }
            if (ret != 0) {
                AppendText(_T("Cannot copy the work item.\r\n"));
            } else {
                w_ret = WaitForSingleObject(work_item_mutex, 1000);
                switch (w_ret) {
                case WAIT_OBJECT_0: {
                    quicwind_work_item_t * next = work_item_first;
                    quicwind_work_item_t * last = NULL;
                    while (next) {
                        last = next;
                        next = next->next;
                    }
                    if (last) {
                        last->next = w;
                    }
                    else {
                        work_item_first = w;
                    }
                    if (!ReleaseMutex(work_item_mutex)) {
                        AppendText(_T("Cannot release the work item mutex.\r\n"));
                    }
                    quicwind_wake_up_network();
                    break;
                }
                default:
                    AppendText(_T("Cannot obtain the work item mutex.\r\n"));
                    ret = -1;
                    break;
                }
            }
            if (ret != 0) {
                free(w);
            }
        }
    }
    return ret;
}
int quicwind_add_work_item ( quicwind_work_item_enum item_type , int sel_cid , char const * name , char const * port_number , char const * doc_name , char const * alpn , char const * sni ) { int ret = 0 ; DWORD w_ret = 0 ; quicwind_work_item_t * w = NULL ; if ( work_item_mutex == NULL ) { AppendText ( _T ( " \r \n " ) ) ; ret = -1 ; } else { w = ( quicwind_work_item_t * ) malloc ( sizeof ( quicwind_work_item_t ) ) ; if ( w == NULL ) { AppendText ( _T ( " \r \n " ) ) ; ret = -1 ; } else { w -> next = NULL ; w -> item_type = item_type ; w -> sel_cid = sel_cid ; w -> name [ 0 ] = 0 ; w -> port [ 0 ] = 0 ; w -> doc [ 0 ] = 0 ; w -> alpn [ 0 ] = 0 ; w -> sni [ 0 ] = 0 ; if ( ret == 0 && name != NULL ) { ret = memcpy_s ( w -> name , sizeof ( w -> name ) , name , sizeof ( w -> name ) ) ; } if ( ret == 0 && port_number != NULL ) { ret = memcpy_s ( w -> port , sizeof ( w -> port ) , port_number , sizeof ( w -> port ) ) ; } if ( ret == 0 && doc_name != NULL ) { ret = memcpy_s ( w -> doc , sizeof ( w -> doc ) , doc_name , sizeof ( w -> doc ) ) ; } if ( ret == 0 && alpn != NULL ) { ret = memcpy_s ( w -> alpn , sizeof ( w -> alpn ) , alpn , sizeof ( w -> alpn ) ) ; } if ( ret == 0 && sni != NULL ) { ret = memcpy_s ( w -> sni , sizeof ( w -> sni ) , sni , sizeof ( w -> sni ) ) ; } if ( ret != 0 ) { AppendText ( _T ( " \r \n " ) ) ; } else { w_ret = WaitForSingleObject ( work_item_mutex , 1000 ) ; switch ( w_ret ) { case WAIT_OBJECT_0 : { quicwind_work_item_t * next = work_item_first ; quicwind_work_item_t * last = NULL ; while ( next ) { last = next ; next = next -> next ; } if ( last ) { last -> next = w ; } else { work_item_first = w ; } if ( ! ReleaseMutex ( work_item_mutex ) ) { AppendText ( _T ( " \r \n " ) ) ; } quicwind_wake_up_network ( ) ; break ; } default : AppendText ( _T ( " \r \n " ) ) ; ret = -1 ; break ; } } if ( ret != 0 ) { free ( w ) ; } } } return ret ; }
Add a message to the work queue
Add a message to the work queue