Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    bool done = false;
    int  ferr;
    int  recvbuf[3];

    sprintf(gprog, "%s/%s", getenv("PWD"), argv[0]);
    ferr = msfs_util_init_role(false, &argc, &argv, msg_debug_hook);
    assert(ferr == XZFIL_ERR_OK);
    ferr = msg_mon_process_startup(true); // system messages
    assert(ferr == XZFIL_ERR_OK);
    ferr = msg_mon_get_my_process_name(gname, sizeof(gname));
    assert(ferr == XZFIL_ERR_OK);
    msg_mon_enable_mon_messages(true); // get mon messages
    gargc = argc; // after msg_init - it removes args
    gargp = argv;

    if (is_backup()) {
        strcpy(gdisplay_name, gname);
        strcat(gdisplay_name, "-B");
        myprintf("We are the backup process.\n");
        gim_backup = true;
        while (!gtakeover) {
            int len = sizeof(recvbuf);
            ferr = checkpoint(recvbuf, &len);
            if (ferr == XZFIL_ERR_OK)
                process_request(recvbuf);
        }
        myprintf("The backup is now the primary process.\n");
        strcpy(gdisplay_name, gname);
        strcat(gdisplay_name, "-P");
    } else {
        strcpy(gdisplay_name, gname);
        strcat(gdisplay_name, "-P");
        myprintf("We are the primary process.\n");
    }
    start_backup(-1);

    while (!done) {
        int len = sizeof(recvbuf);
        if (!recv(recvbuf, &len)) {
            done = process_request(recvbuf);
            checkpoint(recvbuf, &len);
        }
    }

    ferr = msg_mon_process_close();
    TEST_CHK_FEOK(ferr);

    if (gpeer_nid >= 0) {
        myprintf("stopping backup.\n");
        ferr = msg_mon_stop_process((char*)"", gpeer_nid, gpeer_pid);
        TEST_CHK_FEOK(ferr);
    }
    myprintf("sending exit process message.\n");
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
    bool      client = false;
    int       ferr;
    char      my_name[BUFSIZ];
    int       oid;
    TPT_DECL (phandle);
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msg_mon_enable_mon_messages(true);
    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(true);           // system messages
    TEST_CHK_FEOK(ferr);
    // process-wait for client/server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 3, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        do_readmsg(); // open message
    } else {
        do_readmsg(); // open message
        ferr = msg_mon_open_process((char *) "$cli",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
        printf("if there were no asserts, all is well\n");
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
    int     exit = false;
    int     err;
    int     ferr;
    int     len;
    char    recv_buffer[BUFSIZ];
    BMS_SRE sre;

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);

    for (;;) {
        do {
            err = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(err);
            err = BMSG_LISTEN_((short *) &sre, // sre
                               0,              // listenopts
                               0);             // listenertag
        } while (err == BSRETYPE_NOWORK);
        ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        TEST_CHK_FEOK(ferr);
        if ((sre.sre_flags & BSRE_MON)) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            if (msg->type == MS_MsgType_Close)
                exit = true;
        }
        strcat(recv_buffer, "- reply from server");
        len = (int) strlen(recv_buffer) + 1;
        BMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    recv_buffer,         // replydata
                    len,                 // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
        if (exit)
            break;
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
    int     exit;
    int     ferr;
    int     lerr;
    char    name[BUFSIZ];
    char    recv_buffer[BUFSIZ];
    MS_SRE  sre;

    msfs_util_init_role(false, &argc, &argv, msg_debug_hook);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(name, sizeof(name));
    TEST_CHK_FEOK(ferr);
    exit = 0;
    while (!exit) {
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        util_check("XMSG_READDATA_", ferr);
        if (sre.sre_flags & XSRE_MON) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            printf("srv %s: mon message, type=%d\n", name, msg->type);
            if (msg->type == MS_MsgType_Close)
                exit = 1;
        } else {
            printf("srv %s: NON-mon message\n", name);
        }
        XMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    NULL,                // replydata
                    0,                   // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
    }
    printf("server %s shutting down\n", name);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Exemplo n.º 5
