// // Reset the global time counter // void reset_time_counter() { struct timespec lv_new_ts; clock_gettime(CLOCK_REALTIME, &lv_new_ts); unsigned long lv_new_tsl = ((unsigned long) lv_new_ts.tv_sec << 20) | ((unsigned long) lv_new_ts.tv_nsec / 1000); if (gv_verbose) printf("srv: reset_time_counter, original ts =0x%lx,0x%lx converted time 0x%lx\n", lv_new_ts.tv_sec, lv_new_ts.tv_nsec, lv_new_tsl); unsigned long lv_existing_tsl = __sync_add_and_fetch_8(gp_shm, 0); __sync_add_and_fetch_8(gp_shm, lv_new_tsl - lv_existing_tsl); if (gv_verbose) printf("srv: reset_time_counter, adjustment=0x%lx, shm=0x%lx\n", lv_new_tsl - lv_existing_tsl, *gp_shml); }
// // 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; 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); }
// // 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); }