Exemple #1
0
U_THREAD_PROC(pping_server_cli_thread_proc, arg)
{
    if (uThreadBlockAllSignals(NULL) != 0)
        d_printf1("Failed to block signals for SSMMsg_server_proc");

    pping_server *pps = ((pping_serv_arg*)arg)->pps;
    USOCKET sock = ((pping_serv_arg*)arg)->sock;
    int component = ((pping_serv_arg*)arg)->pps->component;
    delete ((pping_serv_arg*)arg);

    char c = PPING_DISCONNECT_MSG;
    while (true)
    {
        if (urecv(sock, &c, sizeof(c), NULL) != sizeof(c)) goto sys_failure;
        if (c == PPING_DISCONNECT_MSG) break;
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
        if (c == PPING_PROC_EXCEPTION_MSG)
        {
            if (client_exception_handler(sock, pps) != 1) return 0;
            continue;
        }
#endif
        if (c != PPING_KEEP_ALIVE_MSG) goto sys_failure;
    }

    //d_printf1("pping_server's client is closed\n");
    if (uclose_socket(sock, NULL) == U_SOCKET_ERROR) goto sys_failure;

    return 0;

sys_failure:
    sedna_soft_fault("One of SEDNA processes is down", component);

    return 0;
}
Exemple #2
0
unsigned int __stdcall ulisten(PVOID pM)
#endif // _WIN32
{
    while(!state.exiting)
        if((i=urecv(sock))>0)
        {
            if(state.verbose)
                    printf("%d bytes recv\n",i);
        }
        else
            fprintf(stderr,"error receiving\n");
#if defined(__linux__) || defined(__MACH__)
    pthread_exit(NULL);
    return NULL;
#endif
#ifdef _WIN32
    return 0;
#endif // _WIN32
}
Exemple #3
0
U_THREAD_PROC(pping_client_thread_proc, arg)
{
    if (uThreadBlockAllSignals(NULL) != 0)
        d_printf1("Failed to block signals for pping_client_thread_proc");

    pping_client *ppc = (pping_client*)arg;
    char c = PPING_KEEP_ALIVE_MSG;

    while (true)
    {
        if (ppc->stop_keep_alive) return 0;

        int res = usend(ppc->sock, &c, sizeof(c), NULL);

        if (res != sizeof(c) && !ppc->stop_keep_alive) {
            sedna_soft_fault("SEDNA GOVERNOR is down", ppc->component);
        }

        /* se_stop -hard has been called? */
        if(ppc->signaled_flag    != NULL  &&
                GOV_HEADER_GLOBAL_PTR != NULL  &&
                GOV_HEADER_GLOBAL_PTR -> is_server_stop == SE_STOP_HARD)
        {
            *(ppc->signaled_flag) = true;
        }

        UUnnamedSemaphoreDownTimeout(&(ppc->sem), 1000, NULL);

        if(ppc->timeout)
        {

            if (!ppc->counter && !ppc->reset_flag) {
                *(ppc->signaled_flag) = true;
                ppc->counter = ppc->timeout;
            }

            if(ppc->reset_flag)
            {
                ppc->counter = ppc->timeout;
                if(ppc->signaled_flag) *(ppc->signaled_flag) = false;
                ppc->reset_flag = false;
            }

            (ppc->counter)--;
        }
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
#define SENDVAR(v) if (usend(ppc->sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) continue;
#ifdef _WIN32
        if (ppc->exceptPtrs)
        {
            //TODO: do something if usend/urecv fails or get wrong msg
            char cc = PPING_PROC_EXCEPTION_MSG;
            DWORD proc_id = GetCurrentProcessId();

            if (usend(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc))
            {
                ppc->exceptPtrs = NULL;
                continue;
            }

            SENDVAR(proc_id)
            SENDVAR(ppc->component);
            SENDVAR(ppc->except_thread_id);
            SENDVAR(ppc->exceptPtrs);

            if (urecv(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc))
            {
                ppc->exceptPtrs = NULL;
                continue;
            }
            if (cc != PPING_PROC_EXCEPTION_MSG)
            {
                ppc->exceptPtrs = NULL;
                continue;
            }

            if (ppc->stacktrace_fh != U_INVALID_FD)
            {
                if (StackTraceInit() != 0)
                {
                    StackTraceWriteFd(ppc->exceptPtrs->ContextRecord, (intptr_t)ppc->stacktrace_fh, 9999, 0);

                    StackTraceDeinit();
                }
                uCloseFile(ppc->stacktrace_fh, NULL);
            }


            ppc->exceptPtrs = NULL;
        }
#endif
#undef SENDVAR
#endif
    }
    return 0;
}
Exemple #4
0
/* Single threaded version of pping server.
 * Uses select() to create connections and serve
 * previously created as well.
 *
 * TODO: read all buffer at once
 * TODO: better failures diagnostric
 * TODO: place accept+uNotInherit into a critical section to prevent
 *       descriptors inheritance on fork
 *
 */