0
//
// server main
//
int main(int pv_argc, char *pa_argv[]) {
    bool     lv_done;
    int      lv_ferr;
    int      lv_lerr;
    BMS_SRE  lv_sre;

    CALL_COMP_DOVERS(idtmsrv, pv_argc, pa_argv);

    do_init(pv_argc, pa_argv);

    lv_ferr = msg_mon_process_startup(true); // system messages
    assert(lv_ferr == XZFIL_ERR_OK);
    msg_mon_enable_mon_messages(true);
    lv_ferr = msg_mon_get_my_process_name(ga_name, sizeof(ga_name));
    assert(lv_ferr == XZFIL_ERR_OK);

    do_shm();
    lv_ferr = timer_start_cb(gv_time_refresh_delay, 0, 0, &gv_tleid, &timer_callback);
    assert(lv_ferr == XZFIL_ERR_OK);

    lv_done = false;
    while (!lv_done) {
        do {
            lv_lerr = XWAIT(LREQ, -1);
            lv_lerr = BMSG_LISTEN_((short *) &lv_sre, // sre
                                   0,                 // listenopts
                                   0);                // listenertag
        } while (lv_lerr == XSRETYPE_NOWORK);
        if (lv_sre.sre_flags & XSRE_MON) {
            do_mon_msg(&lv_sre, &lv_done);
        } else {
            do_req(&lv_sre);
        }
    }

    if (gv_verbose)
        printf("server %s shutting down\n", ga_name);
    lv_ferr = msg_mon_process_shutdown();
    assert(lv_ferr == XZFIL_ERR_OK);

    return 0;
}
Exemplo n.º 6
0
//
// server main
//
int main(int argc, char *argv[]) {
    bool     done;
    int      ferr;
    int      lerr;
    BMS_SRE  sre;

    do_init(argc, argv);

    ferr = msg_mon_process_startup(true); // system messages
    assert(ferr == XZFIL_ERR_OK);
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(name, sizeof(name));
    assert(ferr == XZFIL_ERR_OK);

    do_shm();

    done = false;
    while (!done) {
        do {
            lerr = XWAIT(LREQ, -1);
            lerr = BMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        if (sre.sre_flags & XSRE_MON) {
            do_mon_msg(&sre, &done);
        } else {
            do_req(&sre);
        }
    }

    if (verbose)
        printf("server %s shutting down\n", name);
    ferr = msg_mon_process_shutdown();
    assert(ferr == XZFIL_ERR_OK);
    return 0;
}
Exemplo n.º 7
0
int main(int argc, char *argv[]) {
    int        csize = 0;
    int        dinx;
    int        dloop = MAX_OUT;
    int        dsize = MAX_DBUF;
    int        ferr;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        inx;
    int        lerr;
    int        loop = 10;
    int        max;
    int        maxsp = 1;
    int        msgids[MAX_SERVERS * MAX_OUT];
    int        oid;
    int        pinx;
    short     *reqctrl;
    char      *reqdata;
    short     *repctrl;
    char      *repdata;
    RT         results;
    MS_SRE     sre;
    bool       verbose = false;
    int        xinx;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-csize",     TA_Int,  MAX_CBUF,    &csize     },
      { "-dloop",     TA_Int,  MAX_OUT,     &dloop     },
      { "-dsize",     TA_Int,  MAX_DBUF,    &dsize     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp     },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (maxcp < 0)
        maxcp = 1;
    if (maxsp < 0)
        maxsp = 1;
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (!client)
        msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    TEST_CHK_FEOK(ferr);

    // process-wait for clients/servers/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic,
                                        maxcp + maxsp + 1,
                                        NULL,
                                        verbose);
    TEST_CHK_FEOK(ferr);
    sleep(3); // wait for all process_count's to complete
    if (client) {
        pinx = atoi(&my_name[4]);
        assert(pinx >= 0);
        printf("loop=%d\n", loop);
        for (inx = 0; inx < loop; inx++) {
            for (pinx = 0; pinx < maxsp; pinx++) {
                sprintf(serv, "$srv%d", pinx);
                ferr = msg_mon_open_process(serv,
                                            TPT_REF2(phandle,pinx),
                                            &oid);
                TEST_CHK_FEOK(ferr);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                for (dinx = 0; dinx < dloop; dinx++) {
                    xinx = pinx * maxsp + dinx;
                    reqctrl = &send_buffer2[xinx * csize];
                    repctrl = &recv_buffer3[xinx * csize];
                    reqdata = &send_buffer[xinx * dsize];
                    repdata = &recv_buffer[xinx * dsize];
                    ferr = XMSG_LINK_(TPT_REF2(phandle,pinx), // phandle
                                      &msgids[xinx],          // msgid
                                      reqctrl,                // reqctrl
                                      (short) csize,          // reqctrlsize
                                      repctrl,                // replyctrl
                                      (short) csize,          // replyctrlmax
                                      reqdata,                // reqdata
                                      (short) dsize,          // reqdatasize
                                      repdata,                // replydata
                                      (short) dsize,          // replydatamax
                                      0,                      // linkertag
                                      0,                      // pri
                                      0,                      // xmitclass
                                      0);                     // linkopts
                    util_check("XMSG_LINK_", ferr);
                }
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                for (dinx = 0; dinx < dloop; dinx++) {
                    xinx = pinx * maxsp + dinx;
                    ferr = XMSG_BREAK_(msgids[xinx],
                                       results.u.s,
                                       TPT_REF2(phandle,pinx));
                    util_check("XMSG_BREAK_", ferr);
                    assert((int) results.u.t.ctrl_size == csize);
                    assert((int) results.u.t.data_size == dsize);
                    assert(results.u.t.errm == RT_DATA_RCVD); // data
                }
                if (verbose)
                    printf("%s-open-count=%d\n", my_name, inx);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
                TEST_CHK_FEOK(ferr);
                if (verbose)
                    printf("%s-close-count=%d\n", my_name, inx);
            }
        }
    } else {
        max = 2 * maxcp * loop + maxcp * dloop * loop;
        for (inx = 0; inx < max; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,        // msgid
                                  recv_buffer2,         // reqctrl
                                  sre.sre_reqCtrlSize); // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,        // msgid
                                  recv_buffer,          // reqdata
                                  sre.sre_reqDataSize); // bytecount
            util_check("XMSG_READDATA_", ferr);
            XMSG_REPLY_(sre.sre_msgId,         // msgid
                        recv_buffer2,          // replyctrl
                        sre.sre_reqCtrlSize,   // replyctrlsize
                        recv_buffer,           // replydata
                        sre.sre_reqDataSize,   // replydatasize
                        0,                     // errorclass
                        NULL);                 // newphandle
            if (verbose)
                printf("%s-count=%d\n", my_name, inx);
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 8
0
int main(int argc, char *argv[]) {
    bool    client = false;
    int     count;
    int     ferr;
    int     inx;
    int     len;
    int     lerr;
    char    my_name[BUFSIZ];
    int     next;
    char    recv_buffer[BUFSIZ];
    short   recv_buffer2[BUFSIZ];
    MS_SRE  sre;

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);

    for (count = 0; count < 2; count++) {
        next = 0;
        for (inx = 0;; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                printf("tse received mon message, type=%d\n",
                       msg->type);
                switch (msg->type) {
                case MS_MsgType_Close:
                    next = 1;
                    break;
                case MS_MsgType_Open:
                    break;
                default:
                    break;
                }
                len = 0;
            } else {
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            if (next)
                break;
        }
    }
    printf("tse shutting down\n");
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Exemplo n.º 9
0
int main(int argc, char *argv[]) {
    bool                client = false;
    int                 ferr;
    int                 inxl;
    int                 inxo;
    int                 inxs;
    int                 maxs = 2;
    int                 msgid[MAX_OUT];
    bool                mq = false;
    int                 oid;
    TPT_DECL           (phandle);
    void               *res;
    RT                  results;
    const char         *serv = "$srv";
    int                 status;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxout",    TA_Int,  MAX_OUT,     &maxout    },
      { "-maxs",      TA_Int,  MAX_THR_S,   &maxs      },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq        },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);

    if (client) {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     XMAX_SETTABLE_SENDLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        atomic_set(&msg_count, 0);
        for (inxl = 0; inxl < loop; inxl++) {
            ferr = msg_mon_open_process((char *) serv,       // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
            count = 0;
            for (inxo = 0; inxo < 2; inxo++) {
                ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                                  &msgid[inxo],            // msgid
                                  NULL,                    // reqctrl
                                  0,                       // reqctrlsize
                                  send_buffer2[inxo],      // replyctrl
                                  24,                      // replyctrlmax
                                  send_buffer[inxo],       // reqdata
                                  0,                       // reqdatasize
                                  recv_buffer[inxo],       // replydata
                                  BUFSIZ,                  // replydatamax
                                  0,                       // linkertag
                                  0,                       // pri
                                  0,                       // xmitclass
                                  0);                      // linkopts
                util_check("XMSG_LINK_", ferr);
                atomic_inc(&msg_count);
            }
            ferr = XMSG_ABANDON_(msgid[0]);
            util_check("XMSG_ABANDON_", ferr);
            ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                              &msgid[inxo],            // msgid
                              NULL,                    // reqctrl
                              0,                       // reqctrlsize
                              send_buffer2[inxo],      // replyctrl
                              24,                      // replyctrlmax
                              send_buffer[inxo],       // reqdata
                              0,                       // reqdatasize
                              recv_buffer[inxo],       // replydata
                              BUFSIZ,                  // replydatamax
                              0,                       // linkertag
                              0,                       // pri
                              0,                       // xmitclass
                              0);                      // linkopts
            util_check("XMSG_LINK_", ferr);
            atomic_inc(&msg_count);
            ferr = BMSG_BREAK_(msgid[inxo],
                               results.u.s,
                               TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            ferr = XMSG_ABANDON_(msgid[1]);
            util_check("XMSG_ABANDON_", ferr);
            if (maxout < 4)
                maxout = 4;
            for (inxo = 3; inxo < maxout; inxo++) {
                ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                                  &msgid[inxo],            // msgid
                                  NULL,                    // reqctrl
                                  0,                       // reqctrlsize
                                  send_buffer2[inxo],      // replyctrl
                                  60,                      // replyctrlmax
                                  send_buffer[inxo],       // reqdata
                                  120,                     // reqdatasize
                                  recv_buffer[inxo],       // replydata
                                  BUFSIZ,                  // replydatamax
                                  0,                       // linkertag
                                  0,                       // pri
                                  0,                       // xmitclass
                                  0);                      // linkopts
                util_check("XMSG_LINK_", ferr);
                atomic_inc(&msg_count);
                if (verbose)
                    printf("client(%s): msg-count=%d\n",
                           my_name, atomic_read(&msg_count));
                count++;
                ferr = BMSG_BREAK_(msgid[inxo],
                                   results.u.s,
                                   TPT_REF(phandle));
                util_check("XMSG_BREAK_", ferr);
            }
            if (mq) {
                if ((inxl % 100) == 0)
                    printf("client(%s): count=%d\n", my_name, inxl);
            }
        }
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        closes = 0;
        maxmsg = loop * maxout;
        atomic_set(&msg_count, 0);
        msg_mon_enable_mon_messages(true);
        for (inxs = 0; inxs < maxs; inxs++) {
            char lname[10];
            sprintf(lname, "s%d", inxs);
            thrs[inxs] = new MyThread(server_thr, lname, inxs);
        }
        for (inxs = 0; inxs < maxs; inxs++)
            thrs[inxs]->start();
        for (inxs = 0; inxs < maxs; inxs++) {
            status = thrs[inxs]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inxs);
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 10
0
int main(int argc, char *argv[], char *envp[])
{
	INITSRVRTRC

	CEE_status				sts = CEE_SUCCESS;
	SRVR_INIT_PARAM_Def		initParam;
	DWORD					processId;
	char					tmpString[128];
	char					tmpString2[32];
	char					tmpString3[512];
	CEECFG_Transport		transport;
	CEECFG_TcpPortNumber	portNumber;
	BOOL					retcode;
	IDL_OBJECT_def			srvrObjRef;
	CEECFG_TcpProcessName	TcpProcessName;
	int						TransportTrace = 0;

	CALL_COMP_DOVERS(ndcs,argc,argv);

try
{
	regZnodeName[0] = '\x0';
	zkHost[0] = '\x0';
	zkRootNode[0] = '\x0';

	// Initialize seabed
	int	sbResult;
	char buffer[FILENAME_MAX] = {0};
	bzero(buffer, sizeof(buffer));

	sbResult = file_init_attach(&argc, &argv, true, buffer);
	if(sbResult != XZFIL_ERR_OK){
		exit(3);
	}
	sbResult = file_mon_process_startup(true);
	if(sbResult != XZFIL_ERR_OK){
		exit(3);
	}
	msg_mon_enable_mon_messages(true);
}
catch(SB_Fatal_Excep sbfe)
{
	exit(3);
}

	sigset_t newset, oldset;
	sigemptyset(&newset);
	sigaddset(&newset,SIGQUIT);
	sigaddset(&newset,SIGTERM);
	sigprocmask(SIG_BLOCK,&newset,&oldset);

	processId = GetCurrentProcessId();

	 retcode = getInitParamSrvr(argc, argv, initParam, tmpString, tmpString3);
	retcode = TRUE;

	mxosrvr_init_seabed_trace_dll();
	atexit(mxosrvr_atexit_function);

	// +++ Todo: Duplicating calls here. Should try to persist in srvrGlobal
	MS_Mon_Process_Info_Type  proc_info;
	msg_mon_get_process_info_detail(NULL, &proc_info);
	myNid = proc_info.nid;
	myPid = proc_info.pid;
	myProcName = proc_info.process_name;

	char logNameSuffix[32];
	sprintf( logNameSuffix, "_%d_%d.log", myNid, myPid );
	CommonLogger::instance().initLog4cxx("log4cxx.trafodion.masterexe.config", logNameSuffix);

    if(retcode == FALSE )
   {
//LCOV_EXCL_START
      SendEventMsg(  MSG_SET_SRVR_CONTEXT_FAILED,
                           EVENTLOG_ERROR_TYPE,
                           processId,
                           ODBCMX_SERVER,
                           srvrObjRef,
                           2,
                           tmpString,
                           tmpString3);
      exit(0);
//LCOV_EXCL_STOP
   }

   GTransport.initialize();
   if(GTransport.error != 0 )
   {
//LCOV_EXCL_START
      SendEventMsg(  MSG_SET_SRVR_CONTEXT_FAILED,
                           EVENTLOG_ERROR_TYPE,
                           processId,
                           ODBCMX_SERVER,
                           srvrObjRef,
                           1,
                           GTransport.error_message);
      exit(0);
//LCOV_EXCL_STOP
   }
   chdir(GTransport.myPathname);

   initParam.srvrType = CORE_SRVR;

//LCOV_EXCL_START
   if (initParam.debugFlag & SRVR_DEBUG_BREAK)
   {
        volatile int done = 0;
        while (!done) {
          sleep(10);
        }
   }
//LCOV_EXCL_STOP

	char zkErrStr[2048];
	stringstream zk_ip_port;
//	zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);
	if( zkHost[0] == '\x0' && regZnodeName[0] == '\x0' )
	{
		sprintf(zkErrStr, "***** Cannot get Zookeeper properties or registered znode info from startup params");
		SendEventMsg(  MSG_SET_SRVR_CONTEXT_FAILED,
						   EVENTLOG_ERROR_TYPE,
						   processId,
						   ODBCMX_SERVER,
						   srvrObjRef,
						   1,
						   zkErrStr);
		// exit(1);

	}
	else
	{
		zk_ip_port << zkHost;
		sprintf(zkErrStr, "zk_ip_port is: %s", zk_ip_port.str().c_str());
		SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
					processId, ODBCMX_SERVER,
					srvrObjRef, 1, zkErrStr);
	}

	if (initParam.debugFlag & SRVR_DEBUG_BREAK)
		zkSessionTimeout = 600;

	zoo_deterministic_conn_order(1); // enable deterministic order
	zh = zookeeper_init(zk_ip_port.str().c_str(), watcher, zkSessionTimeout * 1000, &myid, 0, 0);
	if (zh == 0){
		sprintf(zkErrStr, "***** zookeeper_init() failed for host:port %s",zk_ip_port.str().c_str());
		SendEventMsg(  MSG_SET_SRVR_CONTEXT_FAILED,
						   EVENTLOG_ERROR_TYPE,
						   processId,
						   ODBCMX_SERVER,
						   srvrObjRef,
						   1,
						   zkErrStr);
		// exit(1);
	}

	bool found = false;
	int rc;
	stringstream ss;
	ss.str("");
	ss << zkRootNode << "/dcs/master";
	string dcsMaster(ss.str());
	Stat stat;
	int startPortNum = 0, portRangeNum;
	char masterHostName[MAX_HOST_NAME_LEN];
	char startPort[12], portRange[12], masterTS[24];
	struct String_vector children;
	children.count = 0;
	children.data = NULL;

	// Get the instance ID from registered node
	char *tkn;
	char tmpStr[256];
	strcpy( tmpStr,  regZnodeName );
	tkn = strtok(tmpStr, ":" );			
	if(tkn!=NULL)
		strcpy(hostname,tkn);
	tkn = strtok(NULL, ":" );
	if( tkn != NULL )
		strcpy( instanceId, tkn );
	tkn = strtok(NULL, ":" );
	if( tkn != NULL )
		strcpy( childId, tkn );
	else
		;	// +++ Todo handle error

	while(!found)
	{
		rc = zoo_exists(zh, dcsMaster.c_str(), 0, &stat);
		if( rc == ZNONODE )
			continue;
		else
		if( rc == ZOK )
		{
			rc = zoo_get_children(zh, dcsMaster.c_str(), 0, &children);
			if( children.count > 0 )
			{
				char zknodeName[2048];
				strcpy(zknodeName, children.data[0]);
				tkn = strtok(zknodeName, ":" );
				if( tkn != NULL )
					strcpy( masterHostName, tkn );

				tkn = strtok(NULL, ":" );
				if( tkn != NULL ) {
					strcpy( startPort, tkn );
					startPortNum = atoi(tkn);
				}

				tkn = strtok(NULL, ":" );
				if( tkn != NULL ) {
					strcpy( portRange, tkn );
					portRangeNum = atoi(tkn);
				}

				tkn = strtok(NULL, ":" );
				if( tkn != NULL )
					strcpy( masterTS, tkn );

				free_String_vector(&children);
				found = true;
			}
			else
				continue;
		}
		else	// error
		{
			sprintf(zkErrStr, "***** zoo_exists() for %s failed with error %d",dcsMaster.c_str(), rc);
			SendEventMsg(  MSG_SET_SRVR_CONTEXT_FAILED,
							   EVENTLOG_ERROR_TYPE,
							   processId,
							   ODBCMX_SERVER,
							   srvrObjRef,
							   1,
							   zkErrStr);
			break;
		}
	}

	// Initialize initparam to defaults
	initParam.transport = CEE_TRANSPORT_TCP;	// -T 3
	initParam.majorVersion = 3; 				// -V 3
	// Will need to remove $ZTC0 and NonStopODBC from below
	sprintf( initParam.asSrvrObjRef, "TCP:$ZTC0/%s:NonStopODBC", startPort);	// -A TCP:$ZTC0/52500:NonStopODBC
	// Will need to remove this after we get rid off all existing AS related processing
	sprintf( initParam.ASProcessName, "$MXOAS" );	// -AS $MXOAS
	// Will need to remove this after we get rid off all existing WMS related processing
	sprintf( initParam.QSProcessName, "$ZWMGR" );	// -QS $ZWMGR

	// moved this here from begining of the function
	BUILD_OBJECTREF(initParam.asSrvrObjRef, srvrObjRef, "NonStopODBC", initParam.portNumber);

	ss.str("");
	ss << zkRootNode << "/dcs/servers/registered";
	string dcsRegistered(ss.str());

	char realpath[1024];
	bool zk_error = false;

 	if( found )
	{
		sprintf(zkErrStr, "Found master node in Zookeeper");
		SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
					processId, ODBCMX_SERVER,
					srvrObjRef, 1, zkErrStr);

		found = false;
		while(!found)
		{
			rc = zoo_exists(zh, dcsRegistered.c_str(), 0, &stat);
			if( rc == ZNONODE )
				continue;
			else
			if( rc == ZOK )
			{
				int i;
				//This section is the original port finding mechanism.
				//All servers (the herd) start looking for any available port
				//between starting port number+2 through port range max.
				//This is mainly for backward compatability for DcsServers
				//that don't pass PORTMAPTOSECS and PORTBINDTOSECS param
				if(portMapToSecs == -1 && portBindToSecs == -1) {
					for(i = startPortNum+2; i < startPortNum+portRangeNum; i++) {
						if (GTransport.m_listener->verifyPortAvailable("SRVR", i))
							break;
					}

					if( i == startPortNum+portRangeNum )
					{
						zk_error = true;
						sprintf(zkErrStr, "***** No ports free");
						break;
					}
				} else {
					//This section is for new port map params, PORTMAPTOSECS and PORTBINDTOSECS,
					//passed in by DcsServer. DcsMaster writes the port map to data portion of
					//<username>/dcs/servers/registered znode. Wait PORTMAPTOSECS for port map
					//to appear in registered znode. When it appears read it and scan looking for
					//match of instance and child Id.
					long retryTimeout = 500;//.5 second
					long long timeout = JULIANTIMESTAMP();
					bool isPortsMapped = false;
					char *zkData = new char[1000000];
					int zkDataLen = 1000000;
					while(! isPortsMapped) {
						memset(zkData,0,1000000);
						rc = zoo_get(zh, dcsRegistered.c_str(), false, zkData, &zkDataLen, &stat);
						if( rc == ZOK && zkDataLen > 0 ) {
							sprintf(zkErrStr, "DCS port map = %s", zkData);
							SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
									processId, ODBCMX_SERVER,
									srvrObjRef, 1, zkErrStr);

							int myInstanceId = atoi(instanceId);
							int myChildId = atoi(childId);

							sprintf(zkErrStr, "Searching for my id (%d:%d) in port map",myInstanceId,myChildId);
							SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
									processId, ODBCMX_SERVER,
									srvrObjRef, 1, zkErrStr);

							char portMapInstanceId[8];
							char portMapChildId[8];
							char portMapPortNum[8];
							char* saveptr;
							char* token = strtok_r (zkData,":",&saveptr);
							while (token != NULL)
							{
								if( token != NULL )//instance Id
									strcpy( portMapInstanceId, token );
								token = strtok_r(NULL, ":",&saveptr);
								if( token != NULL )//child id
									strcpy( portMapChildId, token );
								token = strtok_r(NULL, ":",&saveptr);
								if( token != NULL )//port number
									strcpy( portMapPortNum, token );

								int currPortMapInstanceId = atoi(portMapInstanceId);
								int currPortMapChildId = atoi(portMapChildId);
								int currPortMapPortNum = atoi(portMapPortNum);

								if(myInstanceId == currPortMapInstanceId && myChildId == currPortMapChildId) {
									i = currPortMapPortNum;
									sprintf(zkErrStr, "Found my port number = %d in port map", i);
									SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
											processId, ODBCMX_SERVER,
											srvrObjRef, 1, zkErrStr);
									break;
								} else {
									token = strtok_r (NULL, ":",&saveptr);
								}
							}

							timeout = JULIANTIMESTAMP();
							bool isAvailable = false;
							while ( isAvailable == false ) {
								if (GTransport.m_listener->verifyPortAvailable("SRVR", i)) {
									isAvailable = true;
								} else {
									if((JULIANTIMESTAMP() - timeout) > (portBindToSecs * 1000000)) {
										sprintf(zkErrStr, "Port bind timeout...exiting");
										zk_error = true;
										break;
									} else {
										sprintf(zkErrStr, "Port = %d is already in use...retrying", i);
										SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
												processId, ODBCMX_SERVER,
												srvrObjRef, 1, zkErrStr);
										DELAY(retryTimeout);
									}
								}
							}

							isPortsMapped = true;

						} else {
							if((JULIANTIMESTAMP() - timeout) > (portMapToSecs * 1000000)) {
								sprintf(zkErrStr, "Port map read timeout...exiting");
								zk_error = true;
								break;
							} else {
								sprintf(zkErrStr, "Waiting for port map");
								SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE,
										processId, ODBCMX_SERVER,
										srvrObjRef, 1, zkErrStr);
								DELAY(retryTimeout);
								rc = zoo_exists(zh, dcsRegistered.c_str(), 0, &stat);
							}
						}
					}

					delete[] zkData;
				}

				initParam.portNumber = i;

				stringstream newpath;
				newpath.str("");
				newpath << dcsRegistered.c_str() << "/" << regZnodeName;
