void *server_thr(void *arg) {
    int       ferr;
    int       lerr;
    int       max_msgs = gmaxc * gloop;
    bool      mon_msg;
    Test_SRE  sre;
    int       status;
    int       whoami = ginxs++;

    arg = arg; // touch
    for (;;) {
        if (gsre_count >= max_msgs)
            break;
        if (gshutdown)
            break;
        do {
            lerr = XWAIT(LREQ, 100);
            lerr = XMSG_LISTEN_((short *) &sre.sre,  // sre
                                0,                   // listenopts
                                0);                  // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        mon_msg = (sre.sre.sre_flags & XSRE_MON);
        if (mon_msg) {
            int msg_size = sre.sre.sre_reqDataSize;
            char *msg = new char[msg_size];
            ferr = XMSG_READDATA_(sre.sre.sre_msgId,     // msgid
                                  msg,                   // reqdata
                                  (ushort) msg_size);    // bytecount
            assert(ferr == XZFIL_ERR_OK);
            pp_check_mon_msg(msg);
            pp_check_mon_msg_shutdown(msg);
            XMSG_REPLY_(sre.sre.sre_msgId,   // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            delete [] msg;
            if (gshutdown)
                break;
        } else {
            status = gmutex.lock();
            TEST_CHK_STATUSOK(status);
            gsre_count++;
            status = gmutex.unlock();
            TEST_CHK_STATUSOK(status);
            if (gverbose)
                printf("s-%d: have work, sre-count=%d\n",
                       whoami, gsre_count);
            server(whoami, &sre);
        }
    }
    return NULL;
}
Beispiel #2
0
void *server_thr(void *arg) {
    int       lerr;
    int       max_msgs = maxcp * maxc * loop;
    Test_SRE  sre;
    Test_SRE *srep;
    int       status;
    int       whoami = inxs++;

    arg = arg; // touch
    for (;;) {
        if (thrlisten) {
            sre.fin = false;
            if (sre_count >= max_msgs)
                break;
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = XMSG_LISTEN_((short *) &sre.sre,  // sre
                                    0,                   // listenopts
                                    0);                  // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            status = mutex.lock();
            TEST_CHK_STATUSOK(status);
            sre_count++;
            status = mutex.unlock();
            TEST_CHK_STATUSOK(status);
            srep = &sre;
        } else
            srep = (Test_SRE *) work_q.remove();
        if (verbose)
            printf("s-%d: have work, fin=%d\n", whoami, srep->fin);
        if (srep->fin)
            break;
        server(whoami, srep);
        if (!thrlisten)
            free_q.add(&srep->link);
    }
    return NULL;
}
void *thread_send(void *arg) {
    bool            end;
    int             ferr;
    int             inx;
    char            lwho[BUFSIZ];
    int             msgid;
    char           *name;
    RT              results;
    Util_AA<char>   send_buffer(40000);
    int             status;
    int             thrinx;

    end = (arg == NULL);
    if (end)
        thrinx = -1;
    else {
        name = SB_Thread::Sthr::self_name();
        thrinx = atoi(name);
    }
    sprintf(lwho, "client-%d", thrinx);
    for (inx = 0; inx < loop; inx++) {
        sprintf(&send_buffer, "hello, greetings from %s-%d, inx=%d",
                my_name, thrinx, inx);
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          &send_buffer,                // reqdata
                          end ?                        // reqdatasize
                         (ushort) 0 : (ushort) 39000,
                          recv_buffer,                 // replydata
                          40000,                       // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          XMSG_LINK_LDONEQ);           // linkopts
        assert((ferr != XZFIL_ERR_NOBUFSPACE) &&
               (ferr != XZFIL_ERR_PATHDOWN));
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        if (verbose) {
            printf("%s - BREAK returned err=%d\n", lwho, ferr);
            if (ferr == XZFIL_ERR_OK)
                printf("%s - rcvd=%s\n", lwho, recv_buffer);
        }
        if (ferr != XZFIL_ERR_OK) {
            static SB_Thread::Mutex mutex;
            if (mutex.trylock() == 0) { // got lock
                restart_server();
                status = mutex.unlock();
                TEST_CHK_STATUSOK(status);
            } else
                SB_Thread::Sthr::sleep(100); // 100 ms
            inx--;
            continue;
        } else if (end)
            break;
    }
    return NULL;
}