inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_period& tp) { gregorian::date d(not_a_date_time); time_duration td(0,0,0); ptime beg(d, td); ptime end(beg); std::basic_string<charT> s; // get first date string and remove leading '[' is >> s; { std::basic_stringstream<charT> ss; ss << s.substr(s.find('[')+1); ss >> d; } // get first time_duration & second date string, remove the '/' // and split into 2 strings is >> s; { std::basic_stringstream<charT> ss; ss << s.substr(0, s.find('/')); ss >> td; } beg = ptime(d, td); { std::basic_stringstream<charT> ss; ss << s.substr(s.find('/')+1); ss >> d; } // get last time_duration and remove the trailing ']' is >> s; { std::basic_stringstream<charT> ss; ss << s.substr(0, s.find(']')); ss >> td; } end = ptime(d, td); tp = time_period(beg,end); return is; }
void perslog (char *verb, const char *pers) {FILE *fp; char buffer [PROOL_MAX_STRLEN]; char *ident; if (mudname[0]) ident=mudname; else ident = "Zerkalo"; fp=fopen(PERSLOG_FILE, "a"); fprintf(fp,"%s %s %s\n",ptime(),pers,verb); if (console_codetable==T_UTF) { koi_to_utf8((char*)pers,buffer); printf("%s %s %s %s\n",ident,ptime(),buffer,verb); } else { printf("%s %s %s %s\n",ident,ptime(),pers,verb); } fclose(fp); }
static CTime ConvertTime_tToCtime( const time_t * t) { int nYear, nMonth, nDate, nHour, nMin, nSec; struct tm *local = localtime(t); nYear = local->tm_year + 1900; nMonth = local->tm_mon + 1; nDate = local->tm_mday; nHour = local->tm_hour; nMin = local->tm_min; nSec = local->tm_sec; CTime ptime(nYear, nMonth, nDate, nHour, nMin, nSec); return ptime; }
/* we have added a granted lock, or a lock request, or an owned lock. * all locks time out by themselves if they aren't explicitly updated * as part of the cloud protocol. for the given lock, set its timeout * time, and schedule a timer interrupt when that time is reached. */ void set_lock_timer(lockable_resource_t *l) { struct timeval now; /* don't know why we commented this out; probably a mistake */ // if (!db[22].d) { return; } if (db[28].d) { ddprintf("set_lock_timer..\n"); } while (!checked_gettimeofday(&now)); l->sec = now.tv_sec; l->usec = now.tv_usec; usec_add_msecs(&l->sec, &l->usec, RECV_TIMEOUT_USEC / 1000); reset_lock_timer(); if (db[28].d) { ptime("\nset_lock_timer now", now); ptime("set_lock_timer interrupt", times[4]); ddprintf("\n"); } } /* set_lock_timer */
void update_fps() { ++g_num_frames; double t = ptime(); if (t - g_last_fps_update >= update_interval) { float fps = (float)(g_num_frames / (t - g_last_fps_update)); char buf[255]; snprintf(buf, sizeof(buf), title_format, fps); buf[sizeof(buf) - 1] = '\0'; g_last_fps_update = t; g_num_frames = 0; glutSetWindowTitle(buf); } }
ptime StreamData::GetDateTime(std::string s) { // parse 2012-02-03T17:31:51.0968Z int Year, Month, Day, Hour, Minute, Second, Millisecond; if(sscanf(s.c_str(), "%d-%d-%dT%d:%d:%d.%d", &Year, &Month, &Day, &Hour, &Minute,&Second, &Millisecond)==7){} //12/2/2009 2:42:25 PM else if(sscanf(s.c_str(), "%d/%d/%4d%d:%d:%d", &Month, &Day, &Year, &Hour, &Minute,&Second)==6){} else throw std::exception("Unrecognized date-time format\n"); return ptime( date(Year,Month,Day), hours(Hour) + minutes(Minute) + seconds(Second) + boost::posix_time::millisec(int(Millisecond)) ); //return COleDateTime( Year, Month, Day, Hour, Minute, Second ); }
void update() { double t = ptime(); if (g_update) { g_cloth->lock(); if (g_script != NULL) { g_script->update(0.01f); } g_cloth->step(0.01f); g_cloth->unlock(); } glutPostRedisplay(); }
/* * A queue polling processor for ebxml queues - register this with * the qpoller. * * This builds an ebXML MIME message, opens a connection to a * receiver, sends the request, processes the response, and * finally updates the queue status. */ int ebxml_qprocessor (XML *xml, QUEUEROW *r) { MIME *m; /* * build an ebXML MIME message */ if ((m = ebxml_getmessage (xml, r)) == NULL) { char buf[24]; queue_field_set (r, "MESSAGECREATIONTIME", ptime (NULL, buf)); queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "failed"); queue_field_set (r, "TRANSPORTERRORCODE", "bad message"); queue_push (r); return (-1); } /* * update the queue with message status */ debug ("updating queue\n"); queue_field_set (r, "PROCESSINGSTATUS", "waiting"); queue_field_set (r, "TRANSPORTSTATUS", "attempted"); queue_field_set (r, "TRANSPORTERRORCODE", ""); queue_push (r); /* * send it to the destination */ debug ("sending to destination\n"); if (ebxml_send (xml, r, m) == 0) ebxml_file_ack (xml, r); /* * update the queue with status from the reply */ debug ("updating reply\n"); queue_push (r); /* * release all memory */ mime_free (m); info ("ebXML %s:%d send completed\n", r->queue->name, r->rowid); return (0); }
void CLogger::log(const string & message, const string & level, const string & category) { SLogElement element; element.message = message; element.level = level; element.category = category; element.time = ptime(from_time_t(time(0))); _logs.push_back(element); ++_logCount; if (hasEventHandler("onLog")) { CEvent event(this, boost::assign::map_list_of("logItem", (void*)&element)); onLog(event); } if (autoFlush > 0 && _logCount >= autoFlush && !_processing) { _processing = true; flush(autoDump); _processing = false; } }
CommandBase* ParserList::makeCmdListSpecificMonth(string monthStr) { int parsedMonth; // Parse month, if month is valid try { parsedMonth = parseMonth(monthStr); } catch (invalid_argument) { return NULL; } // Ensure that the month is the coming month, and not a month which // has already passed date currentDate = second_clock::local_time().date(); date startDate = date(currentDate.year(), parsedMonth, 1); if (currentDate.month() > parsedMonth) { startDate += years(1); } ptime startTime = ptime(startDate); ptime endTime = getLastOfMonth(startTime); return makeCmdListPeriod(startTime, endTime); }
/* verify memory or file */ static int verify_data(pgpv_t *pgp, const char *cmd, const char *inname, char *in, ssize_t cc) { pgpv_cursor_t cursor; const char *modifiers; size_t size; size_t cookie; char *data; int el; memset(&cursor, 0x0, sizeof(cursor)); if (strcasecmp(cmd, "cat") == 0) { if ((cookie = pgpv_verify(&cursor, pgp, in, cc)) != 0) { if ((size = pgpv_get_verified(&cursor, cookie, &data)) > 0) { write(STDOUT_FILENO, data, size); } return 1; } } else if (strcasecmp(cmd, "dump") == 0) { if ((cookie = pgpv_verify(&cursor, pgp, in, cc)) != 0) { size = pgpv_dump(pgp, &data); write(STDOUT_FILENO, data, size); return 1; } } else if (strcasecmp(cmd, "verify") == 0 || strcasecmp(cmd, "trust") == 0) { modifiers = (strcasecmp(cmd, "trust") == 0) ? "trust" : NULL; if (pgpv_verify(&cursor, pgp, in, cc)) { printf("Good signature for %s made ", inname); ptime(cursor.sigtime); el = pgpv_get_cursor_element(&cursor, 0); pentry(pgp, el, modifiers); return 1; } fprintf(stderr, "Signature did not match contents -- %s\n", cursor.why); } else { fprintf(stderr, "unrecognised command \"%s\"\n", cmd); } return 0; }
/* send data */ int ircsend( int ssock, const char *fmt, ... ) { if ( !fmt ) return -1; /* format to sendbuf */ char sendbuf[512]; va_list arg; va_start(arg,fmt); vsnprintf(sendbuf,512,fmt,arg); va_end(arg); /* trim if line is too long */ if ( strlen(sendbuf) > 350 ) { sendbuf[350] = '\0'; strcat(sendbuf,"..."); } ptime("[%Y/%m/%d %H:%M:%S]",NULL); printf(" >>> %s\n",sendbuf); /* special check, autoquit */ if ( !strncasecmp(strcat(sendbuf,"\r\n"),"QUIT",4) ) active = 0; /* time to send */ return send(ssock,sendbuf,strlen(sendbuf),0); }
inline ptime time_now() { return ptime(mach_absolute_time()); }
inline ptime max_time() { return ptime((std::numeric_limits<boost::int64_t>::max)()); }
inline ptime min_time() { return ptime(0); }
//! Convert a tm struct to a ptime ignoring is_dst flag inline ptime ptime_from_tm(const std::tm& timetm) { boost::gregorian::date d = boost::gregorian::date_from_tm(timetm); return ptime(d, time_duration(timetm.tm_hour, timetm.tm_min, timetm.tm_sec)); }
int main(int argc, char **argv) { char filename[PATH_MAX]; int sz = 0; char *data = NULL; sprintf(filename, "/tmp/speedy.6.%x.F", geteuid()); FILE *fh = fopen(filename, "r"); if (fh) { struct stat st; if (stat(filename, &st) == 0) { sz = st.st_size; } if (sz) { data = malloc(sz); fread(data, 1, sz, fh); } } else { printf("Cannot read file (%s).\n", filename); } if (data) { speedy_file_t *speedy_file_maddr = (speedy_file_t*)data; file_head_t *h = &FILE_HEAD; slotnum_t slotnum, num1; slot_t *slot; int i; time_t ctime = h->create_time.tv_sec; printf("{\n"); printf(" header => {\n"); printf(" create_time => { sec => %d, usec => %d, text => '%s' },\n", h->create_time.tv_sec, h->create_time.tv_usec, ptime(&ctime)); printf(" lock_owner => %d,\n", h->lock_owner); printf(" group_head => %d,\n", h->group_head); printf(" group_tail => %d,\n", h->group_tail); printf(" slot_free => %d,\n", h->slot_free); printf(" slots_alloced => %d,\n", h->slots_alloced); printf(" fe_run_head => %d,\n", h->fe_run_head); printf(" fe_run_tail => %d,\n", h->fe_run_tail); printf(" file_removed => %d\n", h->file_removed); printf(" },\n"); printf(" free_slots => [ "); for (slotnum = h->slot_free; !BAD_SLOTNUM(slotnum); slotnum = speedy_slot_next(slotnum)) { printf("%d", slotnum); if (!BAD_SLOTNUM(speedy_slot_next(slotnum))) printf(", "); } printf(" ],\n"); printf(" fe_running => [ "); for (slotnum = h->fe_run_head; !BAD_SLOTNUM(slotnum); slotnum = speedy_slot_next(slotnum)) { printf("%d\n", slotnum); if (!BAD_SLOTNUM(speedy_slot_next(slotnum))) printf(", "); } printf(" ],\n"); printf(" group_list => {\n"); for (slotnum = h->group_head; !BAD_SLOTNUM(slotnum); slotnum = speedy_slot_next(slotnum)) { gr_slot_t *gr = &FILE_SLOT(gr_slot, slotnum); grnm_slot_t *name = &FILE_SLOT(grnm_slot, gr->name_slot); scr_slot_t *scr = &FILE_SLOT(scr_slot, gr->script_head); printf(" index => %d,\n", slotnum); printf(" be_starting => %d,\n", gr->be_starting); printf(" be_parent => { pid => %d },\n", gr->be_parent); printf(" script_head => %d,\n", gr->script_head); printf(" scripts => [\n"); for (num1 = gr->script_head; !BAD_SLOTNUM(num1); num1 = speedy_slot_next(num1)) { scr = &FILE_SLOT(scr_slot, num1); printf(" {\n"); printf(" index => %d,\n", num1); printf(" dev_num => %d,\n", scr->dev_num); printf(" ino_num => %d,\n", scr->ino_num); printf(" mtime => { sec => %d, text => '%s' }\n", scr->mtime, ptime(&scr->mtime)); printf(" }"); if (!BAD_SLOTNUM(speedy_slot_next(slotnum))) printf(", "); } printf(" ],\n"); printf(" name_slot => { index => %d, text => '%s' },\n", gr->name_slot, name->name); printf(" be_head => %d,\n", gr->be_head); printf(" be_tail => %d,\n", gr->be_tail); printf(" fe_head => %d,\n", gr->fe_head); printf(" fe_tail => %d,\n", gr->fe_tail); printf(" fe_wait_list => [\n"); for (num1 = gr->fe_head; !BAD_SLOTNUM(num1); num1 = speedy_slot_next(num1)) { fe_slot_t *fe = &FILE_SLOT(fe_slot, num1); printf(" {\n"); printf(" index => %d,\n", num1); printf(" pid => { pid => %d },\n", fe->pid); printf(" exit_val => %d,\n", fe->exit_val); printf(" backend => %d,\n", fe->backend); printf(" exit_on_sig => %d,\n", fe->exit_on_sig); printf(" sent_sig => %d,\n", fe->sent_sig); printf(" },\n"); } printf(" ],\n"); printf(" be_list => [\n"); for (num1 = gr->be_head; !BAD_SLOTNUM(num1); num1 = speedy_slot_next(num1)) { be_slot_t *be = &FILE_SLOT(be_slot, num1); printf(" {\n"); printf(" index => %d,\n", num1); printf(" pid => { pid => %d },\n", be->pid); printf(" fe_running => %d,\n", be->fe_running); printf(" maturity => %d\n", be->maturity); printf(" },\n"); } printf(" ]\n"); printf(" }\n"); } printf("}\n"); } return 0; }
inline void message_queue::receive(void *buffer, std::size_t buffer_size, std::size_t &recvd_size, unsigned int &priority) { this->do_receive(blocking, buffer, buffer_size, recvd_size, priority, ptime()); }
/* * send a message * return non-zero if message not sent successful with completed * queue info for status and transport */ int ebxml_send (XML*xml, QUEUEROW *r, MIME *msg) { DBUF *b; NETCON *conn; char host[MAX_PATH]; /* need buffers for redirect */ char path[MAX_PATH]; int port, route, timeout, delay, retry; SSL_CTX *ctx; char *rname, /* route name */ *content, /* message content */ buf[MAX_PATH]; /* format up the message */ if ((content = mime_format (msg)) == NULL) { queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "failed"); queue_field_set (r, "TRANSPORTERRORCODE", "failed formatting message"); return (-1); } debug ("Send content:\n%s\n", content); /* * get connection info from the record route */ if ((route = cfg_route_index (xml, queue_field_get (r, "ROUTEINFO"))) < 0) { queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "failed"); queue_field_set (r, "TRANSPORTERRORCODE", "bad route"); return (-1); } rname = cfg_route (xml, route, "Name"); ctx = ebxml_route_ctx (xml, route); strcpy (host, cfg_route (xml, route, "Host")); port = atoi (cfg_route (xml, route, "Port")); if ((retry = atoi (cfg_route (xml, route, "Retry"))) == 0) retry = cfg_retries (xml); timeout = atoi (cfg_route (xml, route, "Timeout")); delay = cfg_delay (xml); strcpy (path, cfg_route (xml, route, "Path")); sendmsg: info ("Sending ebXML %s:%d to %s\n", r->queue->name, r->rowid, rname); debug ("opening connection socket on port=%d retrys=%d timeout=%d\n", port, retry, timeout); if ((conn = net_open (host, port, 0, ctx)) == NULL) { error ("failed opening connection to %s:%d\n", host, port); goto retrysend; } /* set read timeout if given */ if (timeout) { net_timeout (conn, timeout * 1000); timeout <<= 1; /* bump each try */ } delay = 0; /* connection OK, don't delay */ queue_field_set (r, "MESSAGESENTTIME", ptime (NULL, buf)); sprintf (buf, "POST %s HTTP/1.1\r\n", path); // ch = ebxml_beautify (ch); /* all set... send the message */ debug ("sending message...\n"); net_write (conn, buf, strlen (buf)); net_write (conn, content, strlen (content)); debug ("reading response...\n"); b = ebxml_receive (conn); debug ("closing socket...\n"); net_close (conn); /* no reply? */ if (b == NULL) { warn ("Send response timed out or closed for %s\n", rname); retrysend: /* retry with a wait, or.. */ if (retry-- && phineas_running ()) { if (delay) { info ("Retrying send to %s in %d seconds\n", rname, delay); sleep (delay * 1000); delay <<= 1; } else /* reset connection delay */ delay = cfg_delay (xml); goto sendmsg; } if (ctx != NULL) /* give up! */ SSL_CTX_free (ctx); free (content); queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "failed"); queue_field_set (r, "TRANSPORTERRORCODE", "retries exhausted"); return (-1); } debug ("reply was %d bytes\n%.*s\n", dbuf_size (b), dbuf_size (b), dbuf_getbuf (b)); /* * handle redirects... * note this assumes the same SSL context should be used */ if (ebxml_redirect (dbuf_getbuf (b), host, &port, path)) { dbuf_free (b); goto sendmsg; } if (ctx != NULL) SSL_CTX_free (ctx); if (ebxml_parse_reply (dbuf_getbuf (b), r)) { queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "failed"); queue_field_set (r, "TRANSPORTERRORCODE", "garbled reply"); } debug ("send completed\n"); dbuf_free (b); free (content); return (0); }
inline void message_queue::send (const void *buffer, std::size_t buffer_size, unsigned int priority) { this->do_send(blocking, buffer, buffer_size, priority, ptime()); }
/* * parse a reply message and update the queue row with status */ int ebxml_parse_reply (char *reply, QUEUEROW *r) { MIME *msg, *part; XML *xml; char *ch, buf[PTIMESZ]; if (ebxml_status (reply)) return (-1); if ((msg = mime_parse (reply)) == NULL) { error ("Failed parsing reply message\n"); return (-1); } /* check the ebxml envelope for ack or error */ if ((part = mime_getMultiPart (msg, 1)) == NULL) { error ("Reply missing ebxml envelope\n"); mime_free (msg); return (-1); } if ((xml = xml_parse (mime_getBody (part))) == NULL) { error ("Failed parsing ebxml envelop\n"); mime_free (msg); return (-1); } strcpy (buf, xml_get_text (xml, SOAPACTION)); if (!strcmp (buf, "MessageError")) { debug ("Error reply received!\n"); queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "failed"); ch = xml_get_attribute (xml, SOAPERROR, "eb:errorCode"); debug ("%s eb:errorCode %s\n", SOAPERROR, ch); queue_field_set (r, "TRANSPORTERRORCODE", ch); queue_field_set (r, "APPLICATIONSTATUS", "not-set"); queue_field_set (r, "APPLICATIONERRORCODE", "none"); ch = xml_get_text (xml, SOAPERROR); debug ("SOAPERROR %s\n", ch); queue_field_set (r, "APPLICATIONRESPONSE", ch); queue_field_set (r, "MESSAGERECEIVEDTIME", ptime (NULL, buf)); xml_free (xml); mime_free (msg); return (0); } xml_free (xml); /* Ping reply */ if (strcmp (queue_field_get (r, "ACTION"), "Ping") == 0) { if (strcmp (buf, "Pong")) { error ("Expected 'Pong' action but got '%s'\n", buf); mime_free (msg); return (-1); } queue_field_set (r, "APPLICATIONSTATUS", "not-set"); queue_field_set (r, "APPLICATIONERRORCODE", "none"); queue_field_set (r, "APPLICATIONRESPONSE", "none"); queue_field_set (r, "MESSAGERECEIVEDTIME", ptime (NULL, buf)); } else /* regular reply */ { if ((part = mime_getMultiPart (msg, 2)) == NULL) { error ("Reply missing status part\n"); mime_free (msg); return (-1); } debug ("Body is...\n%s\n", mime_getBody (part)); if ((xml = xml_parse (mime_getBody (part))) == NULL) { error ("Miss formatted Reply status\n"); mime_free (msg); return (-1); } queue_field_set (r, "APPLICATIONSTATUS", xml_get_text (xml, "response.msh_response.status")); queue_field_set (r, "APPLICATIONERRORCODE", xml_get_text (xml, "response.msh_response.error")); queue_field_set (r, "APPLICATIONRESPONSE", xml_get_text (xml, "response.msh_response.appdata")); queue_field_set (r, "MESSAGERECEIVEDTIME", ptime (NULL, buf)); /* TODO... queue_field_set (r, "RESPONSEMESSAGEID", ""); queue_field_set (r, "RESPONSEARGUMENTS", ""); queue_field_set (r, "RESPONSELOCALFILE", ""); queue_field_set (r, "RESPONSEFILENAME", ""); queue_field_set (r, "RESPONSEMESSAGEORIGIN", ""); queue_field_set (r, "RESPONSEMESSAGESIGNATURE", ""); */ xml_free (xml); } queue_field_set (r, "PROCESSINGSTATUS", "done"); queue_field_set (r, "TRANSPORTSTATUS", "success"); queue_field_set (r, "TRANSPORTERRORCODE", "none"); mime_free (msg); return (0); }
inline ptime operator+(time_duration lhs, ptime rhs) { return ptime(rhs.time + lhs.diff); }
/* of the various timers (currently 8), figure out which one is due to * happen soonest, and set a timer interrupt to go off to wake us up then. */ void set_next_alarm() { long long next_interrupt, maybe_next; while (!checked_gettimeofday(&now)); if (db[2].d) { ptime("now", now); ptime("t0", times[0]); ptime("t1", times[1]); ptime("t2", times[2]); ptime("t3", times[3]); ptime("t4", times[4]); ptime("t5", times[5]); ptime("t6", times[6]); ptime("t7", times[7]); ddprintf("\n"); } /* see if we are past time of next expected interrupt here, and if so * note it and reset timer for the future. */ /* this is the exponential timer for stp_beacons */ while ((next_interrupt = usec_diff(times[0].tv_sec, times[0].tv_usec, now.tv_sec, now.tv_usec)) < 0) { double wait_time; int iwait_time; if (db[39].d) { int mean_wait_time = MEAN_WAKEUP_TIME; if (stp_recv_beacon_count > 0) { mean_wait_time *= stp_recv_beacon_count; } wait_time = neg_exp(mean_wait_time); } else { wait_time = neg_exp(MEAN_WAKEUP_TIME); } iwait_time = (int) wait_time; if (db[40].d) { iwait_time *= 20; ddprintf("set stp_send timeout to %d\n", iwait_time); } usec_add_msecs(×[0].tv_sec, ×[0].tv_usec, iwait_time); if (!db[54].d) { got_interrupt[send_stp] = 1; } } /* same as above */ /* this is the wrt_beacon processing interval */ while ((maybe_next = usec_diff(times[1].tv_sec, times[1].tv_usec, now.tv_sec, now.tv_usec)) < 0) { usec_add_msecs(×[1].tv_sec, ×[1].tv_usec, intervals[1]); got_interrupt[process_beacon] = 1; } if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } /* same as above */ /* this is the eth_beacon processing interval */ while ((maybe_next = usec_diff(times[2].tv_sec, times[2].tv_usec, now.tv_sec, now.tv_usec)) < 0) { usec_add_msecs(×[2].tv_sec, ×[2].tv_usec, intervals[2]); got_interrupt[process_eth_beacon] = 1; } if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } /* non-cloud message timeout */ if (times[3].tv_sec != -1) { maybe_next = usec_diff(times[3].tv_sec, times[3].tv_usec, now.tv_sec, now.tv_usec); if (maybe_next < 0) { times[3].tv_sec = -1; got_interrupt[noncloud_message] = 1; } else if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } } /* lockable resource timeout */ if (times[4].tv_sec != -1) { maybe_next = usec_diff(times[4].tv_sec, times[4].tv_usec, now.tv_sec, now.tv_usec); if (maybe_next < 0) { times[4].tv_sec = -1; got_interrupt[lockable_timeout] = 1; if (db[28].d) { ddprintf("\nset_next_alarm; " "detected lockable resource timeout..\n"); } } else if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } } /* print to cloud.asp timeout */ if (times[5].tv_sec != -1) { maybe_next = usec_diff(times[5].tv_sec, times[5].tv_usec, now.tv_sec, now.tv_usec); if (maybe_next < 0) { times[5].tv_sec = -1; got_interrupt[print_cloud] = 1; if (db[28].d) { ddprintf("\nset_next_alarm; " "detected print_cloud timeout..\n"); } } else if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } } /* ping neighbor timeout */ if (times[6].tv_sec != -1) { maybe_next = usec_diff(times[6].tv_sec, times[6].tv_usec, now.tv_sec, now.tv_usec); if (maybe_next < 0) { times[6].tv_sec = -1; got_interrupt[ping_neighbors] = 1; if (db[28].d) { ddprintf("\nset_next_alarm; " "detected ping_neighbors timeout..\n"); } } else if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } } /* disable cloud.asp printing timeout */ if (times[7].tv_sec != -1) { maybe_next = usec_diff(times[7].tv_sec, times[7].tv_usec, now.tv_sec, now.tv_usec); if (maybe_next < 0) { times[7].tv_sec = -1; got_interrupt[disable_print_cloud] = 1; if (db[28].d) { ddprintf("\nset_next_alarm; " "detected disable print cloud timeout..\n"); } } else if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } } /* wifi scan timeout */ if (times[8].tv_sec != -1) { maybe_next = usec_diff(times[8].tv_sec, times[8].tv_usec, now.tv_sec, now.tv_usec); if (maybe_next < 0) { times[8].tv_sec = -1; got_interrupt[wifi_scan] = 1; if (db[28].d) { ddprintf("\nset_next_alarm; " "detected wifi_scan timeout..\n"); } } else if (maybe_next < next_interrupt) { next_interrupt = maybe_next; } } set_alarm((int) (next_interrupt / 1000)); if (db[2].d) { int i; ptime("end", now); ptime("t0", times[0]); ptime("t1", times[1]); ptime("t2", times[2]); ptime("t3", times[3]); ptime("t4", times[4]); ptime("t5", times[5]); ptime("t6", times[6]); ptime("t7", times[7]); ptime("t8", times[8]); ddprintf("\ninterrupts pending: "); for (i = 0; i < TIMER_COUNT; i++) { if (got_interrupt[i]) { ddprintf(" %d", i); } } ddprintf("\nwaiting %d msec\n", (int) (next_interrupt / 1000)); } } /* set_next_alarm */
inline bool message_queue::try_receive(void *buffer, std::size_t buffer_size, std::size_t &recvd_size, unsigned int &priority) { return this->do_receive(non_blocking, buffer, buffer_size, recvd_size, priority, ptime()); }
inline ptime time_now() { LARGE_INTEGER now; QueryPerformanceCounter(&now); return ptime(now.QuadPart); }
/* * move blocks between queues if they are ready. * schedule an interrupt for the next interesting time. * * must be called with the link ilocked. */ static void pushlink(Link *link, vlong now) { Block *bp; vlong tout, tin; /* * put another block in the link queue */ ilock(link); if(link->iq == nil || link->oq == nil){ iunlock(link); return; } timerdel(&link->ci); /* * put more blocks into the xmit queue * use the time the last packet was supposed to go out * as the start time for the next packet, rather than * the current time. this more closely models a network * device which can queue multiple output packets. */ tout = link->tout; if(!tout) tout = now; while(tout <= now){ bp = qget(link->oq); if(bp == nil){ tout = 0; break; } /* * can't send the packet before it gets queued */ tin = gtime(bp->rp); if(tin > tout) tout = tin; tout = tout + (BLEN(bp) - Tmsize) * link->delayn; /* * drop packets */ if(link->droprate && nrand(link->droprate) == 0) link->drops++; else{ ptime(bp->rp, tout + link->delay0ns); if(link->tq == nil) link->tq = bp; else link->tqtail->next = bp; link->tqtail = bp; } } /* * record the next time a packet can be sent, * but don't schedule an interrupt if none is waiting */ link->tout = tout; if(!qcanread(link->oq)) tout = 0; /* * put more blocks into the receive queue */ tin = 0; while(bp = link->tq){ tin = gtime(bp->rp); if(tin > now) break; bp->rp += Tmsize; link->tq = bp->next; bp->next = nil; if(!link->indrop) qpassnolim(link->iq, bp); else if(qpass(link->iq, bp) < 0) link->soverflows++; tin = 0; } if(bp == nil && qisclosed(link->oq) && !qcanread(link->oq) && !qisclosed(link->iq)) qhangup(link->iq, nil); link->tin = tin; if(!tin || tin > tout && tout) tin = tout; link->ci.ns = tin - now; if(tin){ if(tin < now) panic("loopback unfinished business"); timeradd(&link->ci); } iunlock(link); }
inline ptime time_now() { timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return ptime(boost::int64_t(ts.tv_sec) * 1000000 + ts.tv_nsec / 1000); }
inline bool message_queue::try_send (const void *buffer, std::size_t buffer_size, unsigned int priority) { return this->do_send(non_blocking, buffer, buffer_size, priority, ptime()); }
inline ptime operator-(ptime lhs, time_duration rhs) { return ptime(lhs.time - rhs.diff); }
/* * Get the mime header (soap) container */ MIME *ebxml_getsoap (XML *xml, QUEUEROW *r) { XML *soap; MIME *msg; char *ch, *pid, *partyid, *cpa, *organization, path[MAX_PATH], buf[MAX_PATH]; int route; debug ("getting soap container...\n"); organization = cfg_org (xml); pid = queue_field_get (r, "MESSAGEID"); if (pid != NULL) pid = strchr (pid, '-'); if (pid++ == NULL) { error ("Can't get PID from MESSAGEID\n"); return (NULL); } if ((route = cfg_route_index (xml, queue_field_get (r, "ROUTEINFO"))) < 0) return (NULL); debug ("getting soap template for pid=%s org=%s...\n", pid, organization); if ((soap = ebxml_template (xml, XSOAP)) == NULL) { error ("Can't get SOAP template\n"); return (NULL); } xml_set_text (soap, SOAPFROMPARTY, cfg_party (xml)); partyid = "Someone_else"; xml_set_text (soap, SOAPTOPARTY, partyid); cpa = cfg_route (xml, route, "Cpa"); xml_set_text (soap, SOAPCPAID, cpa); xml_set_text (soap, SOAPCONVERSEID, pid); xml_set_text (soap, SOAPSERVICE, queue_field_get (r, "SERVICE")); xml_set_text (soap, SOAPACTION, queue_field_get (r, "ACTION")); sprintf (buf, "%ld@%s", pid, organization); xml_set_text (soap, SOAPMESSAGEID, buf); queue_field_set (r, "MESSAGECREATIONTIME", ptime (NULL, buf)); xml_set_text (soap, SOAPDATATIME, buf); if (!strcmp (queue_field_get (r, "ACTION"), "Ping")) { xml_delete (soap, SOAPBODY); } else { sprintf (buf, "cid:%s@%s", queue_field_get (r, "PAYLOADFILE"), organization); debug ("set %s xlink:href=\"%s\"\n", SOAPMREF, buf); xml_set_attribute (soap, SOAPMREF, "xlink:href", buf); sprintf (buf, "%s.%s", r->queue->name, queue_field_get (r, "RECORDID")); xml_set_text (soap, SOAPDBRECID, buf); xml_set_text (soap, SOAPDBMESSID, queue_field_get (r, "MESSAGEID")); xml_set_text (soap, SOAPDBARGS, queue_field_get (r, "ARGUMENTS")); xml_set_text (soap, SOAPDBRECP, queue_field_get (r, "MESSAGERECIPIENT")); } debug ("building soap mime container...\n"); msg = mime_alloc (); mime_setHeader (msg, MIME_CONTENT, MIME_XML, 99); sprintf (buf, "<%s%s>", "ebxml-envelope@", organization); mime_setHeader (msg, MIME_CONTENTID, buf, 0); debug ("formatting soap xml...\n"); ch = xml_format (soap); debug ("soap envelope:\n%s\n", ch); xml_free (soap); mime_setBody (msg, ch, strlen (ch)); free (ch); debug ("returning soap message...\n"); return (msg); }