//				dcsRegisteredNode.str("");
//				dcsRegisteredNode << dcsRegistered.c_str() << "/" << regZnodeName;
				dcsRegisteredNode = newpath.str();

				ss.str("");
				ss << myPid;
				string pid(ss.str());

				ss.str("");
				ss << "STARTING"
				   << ":"
				   << JULIANTIMESTAMP()
				   << ":"
				   << ":"				// Dialogue ID
				   << myNid
				   << ":"
				   << myPid
				   << ":"
				   << myProcName.c_str()
				   << ":"			   		// Server IP address
				   << ":"					// Server Port
				   << ":"					// Client computer name
				   << ":"					// Client address
				   << ":"					// Client port
				   << ":"					// Client Appl name
				   << ":";

				regSrvrData = ss.str();

				rc = zoo_create(zh, dcsRegisteredNode.c_str(), regSrvrData.c_str(), regSrvrData.length(), &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, realpath, sizeof(realpath)-1);
				if( rc != ZOK )
				{
					zk_error = true;
					sprintf(zkErrStr, "***** zoo_create() failed with error %d", rc);
					break;
				}
				found = true;
			}
			else	// error
			{
				zk_error = true;
				sprintf(zkErrStr, "***** zoo_exists() for %s failed with error %d",dcsRegistered.c_str(), rc);
				break;
			}
		}
	}

	if( zk_error ) {
		SendEventMsg(  MSG_SET_SRVR_CONTEXT_FAILED,
					   EVENTLOG_ERROR_TYPE,
					   processId,
					   ODBCMX_SERVER,
					   srvrObjRef,
					   1,
					   zkErrStr);
		exit(1);
	}

