try to use clock_gettime to make sure we don't care if the system time changes

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7165 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-01-11 00:43:49 +00:00
parent 886f99735a
commit 143bed09a3
38 changed files with 174 additions and 104 deletions
@@ -600,11 +600,16 @@ SWITCH_STANDARD_API(ctl_function)
}
switch_core_session_ctl(SCSC_SPS, &arg);
stream->write_function(stream, "+OK sessions per second: %d\n", arg);
} else if (!strcasecmp(argv[0], "sync_clock")) {
arg = 0;
switch_core_session_ctl(SCSC_SYNC_CLOCK, &arg);
stream->write_function(stream, "+OK clock syncronized\n");
} else {
stream->write_function(stream, "-ERR INVALID COMMAND\nUSAGE: fsctl %s", CTL_SYNTAX);
goto end;
}
}
stream->write_function(stream, "+OK\n");
end:
free(mydata);
@@ -830,13 +835,13 @@ SWITCH_STANDARD_API(tone_detect_session_function)
uint32_t mto;
if (*argv[4] == '+') {
if ((mto = atoi(argv[4]+1)) > 0) {
to = time(NULL) + mto;
to = switch_timestamp(NULL) + mto;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
goto done;
}
} else {
if ((to = atoi(argv[4])) < time(NULL)) {
if ((to = atoi(argv[4])) < switch_timestamp(NULL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
to = 0;
goto done;
@@ -930,7 +935,7 @@ SWITCH_STANDARD_API(sched_transfer_function)
time_t when;
if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1);
when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -972,7 +977,7 @@ SWITCH_STANDARD_API(sched_hangup_function)
switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT;
if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1);
when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -1091,7 +1096,7 @@ SWITCH_STANDARD_API(sched_broadcast_function)
time_t when;
if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1);
when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -1603,7 +1608,7 @@ SWITCH_STANDARD_API(sched_api_function)
*dcmd++ = '\0';
if (*tm == '+') {
when = time(NULL) + atol(tm + 1);
when = switch_timestamp(NULL) + atol(tm + 1);
} else {
when = atol(tm);
}
@@ -220,7 +220,7 @@ SWITCH_STANDARD_APP(sched_transfer_function)
time_t when;
if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1);
when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -245,7 +245,7 @@ SWITCH_STANDARD_APP(sched_hangup_function)
switch_bool_t bleg = SWITCH_FALSE;
if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1);
when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -277,7 +277,7 @@ SWITCH_STANDARD_APP(sched_broadcast_function)
switch_media_flag_t flags = SMF_NONE;
if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1);
when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -749,7 +749,7 @@ SWITCH_STANDARD_APP(strftime_function)
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_time_exp_lt(&tm, switch_time_now());
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), argv[1], &tm);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", argv[0], date);
switch_channel_set_variable(channel, argv[0], date);
@@ -761,7 +761,7 @@ SWITCH_STANDARD_API(strepoch_api_function)
switch_time_t out;
if (switch_strlen_zero(cmd)) {
out = switch_time_now();
out = switch_timestamp_now();
} else {
out = switch_str_time(cmd);
}
@@ -782,7 +782,7 @@ SWITCH_STANDARD_API(strftime_api_function)
thetime = switch_time_make(atoi(cmd),0);
cmd = p+1;
} else {
thetime = switch_time_now();
thetime = switch_timestamp_now();
}
switch_time_exp_lt(&tm, thetime);
switch_strftime(date, &retsize, sizeof(date), switch_strlen_zero(cmd) ? "%Y-%m-%d %T" : cmd, &tm);
@@ -969,12 +969,12 @@ SWITCH_STANDARD_APP(tone_detect_session_function)
uint32_t mto;
if (*argv[3] == '+') {
if ((mto = atol(argv[3]+1)) > 0) {
to = time(NULL) + mto;
to = switch_timestamp(NULL) + mto;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
}
} else {
if ((to = atol(argv[3])) < time(NULL)) {
if ((to = atol(argv[3])) < switch_timestamp(NULL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
to = 0;
}
+1 -1
View File
@@ -510,7 +510,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** result
tv.tv_sec = i;
tv.tv_usec = 0;
i = select((int) (fd + 1), &fds, 0, 0, &tv);
now = time(NULL);
now = switch_timestamp(NULL);
if (i > 0) {
dns_ioevent(nctx, now);
}
+2 -2
View File
@@ -182,7 +182,7 @@ SWITCH_STANDARD_APP(bcast_function)
}
}
control_packet.unique_id = htonl((u_long)time(NULL));
control_packet.unique_id = htonl((u_long)switch_timestamp(NULL));
control_packet.command = htonl(LS_START_BCAST);
control_packet.ip = inet_addr(mcast_ip);
control_packet.port = htonl(mcast_port);
@@ -211,7 +211,7 @@ SWITCH_STANDARD_APP(bcast_function)
control_packet.unique_id = htonl((u_long)time(NULL));
control_packet.unique_id = htonl((u_long)switch_timestamp(NULL));
control_packet.command = htonl(LS_STOP_BCAST);
bytes = 8;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
+1 -1
View File
@@ -484,7 +484,7 @@ SWITCH_STANDARD_APP(rss_function)
switch_size_t retsize;
char dtmf[5] = "";
switch_time_exp_lt(&tm, switch_time_now());
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);
@@ -1380,7 +1380,7 @@ default:
}
}
switch_snprintf(sql, sizeof(sql), "update voicemail_data set read_epoch=%ld where user='%s' and domain='%s' and flags='save'",
(long)time(NULL), myid, domain_name);
(long)switch_timestamp(NULL), myid, domain_name);
vm_execute_sql(profile, sql, profile->mutex);
switch_snprintf(sql, sizeof(sql), "select file_path from voicemail_data where user='%s' and domain='%s' and flags='delete'", myid, domain_name);
vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL);
@@ -1891,7 +1891,7 @@ greet:
int total_new_urgent_messages = 0;
int total_saved_urgent_messages = 0;
usql = switch_mprintf("insert into voicemail_data values(%ld,0,'%q','%q','%q','%q','%q','%q','%q','%u','','%q')", (long)time(NULL),
usql = switch_mprintf("insert into voicemail_data values(%ld,0,'%q','%q','%q','%q','%q','%q','%q','%u','','%q')", (long)switch_timestamp(NULL),
id, domain_name, uuid, caller_profile->caller_id_name, caller_profile->caller_id_number,
myfolder, file_path, message_len, read_flags);
vm_execute_sql(profile, usql, profile->mutex);
@@ -1936,7 +1936,7 @@ end:
message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
&total_new_urgent_messages, &total_saved_urgent_messages);
switch_time_exp_lt(&tm, switch_time_now());
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
switch_channel_set_variable(channel, "voicemail_current_folder", myfolder);
@@ -2255,7 +2255,7 @@ static void do_play(vm_profile_t *profile, char *user, char *domain, char *file,
struct holder holder;
sql = switch_mprintf("update voicemail_data set read_epoch=%ld where user='%s' and domain='%s' and file_path like '%%%s'",
(long)time(NULL), user, domain, file);
(long)switch_timestamp(NULL), user, domain, file);
vm_execute_sql(profile, sql, profile->mutex);
free(sql);
+2 -3
View File
@@ -637,7 +637,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
{
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
switch_time_t started = switch_time_now();
switch_time_t started = switch_timestamp_now();
unsigned int elapsed;
switch_byte_t *data;
@@ -680,7 +680,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
}
if (timeout > -1) {
elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
elapsed = (unsigned int) ((switch_timestamp_now() - started) / 1000);
if (elapsed >= (unsigned int) timeout) {
return SWITCH_STATUS_SUCCESS;
}
@@ -724,7 +724,6 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
switch_swap_linear(frame->data, (int) frame->datalen / 2);
}
#endif
//printf("Send %ld %d\n", time(NULL), (int) frame->datalen);
iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int) frame->datalen, tech_pvt->write_codec.implementation->samples_per_frame);
return SWITCH_STATUS_SUCCESS;
+2 -2
View File
@@ -1242,7 +1242,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
switch_assert(gp->state < REG_STATE_LAST);
stream->write_function(stream, "%25s\t%s\t %32s\t%s", gp->name, "gateway", gp->register_to, sofia_state_names[gp->state]);
if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
stream->write_function(stream, " (retry: %ds)", gp->retry - time(NULL));
stream->write_function(stream, " (retry: %ds)", gp->retry - switch_timestamp(NULL));
}
stream->write_function(stream, "\n");
}
@@ -1348,7 +1348,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
if (!strcasecmp(argv[1], "stop") || !strcasecmp(argv[1], "restart")) {
int rsec = 3;
int diff = (int) (time(NULL) - profile->started);
int diff = (int) (switch_timestamp(NULL) - profile->started);
int remain = rsec - diff;
if (diff < rsec) {
stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
+4 -4
View File
@@ -345,7 +345,7 @@ void event_handler(switch_event_t *event)
char *rpid = switch_event_get_header(event, "orig-rpid");
char *call_id = switch_event_get_header(event, "orig-call-id");
char *user_agent = switch_event_get_header(event, "user-agent");
long expires = (long) time(NULL) + atol(exp_str);
long expires = (long) switch_timestamp(NULL) + atol(exp_str);
char *profile_name = switch_event_get_header(event, "orig-profile-name");
sofia_profile_t *profile = NULL;
@@ -512,19 +512,19 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting thread for %s\n", profile->name);
profile->started = time(NULL);
profile->started = switch_timestamp(NULL);
switch_yield(1000000);
sofia_set_pflag_locked(profile, PFLAG_RUNNING);
while (mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) {
if (++ireg_loops >= IREG_SECONDS) {
sofia_reg_check_expire(profile, time(NULL));
sofia_reg_check_expire(profile, switch_timestamp(NULL));
ireg_loops = 0;
}
if (++gateway_loops >= GATEWAY_SECONDS) {
sofia_reg_check_gateway(profile, time(NULL));
sofia_reg_check_gateway(profile, switch_timestamp(NULL));
gateway_loops = 0;
}
+3 -2
View File
@@ -72,7 +72,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32
}
if (!tech_pvt->owner_id) {
tech_pvt->owner_id = (uint32_t) time(NULL) - port;
tech_pvt->owner_id = (uint32_t) switch_timestamp(NULL) - port;
}
if (!tech_pvt->session_id) {
@@ -1468,7 +1468,8 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
}
if (match) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec is still good, let's keep it\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec [%s] is still good, let's keep it\n",
tech_pvt->rm_encoding);
goto end;
}
}
+4 -4
View File
@@ -608,13 +608,13 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
char *prpid;
int done = 0;
const char *ct;
time_t exptime = time(NULL) + 3600;
time_t exptime = switch_timestamp(NULL) + 3600;
char exp[80] = "";
if (expires) {
long tmp = atol(expires);
if (tmp > 0) {
exptime = tmp - time(NULL);
exptime = tmp - switch_timestamp(NULL);
}
}
@@ -855,7 +855,7 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
}
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
expire_sec = (int)(expire_sec - time(NULL));
expire_sec = (int)(expire_sec - switch_timestamp(NULL));
if (expire_sec < 0) {
expire_sec = 3600;
}
@@ -1047,7 +1047,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
full_via = sip_header_as_string(profile->home, (void *) sip->sip_via);
exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
exp = (long) time(NULL) + exp_raw;
exp = (long) switch_timestamp(NULL) + exp_raw;
switch_mutex_lock(profile->ireg_mutex);
+2 -2
View File
@@ -302,7 +302,7 @@ void sofia_reg_auth_challange(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_mutex_lock(profile->ireg_mutex);
sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)",
uuid_str, time(NULL) + profile->nonce_ttl);
uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
switch_assert(sql != NULL);
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
switch_safe_free(sql);
@@ -495,7 +495,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld, '%q')", call_id,
to_user, to_host, contact_str, cd ? "Registered(NATHACK)" : "Registered",
rpid, (long) time(NULL) + (long) exptime * 2, agent);
rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
if (sql) {
@@ -87,7 +87,7 @@ static void do_rotate(cdr_fd_t *fd)
close(fd->fd);
if (globals.rotate) {
switch_time_exp_lt(&tm, switch_time_now());
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
len = strlen(fd->path) + strlen(date) + 2;
@@ -354,7 +354,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
uint32_t max_len = sizeof(mbuf);
switch_channel_t *channel = NULL;
*event = NULL;
start = time(NULL);
start = switch_timestamp(NULL);
ptr = mbuf;
@@ -436,7 +436,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
}
if (timeout) {
elapsed = (uint32_t) (time(NULL) - start);
elapsed = (uint32_t) (switch_timestamp(NULL) - start);
if (elapsed >= timeout) {
switch_clear_flag_locked(listener, LFLAG_RUNNING);
return SWITCH_STATUS_FALSE;
@@ -2077,14 +2077,14 @@ static JSBool session_wait_for_media(JSContext * cx, JSObject * obj, uintN argc,
channel = switch_core_session_get_channel(jss->session);
switch_assert(channel != NULL);
started = switch_time_now();
started = switch_timestamp_now();
if (argc > 0) {
JS_ValueToInt32(cx, argv[0], &timeout);
}
for (;;) {
if (((elapsed = (unsigned int) ((switch_time_now() - started) / 1000)) > (switch_time_t) timeout)
if (((elapsed = (unsigned int) ((switch_timestamp_now() - started) / 1000)) > (switch_time_t) timeout)
|| switch_channel_get_state(channel) >= CS_HANGUP) {
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
break;
@@ -2116,14 +2116,14 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc
channel = switch_core_session_get_channel(jss->session);
switch_assert(channel != NULL);
started = switch_time_now();
started = switch_timestamp_now();
if (argc > 0) {
JS_ValueToInt32(cx, argv[0], &timeout);
}
for (;;) {
if (((elapsed = (unsigned int) ((switch_time_now() - started) / 1000)) > (switch_time_t) timeout)
if (((elapsed = (unsigned int) ((switch_timestamp_now() - started) / 1000)) > (switch_time_t) timeout)
|| switch_channel_get_state(channel) >= CS_HANGUP) {
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
break;
+1 -1
View File
@@ -123,7 +123,7 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
switch_mutex_lock(globals.mutex);
switch_time_exp_lt(&tm, switch_time_now());
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
profile->log_size = 0;
+1 -1
View File
@@ -303,7 +303,7 @@ static switch_status_t de_say_time(switch_core_session_t *session, char *tosay,
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL);
seconds = (int64_t) switch_timestamp(NULL);
}
if (seconds >= 60) {
+1 -1
View File
@@ -303,7 +303,7 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay,
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL);
seconds = (int64_t) switch_timestamp(NULL);
}
if (seconds >= 60) {
+1 -1
View File
@@ -303,7 +303,7 @@ static switch_status_t es_say_time(switch_core_session_t *session, char *tosay,
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL);
seconds = (int64_t) switch_timestamp(NULL);
}
if (seconds >= 60) {
+1 -1
View File
@@ -303,7 +303,7 @@ static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay,
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL);
seconds = (int64_t) switch_timestamp(NULL);
}
if (seconds >= 60) {
+1 -1
View File
@@ -303,7 +303,7 @@ static switch_status_t it_say_time(switch_core_session_t *session, char *tosay,
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL);
seconds = (int64_t) switch_timestamp(NULL);
}
if (seconds >= 60) {
+1 -1
View File
@@ -303,7 +303,7 @@ static switch_status_t nl_say_time(switch_core_session_t *session, char *tosay,
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL);
seconds = (int64_t) switch_timestamp(NULL);
}
if (seconds >= 60) {