// make one pass through msgs_from_host with handled == 0 // return true if there were any // bool do_message_scan() { DB_MSG_FROM_HOST mfh; char buf[256]; bool found=false; int retval; sprintf(buf, "where handled=0"); while (1) { retval = mfh.enumerate(buf); if (retval) { if (retval != ERR_DB_NOT_FOUND) { log_messages.printf(MSG_DEBUG, "DB connection lost, exiting\n" ); exit(0); } break; } retval = handle_message(mfh); if (!retval) { mfh.handled = true; mfh.update(); } found = true; } return found; }
void handle_msgs_from_host() { unsigned int i; DB_MSG_FROM_HOST mfh; int retval; for (i=0; i<g_request->msgs_from_host.size(); i++) { g_reply->send_msg_ack = true; MSG_FROM_HOST_DESC& md = g_request->msgs_from_host[i]; mfh.clear(); mfh.create_time = time(0); safe_strcpy(mfh.variety, md.variety); mfh.hostid = g_reply->host.id; mfh.handled = false; safe_strcpy(mfh.xml, md.msg_text.c_str()); log_messages.printf(MSG_NORMAL, "got msg from host; variety %s \n", mfh.variety ); retval = mfh.insert(); if (retval) { log_messages.printf(MSG_CRITICAL, "[HOST#%d] message insert failed: %s\n", g_reply->host.id, boincerror(retval) ); g_reply->send_msg_ack = false; // may as well return; if one insert failed, others will too // return; } } }
// make one pass through trickle_ups with handled == 0 // return true if there were any // bool do_trickle_scan() { DB_MSG_FROM_HOST mfh; char buf[256]; bool found=false; int retval; sprintf(buf, "where variety='%s' and handled=0", variety); while (1) { retval = mfh.enumerate(buf); if (retval) { if (retval != ERR_DB_NOT_FOUND) { fprintf(stderr, "lost DB conn\n"); exit(1); } break; } retval = handle_trickle(mfh); if (!retval) { log_messages.printf(MSG_CRITICAL, "handle_trickle(): %s", boincerror(retval) ); } mfh.handled = true; mfh.update(); found = true; } return found; }