Пример #1
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;
}
Пример #2
0
int main(int argc, char *argv[]) {
    bool            client = false;
    int             exprinx;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 100;
    int             msgid[MAX_MSGS];
    int             oid;
    char           *p;
    TPT_DECL       (phandle);
    int             pri;
    RT              results;
    int             rinx;
    BMS_SRE         sre;
    BMS_SRE_LDONE   sre_ldone;
    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_enable_priority_queue();
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer[inx], "hello, greetings from %s, inx=%d",
                    my_name, inx);
            pri = 2 * inx + 5;
            ferr = BMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid[inx],                 // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer[inx],            // reqdata
                              100,                         // reqdatasize
                              recv_buffer[inx],            // replydata
                              100,                         // replydatamax
                              inx,                         // linkertag
                              (short) pri,                 // pri
                              0,                           // xmitclass
                              BMSG_LINK_LDONEQ);           // linkopts
            util_check("BMSG_LINK_", ferr);
        }
        exprinx = loop - 1;
        for (inx = 0; inx < loop;) {
            lerr = XWAIT(LDONE, -1);
            TEST_CHK_WAITIGNORE(lerr);
            do {
                lerr = BMSG_LISTEN_((short *) &sre_ldone, // sre
                                    0,                    // listenopts
                                    0);                   // listenertag
                if (lerr == BSRETYPE_LDONE) {
                    ferr = BMSG_BREAK_(sre_ldone.sre_msgId, results.u.s, TPT_REF(phandle));
                    util_check("BMSG_BREAK_", ferr);
                    assert(results.u.t.ctrl_size == 0);
                    assert(results.u.t.errm == RT_DATA_RCVD); // data
                    printf("%s\n", recv_buffer[sre_ldone.sre_linkTag]);
                    p = strchr(recv_buffer[sre_ldone.sre_linkTag], '=');
                    assert(p != NULL);
                    rinx = atoi(&p[1]);
                    if (rinx != exprinx) {
                        printf("rinx=%d, exprinx=%d\n", rinx, exprinx);
                        assert(rinx == exprinx);
                    }
                    inx++;
                    exprinx--;
                }
            } while (lerr == BSRETYPE_LDONE);
        }
    } else {
        for (inx = 0; inx < loop; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                if (inx == 0)
                    sleep(5);
                lerr = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == BSRETYPE_NOWORK);
            ferr = BMSG_READCTRL_(sre.sre_msgId,    // msgid
                                  NULL,             // reqctrl
                                  0);               // bytecount
            util_check("BMSG_READCTRL_", ferr);
            ferr = BMSG_READDATA_(sre.sre_msgId,    // msgid
                                  recv_buffer[inx], // reqdata
                                  100);             // bytecount
            util_check("BMSG_READDATA_", ferr);
            strcat(recv_buffer[inx], "- reply from ");
            strcat(recv_buffer[inx], my_name);
            len = (int) strlen(recv_buffer[inx]) + 1;
            len = len; // touch - not currently used
            BMSG_REPLY_(sre.sre_msgId,      // msgid
                        NULL,               // replyctrl
                        0,                  // replyctrlsize
                        recv_buffer[inx],   // replydata
                        100,                // 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;
}
Пример #3
0
// ---------------------------------------------------------------------------
// CxaTM_RMMessage::link
// Purpose : Call to BMSG_LINK_.
// This function will retry any retriable errors such as FENOLCB (30).
// Parameters:
//  pv_maxretries - maximum retries for retriable errors.
//  Returns error from BMSG_LINK_ call.
// ---------------------------------------------------------------------------
short CxaTM_RMMessage::link(int32 pv_maxretries)

{
    short lv_ret = 0;
    int32 lv_retries = 0;
    bool lv_exit = false;
    TM_Txid_Internal *lp_transid = (TM_Txid_Internal *) &xid()->data[0];

    XATrace(XATM_TraceExit, ("CxaTM_RMMessage::link ENTRY : ID (%d,%d), linker "
            "tag(rmid) %d.\n", lp_transid->iv_node, lp_transid->iv_seq_num, 
            ip_RM->getRmid()));

    do {
         lv_ret = BMSG_LINK_(ip_RM->getRmPhandle(),     // phandle, 
                           &iv_msgid,                   // msgid
                           NULL,                        // reqctrl
                           0,                           // reqctrlsize
                           NULL,                        // replyctrl
                           0,                           // replyctrlmax
                           (char *) Req(),              // reqdata
                           ReqLen(),                    // reqdatasize
                           (char *) Rsp(),              // replydata
                           RspLen(),                    // replydatamax
                           ip_RM->getRmid(),            // linkertag
                           TSE_LINK_PRIORITY,           // pri
                           0,                           // xmitclass
                           BMSG_LINK_LDONEQ);           // linkopts

       lv_retries++;
       if (lv_ret == FENOLCB && 
          //((pv_maxretries == -1 && (lv_retries % TM_LINKRETRY_RETRIES == 0)) ||
          (pv_maxretries == -1 ||
           (pv_maxretries > 0 && (lv_retries <= pv_maxretries))))
       {  // Message Descriptor depletion.  This means we ran out of MDs.
          // This is retriable, and we want to slow down the TM to allow
          // some of the outstanding requests to complete.
          XATrace(XATM_TraceError, ("CxaTM_RMMessage::link BMSG_LINK_ error %d, "
                       "linker tag(rmid) %d, retires %d/%d - Pausing thread for "
                       "%dms before retrying.\n", lv_ret, ip_RM->getRmid(), 
                       lv_retries, pv_maxretries, TM_LINKRETRY_PAUSE));
          tm_log_event(DTM_TM_LINK_PAUSED, SQ_LOG_WARNING, "DTM_TM_LINK_PAUSED", 
                   lv_ret, -1, lp_transid->iv_node, lp_transid->iv_seq_num, -1, -1, -1, -1, lv_retries, 
                   -1, -1, -1, -1, TM_LINKRETRY_PAUSE /*pause in ms*/, ip_RM->getRmid());
          SB_Thread::Sthr::sleep(TM_LINKRETRY_PAUSE); // in msec
       }
       if (lv_ret != FENOLCB)
          lv_exit = true;
       else
          if (pv_maxretries > 0 && lv_retries >= pv_maxretries)
             lv_exit = true;

    } while (!lv_exit);

    if (lv_ret)
    {
       XATrace(XATM_TraceExit, ("CxaTM_RMMessage::link EXIT : returning error %d.\n", lv_ret));
    }
    else
    {
       XATrace(XATM_TraceExit, ("CxaTM_RMMessage::link EXIT : returning msgid %d.\n", iv_msgid));
    }
    return lv_ret;
} //CxaTM_RMMessage::link
Пример #4
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;
}
Пример #5
0
//
// plugin - send msg to ms-ic
//
static void sb_pi_ic_send(MS_Mon_Node_Info_Entry_Type *pp_node,
                          MS_Mon_Process_Info_Type    *pp_proc,
                          Sqstate_Pi_Info_Type        *pp_info,
                          char                        *pp_title,
                          bool                         pv_title,
                          const char                  *pp_lib,
                          const char                  *pp_call,
                          char                        *pp_rsp,
                          int                          pv_rsplen,
                          int                         *pp_rsplen) {
    char             la_ctrl[200];
    char            *lp_data;
    char            *lp_p;
    char             la_rsp[MAX_RSP];
    short           *lp_ctrl;
    short           *lp_results;
    char            *lp_rsp;
    int              lv_clen;
    int              lv_disable;
    int              lv_dlen;
    int              lv_fserr;
    int              lv_inx;
    int              lv_len;
    int              lv_msgid;
    int              lv_oid;
    bool             lv_open;
    MS_Result_Type   lv_results;
    int              lv_rsplen;

    pp_node = pp_node; // touch
    if (pp_rsplen != NULL)
        *pp_rsplen = 0;

    lv_open = (strcmp(pp_proc->process_name, gp_pname) != 0);
    gp_pname = pp_proc->process_name;

    if (strcmp(pp_call, "ic_unload") == 0)
        sprintf(la_ctrl, "unload" ":" ":" "all");
    else
        sprintf(la_ctrl, "call" ":" "%s" ":" "%s", pp_lib, pp_call);
    lv_clen = static_cast<int>(strlen(la_ctrl)) + 1;
    lv_dlen = 0;
    for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++)
        lv_dlen += static_cast<int>(strlen(pp_info->ic_argv[lv_inx])) + 1;
    if (lv_dlen > 0) {
        lp_data = new char[lv_dlen];
        lp_p = lp_data;
        for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++) {
            lv_len = sprintf(lp_p, "%s", pp_info->ic_argv[lv_inx]);
            lp_p += lv_len + 1;
        }
    } else
        lp_data = NULL;
    if (lv_open) {
        if (gv_verbosev)
            sb_pi_verb_printf("opening %s...\n", gp_pname);
        if (gv_opened) {
            gv_opened = false;
            lv_fserr = msg_mon_close_process(&gv_phandle);
            CHK_FEIGNORE(lv_fserr);
        }
        lv_disable = msg_test_assert_disable();
        if (pp_info->self)
            lv_fserr = msg_mon_open_process_self_ic(&gv_phandle, &lv_oid);
        else
            lv_fserr = msg_mon_open_process_ic(gp_pname, &gv_phandle, &lv_oid);
        msg_test_assert_enable(lv_disable);
        sb_pi_verb_ok(lv_fserr, "open");
    } else
        lv_fserr = XZFIL_ERR_OK;
    if (lv_fserr != XZFIL_ERR_OK) {
        sb_pi_verb_printf("ERROR: could not open %s, fserr=%d\n",
                          gp_pname,
                          lv_fserr);
    } else {
        lp_ctrl = reinterpret_cast<short *>(la_ctrl);
        gv_opened = true;
        if (gv_verbose)
            sb_pi_verb_printf("linking %s, ctrl=%s...\n", gp_pname, la_ctrl);
        lv_disable = msg_test_assert_disable();
        if (pp_rsp == NULL) {
            lp_rsp = la_rsp;
            lv_rsplen = MAX_RSP;
        } else {
            lp_rsp = pp_rsp;
            lv_rsplen = pv_rsplen;
        }
        lv_fserr = BMSG_LINK_(&gv_phandle,                 // phandle
                              &lv_msgid,                   // msgid
                              lp_ctrl,                     // reqctrl
                              lv_clen,                     // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              lp_data,                     // reqdata
                              lv_dlen,                     // reqdatasize
                              lp_rsp,                      // replydata
                              lv_rsplen,                   // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              BMSG_LINK_MSINTERCEPTOR);    // linkopts
        msg_test_assert_enable(lv_disable);
        sb_pi_verb_ok(lv_fserr, "link");
        if (lv_fserr != XZFIL_ERR_OK) {
            sb_pi_printf("ERROR: error in link to %s, fserr=%d\n",
                           gp_pname, lv_fserr);
        } else {
            if (gv_verbosev)
                sb_pi_verb_printf("breaking %s...\n", gp_pname);
            lp_results = reinterpret_cast<short *>(&lv_results);
            lv_disable = msg_test_assert_disable();
            lv_fserr = BMSG_BREAK_(lv_msgid, lp_results, &gv_phandle);
            msg_test_assert_enable(lv_disable);
            sb_pi_verb_ok(lv_fserr, "break");
            if (lv_fserr == XZFIL_ERR_OK) {
                if (pp_rsp == NULL)
                    sb_pi_ic_call_print_rsp(pp_title,
                                            pv_title,
                                            la_rsp,
                                            lv_results.rr_datasize);
                else if (pp_rsplen != NULL)
                    *pp_rsplen = lv_results.rr_datasize;
            } else {
                sb_pi_printf("ERROR: error in break to %s, fserr=%d\n",
                               gp_pname, lv_fserr);
            }
        }
    }
}
Пример #6
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;
}
Пример #7
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;
}
Пример #8
0
//
// plugin - send message to interceptor
//
SB_Export bool sqstatepi_send_ic_ok(const char                  *pp_module,
                                    const char                  *pp_call,
                                    MS_Mon_Node_Info_Entry_Type *pp_node,
                                    MS_Mon_Process_Info_Type    *pp_proc,
                                    Sqstate_Pi_Info_Type        *pp_info,
                                    const char                  *pp_lib,
                                    char                        *pp_rsp,
                                    int                          pv_rsp_len,
                                    int                         *pp_rsp_len) {
    char             la_ctrl[200];
    char            *lp_data;
    char            *lp_p;
    short           *lp_results;
    int              lv_clen;
    int              lv_dlen;
    int              lv_fserr;
    int              lv_inx;
    int              lv_len;
    int              lv_msgid;
    int              lv_oid;
    int              lv_ok;
    bool             lv_open;
    MS_Result_Type   lv_results;

    pp_node = pp_node; // touch
    lv_ok = false;
    *pp_rsp_len = 0;

    lv_open = (strcmp(pp_proc->process_name, gp_sqstatepi_pname) != 0);
    gp_sqstatepi_pname = pp_proc->process_name;

    sqstatepi_set_ctrl(la_ctrl, pp_info, pp_lib, pp_module, pp_call);
    lv_clen = static_cast<int>(strlen(la_ctrl)) + 1;
    lv_dlen = 0;
    for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++)
        lv_dlen += static_cast<int>(strlen(pp_info->ic_argv[lv_inx])) + 1;
    if (lv_dlen > 0) {
        lp_data = new char[lv_dlen];
        lp_p = lp_data;
        for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++) {
            lv_len = sprintf(lp_p, "%s", pp_info->ic_argv[lv_inx]);
            lp_p += lv_len + 1;
        }
    } else
        lp_data = NULL;
    if (lv_open) {
        if (pp_info->verbosev)
            sqstatepi_printf("opening %s...\n", gp_sqstatepi_pname);
        if (gv_sqstatepi_opened) {
            gv_sqstatepi_opened = false;
            lv_fserr = msg_mon_close_process(&gv_sqstatepi_phandle);
            CHK_FEIGNORE(lv_fserr);
        }
        if (pp_info->self)
            lv_fserr = msg_mon_open_process_self_ic(&gv_sqstatepi_phandle,
                                                    &lv_oid);
        else
            lv_fserr = msg_mon_open_process_ic(gp_sqstatepi_pname,
                                               &gv_sqstatepi_phandle,
                                               &lv_oid);
        sqstatepi_verbose_ok(pp_info, lv_fserr, "open");
    } else
        lv_fserr = XZFIL_ERR_OK;
    if (lv_fserr != XZFIL_ERR_OK) {
        sqstatepi_printf("ERROR: could not open %s, fserr=%d\n",
                         gp_sqstatepi_pname, lv_fserr);
    } else {
        gv_sqstatepi_opened = true;
        if (pp_info->verbose)
            sqstatepi_printf("linking %s, ctrl=%s...\n",
                             gp_sqstatepi_pname, la_ctrl);
        lv_fserr = BMSG_LINK_(&gv_sqstatepi_phandle,    // phandle
                              &lv_msgid,                // msgid
                              (short *) la_ctrl,        // reqctrl
                              lv_clen,                  // reqctrlsize
                              NULL,                     // replyctrl
                              0,                        // replyctrlmax
                              lp_data,                  // reqdata
                              lv_dlen,                  // reqdatasize
                              pp_rsp,                   // replydata
                              pv_rsp_len,               // replydatamax
                              0,                        // linkertag
                              0,                        // pri
                              0,                        // xmitclass
                              BMSG_LINK_MSINTERCEPTOR); // linkopts
        sqstatepi_verbose_ok(pp_info, lv_fserr, "link");
        if (lv_fserr != XZFIL_ERR_OK) {
            sqstatepi_printf("ERROR: error in link to %s, fserr=%d\n",
                             gp_sqstatepi_pname, lv_fserr);
        } else {
            if (pp_info->verbosev)
                sqstatepi_printf("breaking %s...\n", gp_sqstatepi_pname);
            lp_results = (short *) &lv_results;
            lv_fserr = BMSG_BREAK_(lv_msgid, lp_results, &gv_sqstatepi_phandle);
            sqstatepi_verbose_ok(pp_info, lv_fserr, "break");
            if (lv_fserr == XZFIL_ERR_OK) {
                *pp_rsp_len = lv_results.rr_datasize;
                lv_ok = true;
            } else {
                sqstatepi_printf("ERROR: error in break to %s, fserr=%d\n",
                                 gp_sqstatepi_pname, lv_fserr);
            }
        }
    }

    if (lp_data != NULL)
        delete [] lp_data;

    return lv_ok;
}