U_THREAD_PROC(pping_server_lstn_thread_proc_st, arg)
{
    if (uThreadBlockAllSignals(NULL) != 0)
        d_printf1("Failed to block signals for pping server thread.");

    U_SSET allset, rset;
    pping_server *pps = (pping_server*)arg;
    int res;
    char c = PPING_DISCONNECT_MSG;
    bool maxfd_valid = true;
    USOCKET client_sock, maxfd, i;

    U_SSET_ZERO(&allset);
    U_SSET_SET(pps->sock, &allset);
    maxfd = pps->sock + 1;

    while (true)
    {
        rset = allset;
        res  = uselect_read_arr(&rset, maxfd, NULL, NULL);
        if (res == U_SOCKET_ERROR) {
            SYS_FAILURE_SERVER("Failure in pping server (select() call failed).");
        }

        /* Iterate through ready to read client descriptors */
        for (i = 0; i < maxfd; i++)
        {
            if(U_SSET_ISSET(i, &rset) && i != pps->sock)
            {
                res = urecv(i, &c, sizeof(c), NULL);
                if( res != sizeof(c) ) {
                    SYS_FAILURE_SERVER("Failure in pping server (recv() call failed, one of the clients may be down).");
                }
                if (c == PPING_DISCONNECT_MSG)
                {
                    U_SSET_CLR(i, &allset);
                    if(uclose_socket(i, NULL) == U_SOCKET_ERROR)
                        SYS_FAILURE_SERVER("Failure in pping server (cannot close a socket descriptor on disconnect).");
                    if ( maxfd-1 == i )
                        maxfd_valid = false;
                }
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
                else if (c == PPING_PROC_EXCEPTION_MSG) {
                    if (client_exception_handler(i, pps) != 1) return 0;
                }
#endif
                else if (c != PPING_KEEP_ALIVE_MSG)
                    SYS_FAILURE_SERVER("Failure in pping server (unexpected message from client).");
            }
        }

        /* Renew maximum descriptor number */
        if( !maxfd_valid )
        {
            for (i = maxfd-1; i >= 0; i--)
            {
                if(U_SSET_ISSET(i, &allset))
                {
                    maxfd = i + 1;
                    maxfd_valid = true;
                    break;
                }
            }
        }

        /* Create a new connection */
        if (U_SSET_ISSET(pps->sock, &rset))
        {
            client_sock = uaccept(pps->sock, NULL);

            if(client_sock == U_INVALID_SOCKET)
                SYS_FAILURE_SERVER("Failure in pping server (accept() call failed).");

            U_SSET_SET(client_sock, &allset);
            if (client_sock > maxfd-1) {
                maxfd = client_sock + 1;
            }

            /* Check if governor wants to shutdown us */
            if (pps->close_lstn_thread)
            {
                for (i = 0; i < maxfd; i++)
                {
                    if(U_SSET_ISSET(i, &allset) &&
                            i != pps->sock &&
                            uclose_socket(i, NULL) == U_SOCKET_ERROR)
                        SYS_FAILURE_SERVER("Failure in pping server (cannot close a socket descriptor).");
                }
                break;
            }

            /* Make the client descriptor unheritable */
            if (uNotInheritDescriptor(UHANDLE(client_sock), NULL) != 0)
                SYS_FAILURE_SERVER("Failure in pping server (cannot make a socket descriptor unheritable).");
        }
    }
    return 0;
}