//LCOV_EXCL_START
// when a server dies, the MXOAS sends message to CFG. CFG creates the MXOSRVR process
// and passess only one command line atribute: -SQL CLEANUP OBSOLETE VOLATILE TABLES
// It is for cleanup resources (volatile tables).
// Newly created MXOSRVR process executes CLEANUP OBSOLETE VOLATILE TABLES and exits.
   // (This process is not managed by AS!. It is only a helper.

	if (initParam.sql != NULL)
	{
      if (strncmp(initParam.sql, "SELECT COUNT", 12) == 0)
      {
         //You can specify a completion code with any positive value in a PROCESS_STOP_.
         //Negative completion codes are reserved for HP use.
         //Therefore negative codes will return as 1000 + abs(completionCode)
         short completionCode = -1;
         completionCode = SQL_EXECDIRECT_FETCH(&initParam);

         if (completionCode < 0)
            completionCode = 1000 + abs(completionCode);

#ifdef NSK_PLATFORM
         PROCESS_STOP_(,,,completionCode,,,,);
#else
		 /*
		  * TODO:
		  * need to revisit this logic to return a value via exit code
		  *
		  */
#endif
      }
      else
      {
Exemplo n.º 11
0
int main(int argc, char *argv[]) {
    int     exit = false;
    int     err;
    int     ferr;
    int     len;
    char    my_name[100];
    char    recv_buffer[BUFSIZ];
    BMS_SRE sre;
    bool    verbose = false;
    TAD     zargs[] = {
      { "-v",         TA_Bool, TA_NOMAX,    &verbose     },
      { "",           TA_End,  TA_NOMAX,    NULL         }
    };

    ferr = msg_init(&argc, &argv);
    arg_proc_args(zargs, false, argc, argv);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, (int) sizeof(my_name));
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);

    for (;;) {
        do {
            err = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(err);
            err = BMSG_LISTEN_((short *) &sre, // sre
                               0,              // listenopts
                               0);             // listenertag
        } while (err == BSRETYPE_NOWORK);
        ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        TEST_CHK_FEOK(ferr);
        if ((sre.sre_flags & BSRE_MON)) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            if (verbose)
                printf("server %s rcvd mon-msg %s (%d)\n",
                       my_name,
                       SB_get_label_ms_mon_msgtype(msg->type),
                       msg->type);
            if (msg->type == MS_MsgType_Close)
                exit = true;
        }
        strcat(recv_buffer, "- reply from server");
        len = (int) strlen(recv_buffer) + 1;
        BMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    recv_buffer,         // replydata
                    len,                 // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
        if (exit)
            break;
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Exemplo n.º 12
0
int main(int argc, char *argv[]) {
    int         arg;
    bool        chook = false;
    bool        client = false;
    int         ferr;
    int         inx;
    int         loop = 10;
    char        my_name[BUFSIZ];
    bool        nowait = false;
    int         nid;
    int         pid;
    char        prog[MS_MON_MAX_PROCESS_PATH];
    char        retname[BUFSIZ];
    char        server_name[30];
    int         server_nid;
    TPT_DECL   (server_phandle);
    int         server_pid;
    bool        shook = false;
    int         status;
    TAD         zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (chook && client)
        test_debug_hook("c", "c");
    if (shook && !client)
        test_debug_hook("s", "s");
    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    if (client)
        msg_mon_enable_mon_messages(true);
    util_test_start(client);
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_process_startup(client); // system messages
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_process_info(NULL, &nid, &pid);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, sizeof(my_name));
    TEST_CHK_FEOK(ferr);

    if (client) {
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        for (inx = 0; inx < loop; inx++) {
            sprintf(server_name, "$SRV%d", inx);
            server_nid = -1;
            if (nowait)
                ferr = msg_mon_start_process_nowait_cb(cb,                       // callback
                                                       prog,                     // prog
                                                       server_name,              // name
                                                       retname,                  // ret-name
                                                       argc,                     // argc
                                                       argv,                     // argv
                                                       MS_ProcessType_Generic,   // type
                                                       0,                        // priority
                                                       false,                    // debug
                                                       false,                    // backup
                                                       inx,                      // tag
                                                       &server_nid,              // nid
                                                       &server_pid,              // pid
                                                       NULL,                     // infile
                                                       NULL);                    // outfile
            else
                ferr = msg_mon_start_process(prog,                   // prog
                                             server_name,            // name
                                             NULL,                   // ret name
                                             argc,
                                             argv,
                                             TPT_REF(server_phandle),
                                             0,                      // open
                                             NULL,                   // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             0,                      // debug
                                             0,                      // backup
                                             &server_nid,            // nid
                                             &server_pid,            // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
            printf("process started, err=%d\n", ferr);
            TEST_CHK_FEOK(ferr);
            if (nowait) {
                status = cv.wait(true);
                TEST_CHK_STATUSOK(status);
            }
            wait_death();
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 13
0
int main(int argc, char *argv[]) {
    int                 abandon = 0;
    bool                client = false;
    int                 closes;
    int                 count;
    int                 count_abandon;
    int                 ferr;
    int                 inxl;
    int                 inxo;
    int                 inxs;
    int                 lerr;
    int                 loop = 10;
    int                 maxcp = 1;
    int                 maxout = 1;
    int                 maxsp = 1;
    int                 msgid[MAX_OUT];
    int                 msg_count;
    bool                mq = false;
    int                 oid;
    TPT_DECL2          (phandle, MAX_SRV);
    int                 recv_len;
    RT                  results;
    int                 send_len;
    char                serv[20];
    BMS_SRE             sre;
    bool                verbose = false;
    TAD                 zargs[] = {
      { "-abandon",   TA_Int,  TA_NOMAX,    &abandon   },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLI,     &maxcp     },
      { "-maxout",    TA_Int,  MAX_OUT,     &maxout    },
      { "-maxsp",     TA_Int,  MAX_SRV,     &maxsp     },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq        },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);

    if (client) {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     XMAX_SETTABLE_SENDLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        msg_count = 0;
        count_abandon = 0;
        for (inxl = 0; inxl < loop; inxl++) {
            for (inxs = 0; inxs < maxsp; inxs++) {
                sprintf(serv, "$srv%d", inxs);
                ferr = msg_mon_open_process((char *) serv,       // name
                                            TPT_REF2(phandle, inxs),
                                            &oid);
                TEST_CHK_FEOK(ferr);
            }
            count = 0;
            if (abandon)
                count_abandon = rnd(abandon);
            for (inxs = 0; inxs < maxsp; inxs++) {
                for (inxo = 0; inxo < maxout; inxo++) {
                    send_len = rnd(BUFSIZ);
                    ferr = BMSG_LINK_(TPT_REF2(phandle, inxs), // phandle
                                      &msgid[inxo],            // msgid
                                      NULL,                    // reqctrl
                                      0,                       // reqctrlsize
                                      NULL,                    // replyctrl
                                      0,                       // replyctrlmax
                                      send_buffer[inxo],       // reqdata
                                      send_len,                // reqdatasize
                                      recv_buffer[inxo],       // replydata
                                      BUFSIZ,                  // replydatamax
                                      0,                       // linkertag
                                      0,                       // pri
                                      0,                       // xmitclass
                                      0);                      // linkopts
                    util_check("XMSG_LINK_", ferr);
                }
            }
            for (inxs = 0; inxs < maxsp; inxs++) {
                for (inxo = 0; inxo < maxout; inxo++) {
                    msg_count++;
                    if (verbose)
                        printf("client(%s): msg-count=%d\n",
                               my_name, msg_count);
                    count++;
                    if (abandon && (count >= count_abandon)) {
                        if (verbose)
                            printf("client(%s): sending abandon, count=%d\n",
                                   my_name, count);
                        count_abandon = rnd(abandon);
                        count = 0;
                        ferr = XMSG_ABANDON_(msgid[inxo]);
                        util_check("XMSG_ABANDON_", ferr);
                    } else {
                        ferr = BMSG_BREAK_(msgid[inxo],
                                           results.u.s,
                                           TPT_REF2(phandle, inxs));
                        util_check("XMSG_BREAK_", ferr);
                    }
                }
            }
            if (mq) {
                if ((inxl % 100) == 0)
                    printf("client(%s): count=%d\n", my_name, inxl);
            }
        }
        for (inxs = 0; inxs < maxsp; inxs++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle, inxs));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        closes = 0;
        msg_count = 0;
        msg_mon_enable_mon_messages(true);
        // process requests
        for (;;) {
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            if (sre.sre_flags & XSRE_MON) {
                ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer[0], // reqdata
                                      BUFSIZ);        // bytecount
                util_check("XMSG_READDATA_", ferr);
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer[0];
                if (verbose)
                    printf("server(%s): mon-msg type=%d\n",
                           my_name, msg->type);
                if (msg->type == MS_MsgType_Close) {
                    closes++;
                    if (verbose)
                        printf("server(%s): closes=%d\n",
                               my_name, closes);
                }
            } else {
                msg_count++;
                if (verbose)
                    printf("server(%s): msg-count=%d\n",
                           my_name, msg_count);
            }
            recv_len = rnd(BUFSIZ);
            BMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        recv_buffer[0],      // replydata
                        recv_len,            // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            if (closes >= maxcp)
                break;
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 14
0
int main(int argc, char *argv[]) {
    bool      client = false;
    int       count;
    int       ferr;
    int       inx;
    int       lerr;
    int       loop = 10;
    int       msgid;
    int       oid;
    TPT_DECL (phandle);
    RT        results;
    MS_SRE    sre;
    BMS_SRE   sre_tb;
    MS_SRE    sre_tx;
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    } else
        msg_mon_enable_mon_messages(true); // need this
    util_gethostname(my_name, sizeof(my_name));

    for (inx = 0; inx < loop; inx++) {
        count = inx % 100;
        if (client) {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_bufferc,                // reqctrl
                              (short) count,               // reqctrlsize
                              recv_bufferc,                // replyctrl
                              (short) (count+1),           // replyctrlmax
                              send_buffer,                 // reqdata
                              (short) (count+2),           // reqdatasize
                              recv_buffer,                 // replydata
                              (short) (count+3),           // replydatamax
                              0,                           // linkertag
                              (short) count,               // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre_tx,     // sre
                                    XLISTEN_TEST_IREQM,    // listenopts
                                    0);                    // listenertag
                if (lerr == XSRETYPE_NOWORK)
                    continue;
                if (sre_tx.sre_flags & XSRE_MON) {
                    // toss out monitor messages
                    lerr = XMSG_LISTEN_((short *) &sre, // sre
                                        0,              // listenopts
                                        0);             // listenertag
                    assert(lerr == XSRETYPE_IREQ);
                    assert(sre_tx.sre_flags & XSRE_MON);
                    lerr = XSRETYPE_NOWORK;
                    XMSG_REPLY_(sre.sre_msgId,  // msgid
                                NULL,           // replyctrl
                                0,              // replyctrlsize
                                NULL,           // replydata
                                0,              // replydatasize
                                0,              // errorclass
                                NULL);          // newphandle
                    continue;
                }
                lerr = BMSG_LISTEN_((short *) &sre_tb,     // sre
                                    BLISTEN_TEST_IREQM,    // listenopts
                                    0);                    // listenertag
                assert(lerr == BSRETYPE_IREQ);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
                assert(lerr == XSRETYPE_IREQ);
            } while (lerr == XSRETYPE_NOWORK);

            assert(sre.sre_pri == count);
            assert(sre.sre_reqCtrlSize == count);
            assert(sre.sre_reqDataSize == (count + 2));
            assert(sre.sre_replyCtrlMax == (count + 1));
            assert(sre.sre_replyDataMax == (count + 3));

            assert(sre.sre_msgId == sre_tx.sre_msgId);
            assert(sre.sre_flags == sre_tx.sre_flags);
            assert(sre.sre_pri == sre_tx.sre_pri);
            assert(sre.sre_reqCtrlSize == sre_tx.sre_reqCtrlSize);
            assert(sre.sre_reqDataSize == sre_tx.sre_reqDataSize);
            assert(sre.sre_replyCtrlMax == sre_tx.sre_replyCtrlMax);
            assert(sre.sre_replyDataMax == sre_tx.sre_replyDataMax);

            assert(sre.sre_msgId == sre_tb.sre_msgId);
            assert(sre.sre_flags == sre_tb.sre_flags);
            assert(sre.sre_pri == sre_tb.sre_pri);
            assert(sre.sre_reqCtrlSize == sre_tb.sre_reqCtrlSize);
            assert(sre.sre_reqDataSize == sre_tb.sre_reqDataSize);
            assert(sre.sre_replyCtrlMax == sre_tb.sre_replyCtrlMax);
            assert(sre.sre_replyDataMax == sre_tb.sre_replyDataMax);

            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        0,              // replydatasize
                        0,              // errorclass
                        NULL);          // newphandle
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 15
0
int main(int argc, char *argv[]) {
    bool            exit;
    int             ferr;
    int             lerr;
    int             msgid;
    int             nid;
    int             oid;
    int             pid;
    TPT_DECL       (phandle);
    char            recv_buffer[BUFSIZ];
    short           recv_buffer2[BUFSIZ];
    MS_Result_Type  results;
    MS_SRE          sre;

    ferr = msfs_util_init_role(true, &argc, &argv, msg_debug_hook);
    TEST_CHK_FEOK(ferr);
    util_test_start(true);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);
    printf("cli: opening server\n");
    ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid);
    TEST_CHK_FEOK(ferr);
    printf("cli: server opened\n");
    ferr = msg_mon_open_process((char *) "$srv",      // name
                                TPT_REF(phandle),
                                &oid);
    TEST_CHK_FEOK(ferr);
    exit = false;
    while (!exit) {
        lerr = XWAIT(LREQ, -1);
        TEST_CHK_WAITIGNORE(lerr);
        for (;;) {
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            if (lerr == XSRETYPE_NOWORK)
                break;
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                printf("cli: mon message, type=%d\n", msg->type);
                if (msg->type == MS_MsgType_Open) {
                    ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid);
                    TEST_CHK_FEOK(ferr);
                    assert(msg->u.open.nid == nid);
                    assert(msg->u.open.pid == pid);
                    assert(strcasecmp(msg->u.open.target_process_name, "$srv") == 0);
                    exit = true;
                }
            } else {
                printf("cli: NON-mon message\n");
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }
    printf("cli: sending message to server\n");
    ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                      &msgid,                      // msgid
                      NULL,                        // reqctrl
                      0,                           // reqctrlsize
                      recv_buffer2,                // replyctrl
                      1,                           // replyctrlmax
                      NULL,                        // reqdata
                      0,                           // reqdatasize
                      recv_buffer,                 // replydata
                      BUFSIZ,                      // replydatamax
                      0,                           // linkertag
                      0,                           // pri
                      0,                           // xmitclass
                      0);                          // linkopts
    util_check("XMSG_LINK_", ferr);
    ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle));
    util_check("XMSG_BREAK_", ferr);
    exit = false;
    while (!exit) {
        lerr = XWAIT(LREQ, -1);
        for (;;) {
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            if (lerr == XSRETYPE_NOWORK)
                break;
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqctrl
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                printf("cli: mon message, type=%d\n", msg->type);
                if (msg->type == MS_MsgType_ProcessDeath) {
                    assert(msg->u.death.nid == nid);
                    assert(msg->u.death.pid == pid);
                    exit = true;
                }
            } else
                printf("cli: NON-mon message\n");
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(true);
    return 0;
}
Exemplo n.º 16
0
int main(int argc, char *argv[]) {
    char       cli[10];
    bool       closer;
    int        disable;
    int        event_len;
    int        ferr;
    int        inst = 0;
    int        inx;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        nid;
    int        oid;
    TPT_DECL  (phandle);
    int        pid;
    char       recv_buffer[30000];
    RT         results;
    char       send_buffer[10];
    MS_SRE     sre;
    TAD        zargs[] = {
      { "-client",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-inst",      TA_Int,  TA_NOMAX,    &inst      },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  TA_NOMAX,    &maxcp     },
      { "-maxs",      TA_Int,  TA_NOMAX,    &maxs      },
      { "-maxsp",     TA_Next, TA_NOMAX,    NULL       },
      { "-name",      TA_Next, TA_NOMAX,    NULL       },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(true);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, sizeof(my_name));
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);

    // process-wait for clients/shell
    // (needed so msg_mon_register_death_notification below works correctly)
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, maxcp, NULL, false);
    TEST_CHK_FEOK(ferr);
    sleep(1);

    if (verbose)
        printf("%s: inst=%d, maxcp=%d\n", my_name, inst, maxcp);
    closer = (inst == (maxcp -1));
    if (closer && (maxcp > 1)) {
        if (verbose)
           printf("%s: register-death-notifications\n", my_name);
        for (inx = 0; inx < (maxcp - 1); inx++) {
            sprintf(cli, "$c%d", inx);
            ferr = msg_mon_get_process_info(cli, &nid, &pid);
            TEST_CHK_FEOK(ferr);
            ferr = msg_mon_register_death_notification(nid, pid);
            TEST_CHK_FEOK(ferr);
        }
    }

    //
    // wait here until all clients sync-up
    // (needed so msg_mon_register_death_notification above works correctly)
    //
    ferr = msg_mon_event_send(-1,                         // nid
                              -1,                         // pid
                              MS_ProcessType_TSE,         // process-type
                              3,                          // event-id
                              0,                          // event-len
                              NULL);                      // event-data
    TEST_CHK_FEOK(ferr);
    for (inx = 0; inx < maxcp; inx++) {
        ferr = msg_mon_event_wait(3, &event_len, event_data);
        TEST_CHK_FEOK(ferr);
    }
    disable = msg_test_assert_disable();
    // check process-type range
    ferr = msg_mon_event_send(-1,                         // nid
                              -1,                         // pid
                              -1,                         // process-type
                              4,                          // event-id
                              0,                          // event-len
                              NULL);                      // event-data
    assert(ferr == XZFIL_ERR_BOUNDSERR);
    ferr = msg_mon_event_send(-1,                         // nid
                              -1,                         // pid
                              MS_ProcessType_SMS + 1,    // process-type
                              5,                          // event-id
                              0,                          // event-len
                              NULL);                      // event-data
    assert(ferr == XZFIL_ERR_BOUNDSERR);
    msg_test_assert_enable(disable);

    ferr = msg_mon_open_process((char *) "$srv",      // name
                                TPT_REF(phandle),
                                &oid);
    TEST_CHK_FEOK(ferr);
    for (inx = 0; inx < loop; inx++) {
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          send_buffer,                 // reqdata
                          1,                           // reqdatasize
                          recv_buffer,                 // replydata
                          0,                           // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        util_check("XMSG_LINK_", ferr);
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        util_check("XMSG_BREAK_", ferr);
    }
    if (closer) {
        inx = 0;
        while (inx < (maxcp - 1)) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            if (sre.sre_flags & XSRE_MON) {
                ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer,    // reqdata
                                      BUFSIZ);        // bytecount
                TEST_CHK_FEOK(ferr);
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                if (msg->type == MS_MsgType_ProcessDeath) {
                    if (verbose)
                       printf("%s: process death process=%s\n",
                              my_name, msg->u.death.process_name);
                    inx++;
                }
            }
            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        0,              // replydatasize
                        0,              // errorclass
                        NULL);          // newphandle
        }
        if (verbose)
           printf("%s: sending stop\n", my_name);
        for (inx = 0; inx < maxs; inx++) {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
        }
    }
    ferr = msg_mon_close_process(TPT_REF(phandle));
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(true);
    return 0;
}
Exemplo n.º 17
0
int main(int argc, char *argv[]) {
    bool       check = false;
    int        csize = -1;
    bool       client = false;
    int        dsize = MAX_BUF;
    int        ferr;
    int        inx;
    int        len;
    int        lerr;
    int        loop = 10;
    int        min_csize;
    int        min_dsize;
    int        max_csize = -1;
    int        max_dsize = -1;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    uint       result;
    RT         results;
    BMS_SRE    sre;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-check",     TA_Bool, TA_NOMAX,    &check     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-csize",     TA_Int,  MAX_BUF,     &csize     },
      { "-dsize",     TA_Int,  MAX_BUF,     &dsize     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcsize",  TA_Int,  MAX_BUF,     &max_csize },
      { "-maxdsize",  TA_Int,  MAX_BUF,     &max_dsize },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);

    if (check) {
        if (csize < 0)
            csize = 0;
        if (dsize == MAX_BUF)
            dsize = 0;
        min_csize = csize;
        min_dsize = dsize;
        min_csize = min_csize; // touch
        min_dsize = min_dsize; // touch
        if (client) {
            for (inx = 0; inx < MAX_BUF; inx++) {
                send_buffer[inx] = (char) inx; // cast
                send_buffer2[inx] = (short) inx; // cast
            }
        }
    } else
        min_csize = 0;
    for (inx = 0; inx < loop; inx++) {
        if (verbose)
            printf("client=%d, csize=%d, dsize=%d\n", client, csize, dsize);
        else if (check && (csize == min_csize))
            printf("client=%d, csize=%d, dsize=%d\n", client, csize, dsize);
        if (client) {
            if (check) {
                send_buffer[0] = (char) dsize; // cast
                send_buffer2[0] = (short) csize; // cast
                len = 0;
            } else {
                sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                        my_name, inx);
                len = (int) strlen(send_buffer) + 1; // cast
            }
            ferr = BMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              csize < 0 ?                  // reqctrlsize
                                (inx & 1) : csize,
                              recv_buffer3,                // replyctrl
                              csize < 0 ? 1 : csize,       // replyctrlmax
                              send_buffer,                 // reqdata
                              check ? dsize : len,         // reqdatasize
                              recv_buffer,                 // replydata
                              MAX_BUF,                     // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("BMSG_LINK_", ferr);
            ferr = BMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("BMSG_BREAK_", ferr);
            if (check)
                assert(results.u.t.ctrl_size == (uint) csize);
            else
                assert(results.u.t.ctrl_size == (uint) (csize < 0 ? (inx & 1) : csize));
            if (check)
                assert(results.u.t.data_size == (uint) dsize);
            else
                assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            if (check) {
                if (dsize)
                    result = RT_DATA_RCVD; // data
                else
                    result = 0x0; // no-data
                assert(results.u.t.errm == result);
                check_buf(send_buffer2, recv_buffer3, csize);
                check_buf(send_buffer, recv_buffer, dsize);
            } else {
                assert(results.u.t.errm == RT_DATA_RCVD); // data
                printf("%s\n", recv_buffer);
            }
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = BMSG_READCTRL_(sre.sre_msgId,          // msgid
                                  recv_buffer2,           // reqctrl
                                  sre.sre_reqCtrlSize);   // bytecount
            util_check("BMSG_READCTRL_", ferr);
            ferr = BMSG_READDATA_(sre.sre_msgId,        // msgid
                                  recv_buffer,          // reqdata
                                  sre.sre_reqDataSize); // bytecount
            util_check("BMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
            } else {
                if (!check) {
                    strcat(recv_buffer, "- reply from ");
                    strcat(recv_buffer, my_name);
                    len = (int) strlen(recv_buffer) + 1; // cast
                } else
                    len = 0;
            }
            BMSG_REPLY_(sre.sre_msgId,                     // msgid
                        recv_buffer2,                      // replyctrl
                        sre.sre_reqCtrlSize,               // replyctrlsize
                        recv_buffer,                       // replydata
                        check ? sre.sre_reqDataSize : len, // replydatasize
                        0,                                 // errorclass
                        NULL);                             // newphandle
            if (sre.sre_flags & XSRE_MON)
                continue;
        }
        if (check) {
            if (max_csize >= 0) {
                csize++;
                if (csize >= max_csize)
                    csize = min_csize;
            }
            if ((max_dsize >= 0) && (csize == min_csize))
                dsize++;
            if (dsize >= max_dsize) {
                printf("break client=%d, csize=%d, dsize=%d\n", client, csize, dsize);
                break;
            }
            if ((max_csize >= 0) || (max_dsize >= 0)) {
                inx--;
                continue;
            }
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 18
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        client_mon;
    int        cnid = -1;
    bool       commit_rcvd = false;
    int        cpid = -1;
    int        disable;
    bool       done = false;
    int        event_len;
    int        ferr;
    int        first;
    int        handle;
    int        inx;
    int        len;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        nid;
    bool       open_rcvd = false;
    int        orig_tag;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        pid;
    int        pinx;
    RT         results;
    int        send_len;
    MS_SRE     sre;
    int        status;
    bool       sync = false;
    bool       threaded = false;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-quiet",     TA_Bool, TA_NOMAX,    &quiet     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-sync",      TA_Bool, TA_NOMAX,    &sync      },
      { "-threaded",  TA_Bool, TA_NOMAX,    &threaded  },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    sleep(1); // wait for client to get into msg_mon_process_info
    ferr = msg_mon_get_my_process_name(pname, sizeof(pname));
    TEST_CHK_FEOK(ferr);
    if (strcasecmp(pname, "$tm0") == 0)
         tag = TAG0;
    else if (strcasecmp(pname, "$tm1") == 0)
         tag = TAG1;
    else
         tag = TAG2;
    ferr = msg_mon_get_process_info(NULL, &snid, &spid);
    TEST_CHK_FEOK(ferr);
    if (client) {
        char serv[BUFSIZ];
        for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
            sprintf(serv, "$tm%d", pinx);
            ferr = msg_mon_open_process(serv,         // name
                                        TPT_REF2(phandle,pinx),
                                        &oid[pinx]);
            TEST_CHK_FEOK(ferr);
        }
    } else {
        first = (strcasecmp(pname, "$tm0") == 0);
        disable = msg_test_assert_disable();
        ferr = msg_mon_tm_leader_set(&nid, &pid, lname);
        msg_test_assert_enable(disable);
        if (first) {
            TEST_CHK_FEOK(ferr);
        } else
            assert(ferr != XZFIL_ERR_OK);
        printf("leader is p-id=%d/%d, name=%s\n",
               nid, pid, lname);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    if (!client) {
        ferr = msg_mon_event_wait(1, &event_len, event_data);
        util_check("msg_mon_event_wait", ferr);
        ferr = msg_mon_tmsync_register(tmsync_cb);
        util_check("msg_mon_tmsync_register", ferr);
        if (sync) {
            char serv[BUFSIZ];
            for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
                sprintf(serv, "$tm%d", pinx);
                if (strcasecmp(serv, pname) != 0) {
                    ferr = msg_mon_open_process(serv,         // name
                                                TPT_REF2(phandle,pinx),
                                                &oid[pinx]);
                    TEST_CHK_FEOK(ferr);
                }
            }
            // at this point, we know everyone is registered
            // if everyone isn't registered, there will be an abort
            do_sync();
            if (threaded)
                do_sync_threaded();
        }
    }

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
                if (verbose)
                    printf("%s: sending message, pinx=%d, inx=%d\n",
                           pname, pinx, inx);
                ferr = XMSG_LINK_(TPT_REF2(phandle,pinx),      // phandle
                                  &msgid,                      // msgid
                                  send_buffer2,                // reqctrl
                                  (ushort) (inx & 1),          // reqctrlsize
                                  recv_buffer3,                // replyctrl
                                  1,                           // replyctrlmax
                                  send_buffer,                 // reqdata
                                  (ushort) send_len,           // reqdatasize
                                  recv_buffer,                 // replydata
                                  BUFSIZ,                      // replydatamax
                                  0,                           // linkertag
                                  0,                           // pri
                                  0,                           // xmitclass
                                  0);                          // linkopts
                util_check("XMSG_LINK_", ferr);
                ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF2(phandle,pinx));
                util_check("XMSG_BREAK_", ferr);
                assert(results.u.t.ctrl_size == (uint) (inx & 1));
                assert(results.u.t.data_size > (strlen(send_buffer) + 14));
                assert(results.u.t.errm == RT_DATA_RCVD); // data
                if (!quiet)
                    printf("%s\n", recv_buffer);
            }
        }
        for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        inx = 0;
        while (!done) {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            for (;;) {
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
                if (lerr == XSRETYPE_NOWORK)
                    break;
                ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                      recv_buffer2,   // reqctrl
                                      1);             // bytecount
                util_check("XMSG_READCTRL_", ferr);
                ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer,    // reqdata
                                      BUFSIZ);        // bytecount
                util_check("XMSG_READDATA_", ferr);
                if (sre.sre_flags & XSRE_MON) {
                    MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                    if (cnid < 0) {
                        ferr = msg_mon_get_process_info((char *) "$cli", &cnid, &cpid);
                        if (ferr != XZFIL_ERR_OK) {
                            cnid = -1;
                            cpid = -1;
                        }
                    }
                    client_mon = true;
                    Item *item_hdl;
                    Item *item_tag;
                    const char *type;
                    switch (msg->type) {
                    case MS_MsgType_Close:
                        type = "close";
                        if ((cnid == msg->u.close.nid) &&
                            (cpid == msg->u.close.pid)) {
                        } else
                            client_mon = false;
                        break;
                    case MS_MsgType_NodeDown:
                        type = "node-down";
                        break;
                    case MS_MsgType_Open:
                        type = "open";
                        if ((cnid == msg->u.open.nid) &&
                            (cpid == msg->u.open.pid))
                            open_rcvd = true;
                        else
                            client_mon = false;
                        break;
                    case MS_MsgType_ProcessDeath:
                        type = "process-death";
                        break;
                    case MS_MsgType_Shutdown:
                        type = "shutdown";
                        done = true;
                        break;
                    case MS_MsgType_TmSyncAbort:
                    case MS_MsgType_TmSyncCommit:
                        if (msg->type == MS_MsgType_TmSyncAbort)
                            type = "tmsync-abort";
                        else
                            type = "tmsync-commit";
                        nid = msg->u.tmsync.nid[0];
                        handle = msg->u.tmsync.handle[0];
                        if (msg->u.tmsync.orig_count == 0) {
                            msg->u.tmsync.orig_tag[0] = -1;
                            msg->u.tmsync.orig_handle[0] = -1;
                        }
                        orig_tag = msg->u.tmsync.orig_tag[0];
                        if (!quiet) {
                            printf("server (%s) received (%s) mon message, type=%s(%d), nid=%d\n",
                               pname,
                               client_mon ? "cli" : "dtm",
                               type,
                               msg->type,
                               nid);
                            printf("  orig_count=%d, orig_tag=%d, orig_handle=%d, count=%d, handle[0]=%d\n",
                               msg->u.tmsync.orig_count,
                               orig_tag,
                               msg->u.tmsync.orig_handle[0],
                               msg->u.tmsync.count,
                               handle);
                        }
                        if (nid == snid) {
                            if (!quiet)
                                printf("server (%s) commit handle=%d, orig-count=%d\n",
                                       pname, handle, msg->u.tmsync.orig_count);
                            for (int inx2 = 0;
                                 inx2 < msg->u.tmsync.count;
                                 inx2++) {
                                int ltag = msg->u.tmsync.orig_tag[inx2];
                                int lhandle = msg->u.tmsync.orig_handle[inx2];
                                if (!quiet)
                                    printf("server (%s) commit orig-tag/handle=%d/%d\n",
                                           pname, ltag, lhandle);
                                item_tag = (Item *) tag_issue_map.remove(ltag);
                                assert(item_tag != NULL);
                                delete item_tag;
                                item_hdl = (Item *) handle_issue_map.remove(lhandle);
                                assert(item_hdl != NULL);
                                delete item_hdl;
                            }
                        } else {
                            assert(msg->u.tmsync.orig_count == 0);
                        }
                        commit_rcvd = true;
                        break;
                    default:
                        type = "<unknown>";
                    }
                    if (!quiet)
                        printf("server (%s) received (%s) mon message, type=%s(%d)\n",
                               pname, client_mon ? "cli" : "dtm", type, msg->type);
                    len = 0;
                } else {
                    inx++;
                    if (verbose)
                        printf("%s: received non-mon message, inx=%d\n",
                               pname, inx);
                    if (!sync)
                        assert(sync_rcvd);
                    assert(commit_rcvd);
                    assert(open_rcvd);
                    strcat(recv_buffer, "- reply from ");
                    strcat(recv_buffer, my_name);
                    strcat(recv_buffer, " - ");
                    strcat(recv_buffer, pname);
                    len = (int) strlen(recv_buffer) + 1;
                }
                XMSG_REPLY_(sre.sre_msgId,       // msgid
                            recv_buffer2,        // replyctrl
                            sre.sre_reqCtrlSize, // replyctrlsize
                            recv_buffer,         // replydata
                            (ushort) len,        // replydatasize
                            0,                   // errorclass
                            NULL);               // newphandle
            }
        }
        assert(inx == loop);
        assert(tag_issue_map.empty());
        assert(handle_issue_map.empty());
        // need to wait for shutdown to be started
        ferr = msg_mon_event_wait(2, &event_len, event_data);
        util_check("msg_mon_event_wait", ferr);
        if (sync && threaded) {
            sync_thr_shutdown = true;
            for (int thr = 0; thr < MAX_THR; thr++) {
                void *larg;
                status = sync_thr[thr]->join(&larg);
                TEST_CHK_STATUSOK(status);
            }
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 19
0
int main(int argc, char *argv[]) {
    bool      client = false;
    bool      client2 = false;
    int       close_count;
    int       cnid;
    int       cpid;
    int       ferr;
    bool      fin = false;
    int       inx;
    int       lerr;
    int       loop = 10;
    int       oid;
    char     *sname = (char *) "$srv";
    BMS_SRE   sre;
    bool      verbose = false;
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-client2",   TA_Bool, TA_NOMAX,    &client2   },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "-verbose",   TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    util_test_start(client);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        msg_debug_hook("c", "c");
        sprintf(cprog, "%s/%s", getenv("PWD"), argv[0]);
        for (inx = 0; inx < argc; inx++) {
            if (strcmp(argv[inx], "-client") == 0)
                argv[inx] = (char *) "-client2";
        }
        for (inx = 0; inx < loop; inx++) {
            if (verbose)
                printf("cli: newproc, inx=%d\n", inx);
            sprintf(cname, "$cli%d", inx);
            cnid = -1;
            ferr = msg_mon_start_process(cprog,                  // prog
                                         cname,                  // name
                                         NULL,                   // ret_name
                                         argc,                   // argc
                                         argv,                   // argv
                                         TPT_REF(cphandle),      // phandle
                                         false,                  // open
                                         NULL,                   // oid
                                         MS_ProcessType_Generic, // type
                                         0,                      // priority
                                         false,                  // debug
                                         false,                  // backup
                                         &cnid,                  // nid
                                         &cpid,                  // pid
                                         NULL,                   // infile
                                         NULL);                  // outfile
            TEST_CHK_FEOK(ferr);
        }
    } else if (client2) {
        if (verbose)
            printf("cli: open\n");
        ferr = msg_mon_open_process(sname,  // name
                                    TPT_REF(sphandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    } else {
        msg_mon_enable_mon_messages(true);
        close_count = 0;
        for (inx = 0; !fin; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == BSRETYPE_NOWORK);
            if (sre.sre_flags & XSRE_MON) {
                ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer,    // reqdata
                                      BUFSIZ);        // bytecount
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                if (verbose)
                    printf("srv: rcvd mon msg=%d, inx=%d\n", msg->type, inx);
                if (msg->type == MS_MsgType_Close)
                    if (++close_count >= loop)
                        fin = true;
            }
            if (verbose)
                printf("srv: reply, inx=%d\n", inx);
            BMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        disable;
    int        ferr;
    int        inx;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    RT         results;
    MS_SRE     sre;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            disable = msg_test_assert_disable();
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            assert(ferr);
            msg_test_assert_enable(disable);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        XMSG_REPLY_(sre.sre_msgId,  // msgid
                    NULL,           // replyctrl
                    0,              // replyctrlsize
                    recv_buffer,    // replydata
                    0,              // replydatasize
                    0,              // errorclass
                    NULL);          // newphandle
        util_abort_core_free();
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 21
0
int main(int argc, char *argv[]) {
    char                      *args[4];
    bool                       attach = false;
    bool                       chook = false;
    bool                       client = false;
    bool                       clientd = false;
    int                        cli_nid = -1;
    int                        cli_pid = -1;
    const char                *cname = "$cli";
    int                        count;
    int                        ferr;
    int                        inx;
    int                        len;
    int                        lerr;
    int                        loop = 10;
    TPT_DECL                  (mphandle);
    char                      *mphandlec = (char *) &mphandle;
    TPT_DECL_INT              (mphandlei);
    int                        msgid;
    int                        my_mon_nid;
    int                        my_mon_pid;
    int                        my_mon_ptype;
    int                        my_mon_zid;
    int                        my_os_pid;
    long                       my_os_tid;
    int                        my_compid;
    int                        my_pnid;
    int                        my_segid;
    int                        nid;
    int                        oid;
    TPT_DECL                  (phandle);
    int                        pid;
    char                      *pname = NULL;
    int                        ptype;
    RT                         results;
    int                        scollpid = -1;
    int                        scompid = -1;
    int                        send_len;
    bool                       shook = false;
    const char                *sname = "$srv";
    bool                       sonar = false;
    MS_SRE                     sre;
    int                        srv_nid = -1;
    int                        srv_pid = -1;
    MS_Mon_Monitor_Stats_Type  stats;
    int                        status;
    long                       t_elapsed;
    struct timeval             t_start;
    struct timeval             t_stop;
    int                        tm_seq;
    bool                       val_bool;
    int                        val_int;
    const char                *val_str;
    int                        winx;
    pid_t                      wpid;
    TAD                        zargs[] = {
        { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
        { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-clientd",   TA_Bool, TA_NOMAX,    &clientd   },
        { "-cname",     TA_Str,  TA_NOMAX,    &cname     },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-name",      TA_Str,  TA_NOMAX,    &pname     },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
        { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
        { "-sname",     TA_Str,  TA_NOMAX,    &sname     },
        { "-sonar",     TA_Bool, TA_NOMAX,    &sonar     },
        { "",           TA_End,  TA_NOMAX,    NULL       }
    };

#ifdef DEBUG_ENV
    env = environ;
    while (*env != NULL) {
        printf("env=%s\n", *env);
        env++;
    }
#endif

    arg_proc_args(zargs, false, argc, argv);
    if (client && chook)
        test_debug_hook("c", "c");
    if (!client && shook)
        test_debug_hook("s", "s");

    setenv("TESTKEYBOOL", "1", 1);
    setenv("TESTKEYINT", "44", 1);
    setenv("TESTKEYSTR", "TESTVALSTR", 1);
    //
    // test msg_getenv* before msg_init
    //
    val_bool = true;
    msg_getenv_bool("TESTKEYBOOL", &val_bool);
    assert(val_bool);
    val_bool = false;
    msg_getenv_bool("TESTKEYBOOL", &val_bool);
    assert(!val_bool);
    val_int = 0;
    msg_getenv_int("TESTKEYINT", &val_int);
    assert(val_int == 0);
    val_int = 1;
    msg_getenv_int("TESTKEYINT", &val_int);
    assert(val_int == 1);
    val_str = (const char *) 1;
    val_str = msg_getenv_str("TESTKEYSTR");
    assert(val_str == NULL);

    if (attach)
        msfs_util_init_attach(&argc, &argv, msg_debug_hook, false, pname);
    else
        msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_time_timer_start(&t_start);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);

    //
    // test msg_getenv* after msg_init
    //
    msg_getenv_bool("TESTKEYBOOL", &val_bool);
    assert(val_bool);
    msg_getenv_int("TESTKEYINT", &val_int);
    assert(val_int == 44);
    val_str = msg_getenv_str("TESTKEYSTR");
    assert(strcmp(val_str, "TESTVALSTR") == 0);

    // process-wait for server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false);
    TEST_CHK_FEOK(ferr);
    // process-wait for client
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        if (sonar) {
            scollpid = fork();
            if (scollpid == 0) {
                // child
                args[0] = (char *) "sonarcollector";
                args[1] = (char *) "-i"; // sampling interval // cast
                args[2] = (char *) "1"; // cast
                args[3] = NULL;
                lerr = execvp(args[0], args);
                assert(lerr == 0);
            }
        }
        ferr = msg_mon_open_process((char *) sname,       // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }

    // this phandle check assumed a particular data structure
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);
    ferr = XPROCESSHANDLE_GETMINE_(TPT_REF(mphandle));
    util_check("XPROCESSHANDLE_GETMINE_", ferr);
    TPT_COPY_INT(mphandlei, mphandle);
    assert((mphandlei[0] & 0xf0) == 0x20); // named
    assert(strncmp(my_name, &mphandlec[4], 32) == 0);
    printf("phandle=%x.%x.%x.%x.%x\n",
           mphandlei[0],
           mphandlei[1],
           mphandlei[2],
           mphandlei[3],
           mphandlei[4]);
    ferr = msg_mon_get_my_info(&my_mon_nid,
                               &my_mon_pid,
                               my_mon_name,
                               BUFSIZ,
                               &my_mon_ptype,
                               &my_mon_zid,
                               &my_os_pid,
                               &my_os_tid);
    util_check("msg_mon_get_my_info", ferr);
    printf("nid=%d, pid=%d, name=%s, ptype=%d, zid=%d, os-pid=%d, os-tid=%ld\n",
           my_mon_nid,
           my_mon_pid,
           my_mon_name,
           my_mon_ptype,
           my_mon_zid,
           my_os_pid,
           my_os_tid);
    my_mon_nid   = -1;
    my_mon_pid   = -1;
    my_mon_ptype = -1;
    my_mon_zid   = -1;
    my_os_pid    = -1;
    my_os_tid    = -1;
    my_compid    = -1;
    my_pnid      = -1;
    ferr = msg_mon_get_my_info3(&my_mon_nid,
                                &my_mon_pid,
                                my_mon_name3,
                                BUFSIZ,
                                &my_mon_ptype,
                                &my_mon_zid,
                                &my_os_pid,
                                &my_os_tid,
                                &my_compid,
                                &my_pnid);
    util_check("msg_mon_get_my_info3", ferr);
    printf("nid=%d, pid=%d, name=%s, ptype=%d, zid=%d, os-pid=%d, os-tid=%ld, compid=%d, pnid=%d\n",
           my_mon_nid,
           my_mon_pid,
           my_mon_name3,
           my_mon_ptype,
           my_mon_zid,
           my_os_pid,
           my_os_tid,
           my_compid,
           my_pnid);
    ferr = msg_mon_get_my_segid(&my_segid);
    util_check("msg_mon_get_my_segid", ferr);
    printf("segid=%d\n", my_segid);

    ferr = msg_mon_get_monitor_stats(&stats);
    util_check("msg_mon_get_monitor_stats", ferr);
    printf("avail_min=%d, acquired_max=%d, buf_misses=%d\n",
           stats.avail_min, stats.acquired_max, stats.buf_misses);

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_tm_seq(&tm_seq);
    util_check("msg_mon_get_tm_seq", ferr);
    printf("tm_seq=%d\n", tm_seq);
    if (client) {
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             0,
                                             NULL);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             1,
                                             info);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
    }

    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              (ushort) (inx & 1),          // reqctrlsize
                              recv_buffer3,                // replyctrl
                              1,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              (ushort) send_len,           // reqdatasize
                              recv_buffer,                 // replydata
                              BUFSIZ,                      // replydatamax
                              0,                           // linkertag
                              (short) (inx+1),             // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid,
                               results.u.s,
                               TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_GETREQINFO_(MSGINFO_NID,
                                    sre.sre_msgId,
                                    &nid);
            util_check("XMSG_GETREQINFO_", ferr);
            ferr = XMSG_GETREQINFO_(MSGINFO_PID,
                                    sre.sre_msgId,
                                    &pid);
            util_check("XMSG_GETREQINFO_", ferr);
            ferr = XMSG_GETREQINFO_(MSGINFO_PTYPE,
                                    sre.sre_msgId,
                                    &ptype);
            util_check("XMSG_GETREQINFO_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                // mon messages have our nid/pid
                if (srv_nid < 0) {
                    ferr = msg_mon_get_process_info((char *) "",
                                                    &srv_nid,
                                                    &srv_pid);
                    TEST_CHK_FEOK(ferr);
                }
                if (!clientd) {
                    assert(nid == srv_nid);
                    assert(pid == srv_pid);
                }
            } else {
                assert(sre.sre_pri == ((inx+1) & 0xffff));
                if (cli_nid < 0) {
                    ferr = msg_mon_get_process_info((char *) cname,
                                                    &cli_nid,
                                                    &cli_pid);
                    TEST_CHK_FEOK(ferr);
                }
                if (!attach)
                    assert(ptype == MS_ProcessType_TSE);
                assert(nid == cli_nid);
                assert(pid == cli_pid);
            }
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
                if (clientd) {
                    MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                    if (msg->type == MS_MsgType_Close)
                        inx = loop;
                }
            } else {
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }
    if (sonar) {
        if (client) {
            // for some reason [monitor?], one 'sonarcom stop' doesn't stop coll
            for (winx = 0; winx < 20; winx++) {
                scompid = fork();
                if (scompid == 0) {
                    // child
                    args[0] = (char *) "sonarcom";
                    args[1] = (char *) "stop";
                    args[2] = NULL;
                    lerr = execvp(args[0], args);
                    assert(lerr == 0);
                }
                wpid = waitpid(scompid, &status, 0);
                assert(wpid == scompid);
                wpid = waitpid(scollpid, &status, WNOHANG);
                if (wpid == scollpid)
                    break;
                else
                    sleep(1);
            }
            assert(wpid == scollpid);
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              NULL,                        // reqdata
                              0,                           // reqdatasize
                              NULL,                        // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            TEST_CHK_FEOK(ferr);
            ferr = XMSG_BREAK_(msgid,
                               results.u.s,
                               TPT_REF(phandle));
            TEST_CHK_FEOK(ferr);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        if (!clientd) {
            ferr = msg_mon_process_close();
            TEST_CHK_FEOK(ferr);
        }
    }
    util_time_timer_stop(&t_stop);
    t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) -
                (t_start.tv_sec * 1000000 + t_start.tv_usec);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    if (client) {
        printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed);
    }
    return 0;
}
Exemplo n.º 22
0
int main(int argc, char *argv[]) {
    bool      client = false;
    int       event_len;
    int       ferr;
    int       inx;
    int       len;
    int       lerr;
    int       linx;
    int       loop = 10;
    int       msgid;
    int       oid;
    TPT_DECL (phandle);
    RT        results;
    int       send_len;
    int       srv_nid = -1;
    int       srv_pid = -1;
    MS_SRE    sre;
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_get_process_info((char *) "$srv", &srv_nid, &srv_pid);
        TEST_CHK_FEOK(ferr);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);

    for (inx = 0; inx < MS_MON_MAX_SYNC_DATA; inx++)
        event_data[inx] = (char) (inx + 1);
    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              (ushort) (inx & 1),          // reqctrlsize
                              recv_buffer3,                // replyctrl
                              1,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              (ushort) send_len,           // reqdatasize
                              recv_buffer,                 // replydata
                              BUFSIZ,                      // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            lerr = XWAIT(LDONE, 10);
            TEST_CHK_WAITIGNORE(lerr);
            assert(!XMSG_ISDONE_(msgid));
            ferr =
              msg_mon_event_send(srv_nid,                    // nid
                                 srv_pid,                    // pid
                                 MS_ProcessType_Undefined,   // process-type
                                 inx,                        // event-id
                                 inx % MS_MON_MAX_SYNC_DATA, // event-len
                                 event_data);                // event-data
            TEST_CHK_FEOK(ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
            } else {
                memset(event_data, 0, sizeof(event_data));
                ferr = msg_mon_event_wait(inx, &event_len, event_data);
                TEST_CHK_FEOK(ferr);
                assert(event_len == (inx % MS_MON_MAX_SYNC_DATA));
                for (linx = 0; linx < event_len; linx++)
                    assert(event_data[linx] == (linx + 1));
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 23
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        ferr;
    int        inx;
    int        loop = 10;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    char       recv_buffer[40000];
    RT         results;
    char       send_buffer[40000];
    int        status;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-delay",     TA_Bool, TA_NOMAX,    &delay     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxs",      TA_Int,  TA_NOMAX,    &maxs      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              39000,                       // reqdatasize
                              recv_buffer,                 // replydata
                              40000,                       // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == 0);
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        }
        for (inx = 0; inx < maxs; inx++) {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            printf("fin %d\n", inx);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        for (inx = 0; inx < maxs; inx++) {
            char name[10];
            sprintf(name, "s%d", inx);
            thrs[inx] = new Server_Thread(server_thr, name, inx);
        }
        for (inx = 0; inx < maxs; inx++) {
            thrs[inx]->start();
            SB_Thread::Sthr::yield();
        }
        for (inx = 0; inx < maxs; inx++) {
            void *res;
            status = thrs[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inx);
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 24
0
int main(int argc, char *argv[]) {
    bool            client = false;
    int             ferr;
    int             inx;
    int             inx2;
    int             lerr;
    int             loop = 10;
    int             oid;
    TPT_DECL       (phandle);
    MS_SRE          sre;
    long            t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    bool            verbose = false;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);

    util_time_timer_start(&t_start);
    if (client) {
        for (inx = 0; inx < loop; inx++) {
            if (verbose)
                printf("opening inx=%d\n", inx);
            ferr = msg_mon_open_process((char *) "$srv",      // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
            ferr = msg_mon_close_process(TPT_REF(phandle));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        for (inx = 0; inx < loop; inx++) {
            for (inx2 = 0; inx2 < 2; inx2++) {
                do {
                    lerr = XWAIT(LREQ, -1);
                    TEST_CHK_WAITIGNORE(lerr);
                    lerr = XMSG_LISTEN_((short *) &sre, // sre
                                        0,              // listenopts
                                        0);             // listenertag
                } while (lerr == XSRETYPE_NOWORK);
                if (verbose)
                    printf("replying inx=%d\n", inx);
                XMSG_REPLY_(sre.sre_msgId,  // msgid
                            NULL,           // replyctrl
                            0,              // replyctrlsize
                            NULL,           // replydata
                            0,              // replydatasize
                            0,              // errorclass
                            NULL);          // newphandle
            }
        }
    }
    util_time_timer_stop(&t_stop);
    t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) -
                (t_start.tv_sec * 1000000 + t_start.tv_usec);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    if (client)
        printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed);
    return 0;
}
Exemplo n.º 25
0
int main(int argc, char *argv[]) {
    bool                       client = false;
    int                        count;
    int                        disable;
    int                        ferr;
    MS_Mon_Open_Info_Type      info;
    MS_Mon_Open_Info_Max_Type  info_max[MAX_OPENS];
    int                        inx;
    int                        len;
    int                        lerr;
    int                        loop = 10;
    int                        msgid;
    int                        oid;
    TPT_DECL                  (phandle);
    RT                         results;
    int                        send_len;
    MS_SRE                     sre;
    TAD                        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    // process-wait for server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false);
    TEST_CHK_FEOK(ferr);
    // process-wait for client
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    } else

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);

    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              (ushort) (inx & 1),          // reqctrlsize
                              recv_buffer3,                // replyctrl
                              1,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              (ushort) send_len,           // reqdatasize
                              recv_buffer,                 // replydata
                              BUFSIZ,                      // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
            } else {
                if (inx == 0) {
                    sleep(3); // wait for monitor replicate
                    disable = msg_test_assert_disable();
                    ferr = msg_mon_get_open_info(-1,
                                                 -1,
                                                 (char *) "$srv",
                                                 1,
                                                 &info);
                    assert(ferr == XZFIL_ERR_INVALOP);
                    ferr = msg_mon_get_open_info_max(-1,
                                                     -1,
                                                     (char *) "$srv",
                                                     false,
                                                     &count,
                                                     MAX_OPENS,
                                                     info_max);
                    assert(ferr == XZFIL_ERR_INVALOP);
                    msg_test_assert_enable(disable);
                }
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 26
0
int main(int argc, char *argv[]) {
    bool            attach = false;
    bool            chook = false;
    bool            client = false;
    const char     *cname = "$cli";
    int             count;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 10;
    int             msgid;
    int             oid;
    TPT_DECL       (phandle);
    char           *pname = NULL;
    RT              results;
    int             send_len;
    bool            shook = false;
    const char     *sname = "$srv";
    MS_SRE          sre;
    long            t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    TAD             zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-cname",     TA_Str,  TA_NOMAX,    &cname     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-name",      TA_Str,  TA_NOMAX,    &pname     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "-sname",     TA_Str,  TA_NOMAX,    &sname     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (client && chook)
        test_debug_hook("c", "c");
    if (!client && shook)
        test_debug_hook("s", "s");

    if (attach)
        msfs_util_init_attach(&argc, &argv, msg_debug_hook, false, pname);
    else
        msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_time_timer_start(&t_start);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);

    // process-wait for server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false);
    TEST_CHK_FEOK(ferr);
    // process-wait for client
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) sname,       // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    if (client) {
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             0,
                                             NULL);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             1,
                                             info);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
    }

    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              (ushort) (inx & 1),          // reqctrlsize
                              recv_buffer3,                // replyctrl
                              1,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              (ushort) send_len,           // reqdatasize
                              recv_buffer,                 // replydata
                              BUFSIZ,                      // replydatamax
                              0,                           // linkertag
                              (short) (inx+1),             // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid,
                               results.u.s,
                               TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
            } else {
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    util_time_timer_stop(&t_stop);
    t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) -
                (t_start.tv_sec * 1000000 + t_start.tv_usec);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    if (client)
        printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed);
    return 0;
}
Exemplo n.º 27
0
int main(int argc, char *argv[]) {
    bool          chook = false;
    int           client = false;
    int           dinx;
    int           disable;
    int           ferr;
    int           inx;
    char          lname[10];
    bool          mq = false;
    int           oid;
    void         *res;
    bool          rnd = false;
    int           sleept;
    int           snid;
    int           spid;
    int           status;
    TAD           zargs[] =  {
        { "-chook",     TA_Bool, TA_NOMAX,    &chook      },
        { "-client",    TA_Bool, TA_NOMAX,    &client     },
        { "-dloop",     TA_Int,  MAX_OUT,     &gdloop     },
        { "-dsize",     TA_Int,  TA_NOMAX,    &gdsize     },
        { "-ksleep",    TA_Int,  TA_NOMAX,    &gksleep    },
        { "-loop",      TA_Int,  TA_NOMAX,    &gloop      },
        { "-maxc",      TA_Int,  MAX_THR,     &gmaxc      },
        { "-maxs",      TA_Int,  MAX_THR,     &gmaxs      },
        { "-mq",        TA_Bool, TA_NOMAX,    &mq         },
        { "-nodecycle", TA_Bool, TA_NOMAX,    &gnodecycle },
        { "-rnd",       TA_Bool, TA_NOMAX,    &rnd        },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL        },
        { "-v",         TA_Bool, TA_NOMAX,    &gverbose   },
        { "-vpp",       TA_Bool, TA_NOMAX,    &gverbosepp },
        { "",           TA_End,  TA_NOMAX,    NULL        }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (client && chook)
        test_debug_hook("c", "c");
    msfs_util_init(&argc, &argv, msg_debug_hook);
    util_test_start(client);
    if (!client)
        setup_sig();
    ferr = msg_mon_process_startup(true);             // system messages
    TEST_CHK_FEOK(ferr);
    gargc = argc; // after msg_init - it removes args
    gargp = argv;
    sprintf(gprog, "%s/%s", getenv("PWD"), argv[0]);
    gvirtual = (getenv("SQ_VIRTUAL_NODES") != NULL);
    ferr = msg_mon_get_my_process_name(gname, sizeof(gname));
    assert(ferr == XZFIL_ERR_OK);
    if (client) {
        msg_mon_enable_mon_messages(true); // get mon messages
        ferr = msg_mon_get_process_info(NULL, &gcnid, NULL);
        assert(ferr == XZFIL_ERR_OK);
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     (short) (gmaxc * gdloop));
        assert(ferr == XZFIL_ERR_OK);
        srand(1);
        sleept = 1000;
        start_server(argc, argv);
        sleep(1);
        ferr = msg_mon_open_process((char *) "$srv",              // name
                                    TPT_REF(gphandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(gphandle), &snid, &spid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < gloop; inx++) {
            if (mq)
                printf("client: inx=%d\n", inx);
            for (dinx = 0; dinx < gmaxc; dinx++) {
                sprintf(lname, "c%d", dinx);
                gthrc[dinx] = new MyThread(client_thr, lname, dinx);
            }
            disable = msg_test_assert_disable();
            for (dinx = 0; dinx < gmaxc; dinx++)
                gthrc[dinx]->start();
            if (rnd)
                sleept = (int) ((float) gksleep * (rand_r(&gseed) / (RAND_MAX + 1.0)));
            usleep(sleept);
            for (dinx = 0; dinx < gmaxc; dinx++) {
                status = gthrc[dinx]->join(&res);
                TEST_CHK_STATUSOK(status);
                if (gverbose)
                    printf("joined with client %d\n", dinx);
            }
            for (dinx = 0; dinx < gmaxc; dinx++)
                delete gthrc[dinx];
            msg_test_assert_enable(disable);
        }
    } else {
        msg_mon_enable_mon_messages(true); // get mon messages
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        pp_init();
        if (!gshutdown) {
            for (dinx = 0; dinx < gmaxs; dinx++) {
                char lname[10];
                sprintf(lname, "s%d", dinx);
                gthrs[dinx] = new SB_Thread::Thread(server_thr, lname);
            }
            for (dinx = 0; dinx < gmaxs; dinx++)
                gthrs[dinx]->start();
            for (dinx = 0; dinx < gmaxs; dinx++) {
                status = gthrs[dinx]->join(&res);
                TEST_CHK_STATUSOK(status);
                if (gverbose)
                    printf("joined with server %d\n", dinx);
            }
        }
        if (gverbosepp)
            pp_printf("exit pid=%d\n", getpid());
    }

    if (client) {
        sleep(1);
        ferr = msg_mon_close_process(TPT_REF(gphandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 28
0
int main(int argc, char *argv[]) {
    bool                client = false;
    bool                client1 = false;
    bool                client2 = false;
    bool                client3 = false;
    int                 ferr;
    int                 inx;
    int                 lerr;
    int                 loop = 10;
    int                 msgid;
    int                 oid;
    TPT_DECL           (phandle);
    MS_Result_Type      results;
    MS_SRE              sre;
    MS_Mon_Transid_Type transid;
    TAD                 zargs[] = {
      { "-client1",   TA_Bool, TA_NOMAX,    &client1   },
      { "-client2",   TA_Bool, TA_NOMAX,    &client2   },
      { "-client3",   TA_Bool, TA_NOMAX,    &client3   },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (client1)
        client = true;
    if (client2)
        client = true;
    if (client3)
        client = true;
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        if (client1)
            sleep(5);
        else if (client2) {
            util_abort_core_free();
        } else {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        for (inx = 0; inx < 7; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  40000);         // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                if (msg->type == MS_MsgType_Open) {
                    if (strcasecmp(msg->u.open.target_process_name, "$cli2") == 0) {
                        transid.id[0] = -1;
                        transid.id[1] = -1;
                        transid.id[2] = -1;
                        transid.id[3] = -1;
                        ferr = msg_mon_deregister_death_notification(-1, // msg->u.open.nid,
                                                                     -1, // msg->u.open.pid,
                                                                     transid);
                        TEST_CHK_FEOK(ferr);
                    }
                }
                printf("server reply type=%d, inx=%d\n", msg->type, inx);
            } else
                printf("server reply inx=%d\n", inx);
            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        0,              // replydatasize
                        0,              // errorclass
                        NULL);          // newphandle
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 29
0
int main(int argc, char *argv[]) {
    int        ferr;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        inx;
    int        lerr;
    int        loop = 10;
    int        max;
    int        maxsp = 1;
    int        oid;
    int        pinx;
    MS_SRE     sre;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp     },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (maxcp < 0)
        maxcp = 1;
    if (maxsp < 0)
        maxsp = 1;
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (!client)
        msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    TEST_CHK_FEOK(ferr);

    // process-wait for clients/servers/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic,
                                        maxcp + maxsp + 1,
                                        NULL,
                                        verbose);
    TEST_CHK_FEOK(ferr);
    sleep(3); // wait for all process_count's to complete
    if (client) {
        pinx = atoi(&my_name[4]);
        assert(pinx >= 0);
        printf("loop=%d\n", loop);
        for (inx = 0; inx < loop; inx++) {
            for (pinx = 0; pinx < maxsp; pinx++) {
                sprintf(serv, "$srv%d", pinx);
                ferr = msg_mon_open_process(serv,
                                            TPT_REF2(phandle,pinx),
                                            &oid);
                TEST_CHK_FEOK(ferr);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
                TEST_CHK_FEOK(ferr);
                if (verbose)
                    printf("%s-close-count=%d\n", my_name, inx);
            }
        }
    } else {
        max = 2 * maxcp * loop;
        for (inx = 0; inx < max; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,        // msgid
                                  recv_buffer2,         // reqctrl
                                  sre.sre_reqCtrlSize); // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,        // msgid
                                  recv_buffer,          // reqdata
                                  sre.sre_reqDataSize); // bytecount
            util_check("XMSG_READDATA_", ferr);
            XMSG_REPLY_(sre.sre_msgId,         // msgid
                        recv_buffer2,          // replyctrl
                        sre.sre_reqCtrlSize,   // replyctrlsize
                        recv_buffer,           // replydata
                        sre.sre_reqDataSize,   // replydatasize
                        1,                     // errorclass
                        NULL);                 // newphandle
            if (verbose)
                printf("%s-count=%d\n", my_name, inx);
        }
        sleep(5);
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 30
0
int main(int argc, char *argv[]) {
    char           *cli;
    int             ferr;
    int             lerr;
    int             msgid;
    int             nid;
    int             oid;
    TPT_DECL       (phandle);
    int             pid;
    MS_Result_Type  results;
    int             send_len;
    const char     *sname = "$srv";
    MS_SRE          sre;

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(pname, sizeof(pname));
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);

    sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
    cli = strstr(prog, "cli");
    strcpy(cli, "srv");
    nid = 0;
    ferr = msg_mon_start_process_nowait(prog,                     // prog
                                        (char *) sname,           // name
                                        retname,                  // ret-name
                                        argc,                     // argc
                                        argv,                     // argv
                                        TPT_REF(phandle),         // phandle
                                        MS_ProcessType_Generic,   // type
                                        0,                        // priority
                                        false,                    // debug
                                        false,                    // backup
                                        0x123456789abcdefLL,      // tag
                                        &nid,                     // nid
                                        &pid,                     // pid
                                        NULL,                     // infile
                                        NULL);                    // outfile
    TEST_CHK_FEOK(ferr);
    assert(strcasecmp(retname, sname) == 0);
    assert(nid == 0);
    lerr = XWAIT(LREQ, -1);
    TEST_CHK_WAITIGNORE(lerr);
    for (;;) {
        lerr = XMSG_LISTEN_((short *) &sre, // sre
                            0,              // listenopts
                            0);             // listenertag
        if (lerr == XSRETYPE_NOWORK)
            continue;
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        TEST_CHK_FEOK(ferr);
        if (sre.sre_flags & XSRE_MON) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            printf("client (%s) received mon message, type=%d\n",
                   pname, msg->type);
            assert(msg->type == MS_MsgType_ProcessCreated);
            printf("client (%s) received new process message, ferr=%d, nid=%d, pid=%d, tag=0x%llx, pname=%s\n",
                   pname,
                   msg->u.process_created.ferr,
                   msg->u.process_created.nid,
                   msg->u.process_created.pid,
                   msg->u.process_created.tag,
                   msg->u.process_created.process_name);
            assert(msg->u.process_created.ferr == XZFIL_ERR_OK);
            assert(msg->u.process_created.tag == 0x123456789abcdefLL);
            ferr = msg_mon_open_process((char *) sname,       // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
        }
        XMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    NULL,                // replydata
                    0,                   // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
        if (sre.sre_flags & XSRE_MON)
            break;
    }

    strcpy(send_buffer, "hello, greetings from client");
    send_len = (int) strlen(send_buffer) + 1;
    ferr = BMSG_LINK_(TPT_REF(phandle),            // phandle
                      &msgid,                      // msgid
                      NULL,                        // reqctrl
                      0,                           // reqctrlsize
                      recv_buffer3,                // replyctrl
                      1,                           // replyctrlmax
                      send_buffer,                 // reqdata
                      (ushort) send_len,           // reqdatasize
                      recv_buffer,                 // replydata
                      BUFSIZ,                      // replydatamax
                      0,                           // linkertag
                      0,                           // pri
                      0,                           // xmitclass
                      0);                          // linkopts
    TEST_CHK_FEOK(ferr);
    ferr = BMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle));
    TEST_CHK_FEOK(ferr);
    printf("%s\n", recv_buffer);

    ferr = msg_mon_close_process(TPT_REF(phandle));
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}