void wait_death() { int ferr; int lerr; MS_Mon_Msg *msg; char recv_buffer[BUFSIZ]; BMS_SRE sre; do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = BMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == BSRETYPE_NOWORK); assert(sre.sre_flags & XSRE_MON); ferr = BMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); msg = (MS_Mon_Msg *) recv_buffer; assert(msg->type == MS_MsgType_ProcessDeath); printf("received death message for %s\n", msg->u.death.process_name); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize NULL, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle }
// // ic - check if cmd is in data // // return true if valid // SB_Export bool sqstateic_get_ic_args(BMS_SRE *pp_sre, int *pp_ic_argc, char *pa_ic_argv[], int pv_ic_argc_max, char *pp_rsp, int pv_rsp_len, int *pp_rsp_len) { char *lp_end; char *lp_p; int lv_dlen; int lv_fserr; int lv_inx; int lv_len; bool lv_valid; pv_rsp_len = pv_rsp_len; // touch lv_dlen = pp_sre->sre_reqDataSize; if ((gp_sqstateic_args != NULL) && (lv_dlen > gv_sqstateic_args_len)) { delete [] gp_sqstateic_args; gp_sqstateic_args = NULL; } if (gp_sqstateic_args == NULL) { gv_sqstateic_args_len = lv_dlen; gp_sqstateic_args = new char[lv_dlen]; } lv_fserr = BMSG_READDATA_(pp_sre->sre_msgId, // msgid gp_sqstateic_args, // reqdata lv_dlen); // bytecount *pp_rsp_len = 0; *pp_ic_argc = 0; if (lv_fserr == XZFIL_ERR_OK) { lv_valid = true; lp_p = gp_sqstateic_args; lp_end = &lp_p[lv_dlen]; for (lv_inx = 0; lp_p < lp_end; lv_inx++) { lv_len = static_cast<int>(strlen(lp_p)); if (lv_inx < pv_ic_argc_max) pa_ic_argv[lv_inx] = lp_p; lp_p += (lv_len + 1); } if (lv_inx >= pv_ic_argc_max) lv_inx = pv_ic_argc_max; *pp_ic_argc = lv_inx; } else { lv_valid = false; *pp_rsp_len = sprintf(pp_rsp, "unable to read request"); } return lv_valid; }
// // process monitor message. // // if shutdown, set done // void do_mon_msg(BMS_SRE *sre, bool *done) { int ferr; MS_Mon_Msg mon_msg; ferr = BMSG_READDATA_(sre->sre_msgId, // msgid (char *) &mon_msg, // reqdata (int) sizeof(mon_msg)); // bytecount assert(ferr == XZFIL_ERR_OK); if (mon_msg.type == MS_MsgType_Shutdown) *done = true; if (verbose) printf("srv: received mon message\n"); do_reply(sre, NULL, 0, 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; }
// // process monitor message. // // if shutdown, set done // void do_mon_msg(BMS_SRE *pp_sre, bool *pp_done) { int lv_ferr; MS_Mon_Msg lv_mon_msg; lv_ferr = BMSG_READDATA_(pp_sre->sre_msgId, // msgid (char *) &lv_mon_msg, // reqdata (int) sizeof(lv_mon_msg)); // bytecount assert(lv_ferr == XZFIL_ERR_OK); if (lv_mon_msg.type == MS_MsgType_Shutdown) { printf("%s: received shutdown message\n", ga_name); *pp_done = true; } if (gv_verbose) printf("srv: received mon message\n"); do_reply(pp_sre, NULL, 0, 0); }
// // process non-mon message // void do_req(BMS_SRE *pp_sre) { const char *lp_req_type; short lv_ec; int lv_ferr; int lv_len; GID_Rep lv_rep; GID_Req lv_req; long lv_req_id; struct timeval lv_tv; struct timespec lv_orig_ts; unsigned long lv_converted_tm_id; lv_ec = XZFIL_ERR_OK; lv_len = 0; if (gv_verbose) printf("srv: received NON-mon message\n"); if (pp_sre->sre_reqDataSize < (int) sizeof(lv_req)) { if (gv_verbose) printf("srv: received short data - sre_reqDataSize=%d, expecting len=%d, setting BADCOUNT\n", pp_sre->sre_reqDataSize, (int) sizeof(lv_req)); lv_ec = XZFIL_ERR_BADCOUNT; } else { lv_ferr = BMSG_READDATA_(pp_sre->sre_msgId, // msgid (char *) &lv_req, // reqdata (int) sizeof(lv_req)); // bytecount if (lv_ferr != XZFIL_ERR_OK){ printf("srv: received lv_ferr %d in do_req \n", lv_ferr); if((lv_ferr = XMSG_ISCANCELED_(pp_sre->sre_msgId))){ printf("srv: XMSG_ISCANCELED_ returned %d in do_req. Most likely the client timeout was exceeded \n", lv_ferr); return; } else{ printf("srv: XMSG_ISCANCELED_ returned %d in do_req after FEEOF on BMSG_READDATA_. ABORTING \n", lv_ferr); abort(); } } if (gv_verbose) { switch (lv_req.iv_req_type) { case GID_REQ_PING: lp_req_type = "ping"; break; case GID_REQ_ID: lp_req_type = "id"; break; case GID_REQ_ID_TO_STRING: lp_req_type = "id_to_string"; break; case GID_REQ_STRING_TO_ID: lp_req_type = "string_to_id"; break; default: lp_req_type = "unknown"; break; } if (gv_verbose) printf("srv: received msg. req-type=%d(%s), tag=%ld, len=%d\n", lv_req.iv_req_type, lp_req_type, lv_req.iv_req_tag, lv_req.iv_req_len); } switch (lv_req.iv_req_type) { case GID_REQ_PING: if (lv_req.iv_req_len == (int) sizeof(lv_req.u.iv_ping)) { if (gv_verbose) printf("srv: received ping request\n"); lv_rep.iv_rep_type = GID_REP_PING; lv_rep.iv_rep_tag = lv_req.iv_req_tag; lv_rep.iv_rep_len = (int) sizeof(lv_rep.u.iv_ping); lv_rep.u.iv_ping.iv_com.iv_error = GID_ERR_OK; gettimeofday(&lv_tv, NULL); lv_rep.u.iv_ping.iv_ts_sec = lv_tv.tv_sec; lv_rep.u.iv_ping.iv_ts_us = lv_tv.tv_usec; } else { if (gv_verbose) printf("srv: received ping, req-len=%d, expecting len=%d, setting BADCOUNT\n", lv_req.iv_req_len, (int) sizeof(lv_req.u.iv_ping)); lv_ec = XZFIL_ERR_BADCOUNT; } break; case GID_REQ_ID: if (lv_req.iv_req_len == (int) sizeof(lv_req.u.iv_id)) { if (gv_verbose) printf("srv: received id request\n"); lv_rep.iv_rep_type = GID_REP_ID; lv_rep.iv_rep_tag = lv_req.iv_req_tag; lv_rep.iv_rep_len = (int) sizeof(lv_rep.u.iv_id); lv_rep.u.iv_id.iv_com.iv_error = GID_ERR_OK; lv_rep.u.iv_id.iv_id = __sync_add_and_fetch_8(gp_shm, 1); } else { if (gv_verbose) printf("srv: received id, req-len=%d, expecting len=%d, setting BADCOUNT\n", lv_req.iv_req_len, (int) sizeof(lv_req.u.iv_id)); lv_ec = XZFIL_ERR_BADCOUNT; } break; case GID_REQ_ID_TO_STRING: if (lv_req.iv_req_len == (int) sizeof(lv_req.u.iv_id_to_string)) { lv_rep.iv_rep_type = GID_REP_ID_TO_STRING; lv_rep.iv_rep_tag = lv_req.iv_req_tag; lv_req_id = lv_req.u.iv_id_to_string.iv_req_id_to_string; if (gv_verbose) printf("srv: received id_to_string request for id:Ox%lx\n", lv_req_id); lv_orig_ts = long_to_timespec(lv_req_id); lv_ferr = timespec_to_str(lv_rep.u.iv_id_to_string.iv_id_to_string, sizeof(lv_rep.u.iv_id_to_string.iv_id_to_string) , &lv_orig_ts); lv_rep.iv_rep_len = sizeof(lv_rep.u.iv_id_to_string); lv_rep.u.iv_id_to_string.iv_com.iv_error = (GID_Err_Type) lv_ferr; if (gv_verbose){ printf("srv: replying to id_to_string request with err=%d, reply-size %d, string %s, and len%d\n", lv_rep.u.iv_id_to_string.iv_com.iv_error, lv_rep.iv_rep_len, lv_rep.u.iv_id_to_string.iv_id_to_string, (int) strlen(lv_rep.u.iv_id_to_string.iv_id_to_string)); } } else { if (gv_verbose) printf("srv: received id_to_string, req-len=%d, expecting len=%d, setting BADCOUNT\n", lv_req.iv_req_len, (int) sizeof(lv_req.u.iv_id_to_string)); lv_ec = XZFIL_ERR_BADCOUNT; } break; case GID_REQ_STRING_TO_ID: if (lv_req.iv_req_len == (int) sizeof(lv_req.u.iv_string_to_id)) { if (gv_verbose) printf("srv: received string_to_id request, string: %s\n", lv_req.u.iv_string_to_id.iv_string_to_id); lv_rep.iv_rep_type = GID_REP_STRING_TO_ID; lv_rep.iv_rep_tag = lv_req.iv_req_tag; lv_ferr = str_to_tm_id(lv_req.u.iv_string_to_id.iv_string_to_id, &lv_converted_tm_id); lv_rep.u.iv_string_to_id.iv_string_to_id = lv_converted_tm_id; lv_rep.iv_rep_len = sizeof(lv_rep.u.iv_string_to_id); lv_rep.u.iv_string_to_id.iv_com.iv_error = (GID_Err_Type) lv_ferr; if (lv_ferr != XZFIL_ERR_OK) lv_ec = lv_ferr; if (gv_verbose) printf("srv: replying to string_to_id request with err=%d, size %d, and id %ld\n", lv_ferr, lv_rep.iv_rep_len, lv_converted_tm_id); } else { if (gv_verbose) printf("srv: received string_to_id, req-len=%d, expecting len=%d, setting BADCOUNT\n", lv_req.iv_req_len, (int) sizeof(lv_req.u.iv_string_to_id)); lv_ec = XZFIL_ERR_BADCOUNT; } break; default: if (gv_verbose) printf("srv: received unknown req-type=%d, setting INVALOP\n", lv_req.iv_req_type); lv_ec = XZFIL_ERR_INVALOP; break; } } if (gv_verbose){ if(lv_rep.iv_rep_type == GID_REP_ID_TO_STRING){ printf("srv: reply, rep-type=%d, tag=%ld, id_to_string=%s, len=%d\n", lv_rep.iv_rep_type, lv_rep.iv_rep_tag, lv_rep.u.iv_id_to_string.iv_id_to_string, lv_rep.iv_rep_len); } else { printf("srv: reply, rep-type=%d, tag=%ld, id=%ld, len=%d\n", lv_rep.iv_rep_type, lv_rep.iv_rep_tag, lv_rep.u.iv_id.iv_id, lv_rep.iv_rep_len); } } lv_len = (int) sizeof(lv_rep); do_reply(pp_sre, (char *) &lv_rep, lv_len, lv_ec); }
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; }
// // process non-mon message // void do_req(BMS_SRE *sre) { short ec; int ferr; int len; GID_Rep rep; GID_Req req; const char *req_type; struct timeval tv; ec = XZFIL_ERR_OK; len = 0; if (verbose) printf("srv: received NON-mon message\n"); if (sre->sre_reqDataSize < (int) sizeof(req)) { if (verbose) printf("srv: received short data - sre_reqDataSize=%d, expecting len=%d, setting BADCOUNT\n", sre->sre_reqDataSize, (int) sizeof(req)); ec = XZFIL_ERR_BADCOUNT; } else { ferr = BMSG_READDATA_(sre->sre_msgId, // msgid (char *) &req, // reqdata (int) sizeof(req)); // bytecount assert(ferr == XZFIL_ERR_OK); if (verbose) { switch (req.req_type) { case GID_REQ_PING: req_type = "ping"; break; case GID_REQ_ID: req_type = "id"; break; default: req_type = "unknown"; break; } if (verbose) printf("srv: received msg. req-type=%d(%s), tag=%ld, len=%d\n", req.req_type, req_type, req.req_tag, req.req_len); } switch (req.req_type) { case GID_REQ_PING: if (req.req_len == (int) sizeof(req.u.ping)) { if (verbose) printf("srv: received ping request\n"); rep.rep_type = GID_REP_PING; rep.rep_tag = req.req_tag; rep.rep_len = (int) sizeof(rep.u.ping); rep.u.ping.com.error = GID_ERR_OK; gettimeofday(&tv, NULL); rep.u.ping.ts_sec = tv.tv_sec; rep.u.ping.ts_us = tv.tv_usec; } else { if (verbose) printf("srv: received ping, req-len=%d, expecting len=%d, setting BADCOUNT\n", req.req_len, (int) sizeof(req.u.ping)); ec = XZFIL_ERR_BADCOUNT; } break; case GID_REQ_ID: if (req.req_len == (int) sizeof(req.u.id)) { if (verbose) printf("srv: received id request\n"); rep.rep_type = GID_REP_ID; rep.rep_tag = req.req_tag; rep.rep_len = (int) sizeof(rep.u.id); rep.u.id.com.error = GID_ERR_OK; rep.u.id.id = __sync_add_and_fetch_8(shm, 1); } else { if (verbose) printf("srv: received id, req-len=%d, expecting len=%d, setting BADCOUNT\n", req.req_len, (int) sizeof(req.u.id)); ec = XZFIL_ERR_BADCOUNT; } break; default: if (verbose) printf("srv: received unknown req-type=%d, setting INVALOP\n", req.req_type); ec = XZFIL_ERR_INVALOP; break; } } if (ec == XZFIL_ERR_OK) { if (verbose) printf("srv: reply, rep-type=%d, tag=%ld, len=%d\n", rep.rep_type, rep.rep_tag, rep.rep_len); len = (int) sizeof(rep); } else { len = 0; } do_reply(sre, (char *) &rep, len, ec); }
// // process non-mon message // void do_req(BMS_SRE *pp_sre) { const char *lp_req_type; short lv_ec; int lv_ferr; int lv_len; GID_Rep lv_rep; GID_Req lv_req; struct timeval lv_tv; lv_ec = XZFIL_ERR_OK; lv_len = 0; if (gv_verbose) printf("srv: received NON-mon message\n"); if (pp_sre->sre_reqDataSize < (int) sizeof(lv_req)) { if (gv_verbose) printf("srv: received short data - sre_reqDataSize=%d, expecting len=%d, setting BADCOUNT\n", pp_sre->sre_reqDataSize, (int) sizeof(lv_req)); lv_ec = XZFIL_ERR_BADCOUNT; } else { lv_ferr = BMSG_READDATA_(pp_sre->sre_msgId, // msgid (char *) &lv_req, // reqdata (int) sizeof(lv_req)); // bytecount assert(lv_ferr == XZFIL_ERR_OK); if (gv_verbose) { switch (lv_req.iv_req_type) { case GID_REQ_PING: lp_req_type = "ping"; break; case GID_REQ_ID: lp_req_type = "id"; break; default: lp_req_type = "unknown"; break; } if (gv_verbose) printf("srv: received msg. req-type=%d(%s), tag=%ld, len=%d\n", lv_req.iv_req_type, lp_req_type, lv_req.iv_req_tag, lv_req.iv_req_len); } switch (lv_req.iv_req_type) { case GID_REQ_PING: if (lv_req.iv_req_len == (int) sizeof(lv_req.u.iv_ping)) { if (gv_verbose) printf("srv: received ping request\n"); lv_rep.iv_rep_type = GID_REP_PING; lv_rep.iv_rep_tag = lv_req.iv_req_tag; lv_rep.iv_rep_len = (int) sizeof(lv_rep.u.iv_ping); lv_rep.u.iv_ping.iv_com.iv_error = GID_ERR_OK; gettimeofday(&lv_tv, NULL); lv_rep.u.iv_ping.iv_ts_sec = lv_tv.tv_sec; lv_rep.u.iv_ping.iv_ts_us = lv_tv.tv_usec; } else { if (gv_verbose) printf("srv: received ping, req-len=%d, expecting len=%d, setting BADCOUNT\n", lv_req.iv_req_len, (int) sizeof(lv_req.u.iv_ping)); lv_ec = XZFIL_ERR_BADCOUNT; } break; case GID_REQ_ID: if (lv_req.iv_req_len == (int) sizeof(lv_req.u.iv_id)) { if (gv_verbose) printf("srv: received id request\n"); lv_rep.iv_rep_type = GID_REP_ID; lv_rep.iv_rep_tag = lv_req.iv_req_tag; lv_rep.iv_rep_len = (int) sizeof(lv_rep.u.iv_id); lv_rep.u.iv_id.iv_com.iv_error = GID_ERR_OK; lv_rep.u.iv_id.iv_id = __sync_add_and_fetch_8(gp_shm, 1); } else { if (gv_verbose) printf("srv: received id, req-len=%d, expecting len=%d, setting BADCOUNT\n", lv_req.iv_req_len, (int) sizeof(lv_req.u.iv_id)); lv_ec = XZFIL_ERR_BADCOUNT; } break; default: if (gv_verbose) printf("srv: received unknown req-type=%d, setting INVALOP\n", lv_req.iv_req_type); lv_ec = XZFIL_ERR_INVALOP; break; } } if (lv_ec == XZFIL_ERR_OK) { if (gv_verbose) printf("srv: reply, rep-type=%d, tag=%ld, len=%d\n", lv_rep.iv_rep_type, lv_rep.iv_rep_tag, lv_rep.iv_rep_len); lv_len = (int) sizeof(lv_rep); } else { lv_len = 0; } do_reply(pp_sre, (char *) &lv_rep, lv_len, lv_ec); }
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; }
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; }
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; }
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; }