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

View File

@ -158,6 +158,8 @@ struct switch_media_bug {
struct switch_runtime { struct switch_runtime {
switch_time_t initiated; switch_time_t initiated;
switch_time_t reference;
int64_t offset;
switch_hash_t *global_vars; switch_hash_t *global_vars;
switch_hash_t *mime_types; switch_hash_t *mime_types;
switch_memory_pool_t *memory_pool; switch_memory_pool_t *memory_pool;

View File

@ -1536,6 +1536,8 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void);
SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void);
SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void);
SWITCH_DECLARE(void) switch_core_setrlimits(void); SWITCH_DECLARE(void) switch_core_setrlimits(void);
SWITCH_DECLARE(void) switch_time_sync(void);
SWITCH_DECLARE(time_t) switch_timestamp(time_t *t);
///\} ///\}

View File

@ -1065,7 +1065,8 @@ typedef enum {
SCSC_SPS, SCSC_SPS,
SCSC_LAST_SPS, SCSC_LAST_SPS,
SCSC_RECLAIM, SCSC_RECLAIM,
SCSC_MAX_SESSIONS SCSC_MAX_SESSIONS,
SCSC_SYNC_CLOCK
} switch_session_ctl_t; } switch_session_ctl_t;
typedef struct apr_pool_t switch_memory_pool_t; typedef struct apr_pool_t switch_memory_pool_t;

View File

@ -600,11 +600,16 @@ SWITCH_STANDARD_API(ctl_function)
} }
switch_core_session_ctl(SCSC_SPS, &arg); switch_core_session_ctl(SCSC_SPS, &arg);
stream->write_function(stream, "+OK sessions per second: %d\n", 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 { } else {
stream->write_function(stream, "-ERR INVALID COMMAND\nUSAGE: fsctl %s", CTL_SYNTAX); stream->write_function(stream, "-ERR INVALID COMMAND\nUSAGE: fsctl %s", CTL_SYNTAX);
goto end; goto end;
} }
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
end: end:
free(mydata); free(mydata);
@ -830,13 +835,13 @@ SWITCH_STANDARD_API(tone_detect_session_function)
uint32_t mto; uint32_t mto;
if (*argv[4] == '+') { if (*argv[4] == '+') {
if ((mto = atoi(argv[4]+1)) > 0) { if ((mto = atoi(argv[4]+1)) > 0) {
to = time(NULL) + mto; to = switch_timestamp(NULL) + mto;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
goto done; goto done;
} }
} else { } 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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
to = 0; to = 0;
goto done; goto done;
@ -930,7 +935,7 @@ SWITCH_STANDARD_API(sched_transfer_function)
time_t when; time_t when;
if (*argv[0] == '+') { if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1); when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else { } else {
when = atol(argv[0]); when = atol(argv[0]);
} }
@ -972,7 +977,7 @@ SWITCH_STANDARD_API(sched_hangup_function)
switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT; switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT;
if (*argv[0] == '+') { if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1); when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else { } else {
when = atol(argv[0]); when = atol(argv[0]);
} }
@ -1091,7 +1096,7 @@ SWITCH_STANDARD_API(sched_broadcast_function)
time_t when; time_t when;
if (*argv[0] == '+') { if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1); when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else { } else {
when = atol(argv[0]); when = atol(argv[0]);
} }
@ -1603,7 +1608,7 @@ SWITCH_STANDARD_API(sched_api_function)
*dcmd++ = '\0'; *dcmd++ = '\0';
if (*tm == '+') { if (*tm == '+') {
when = time(NULL) + atol(tm + 1); when = switch_timestamp(NULL) + atol(tm + 1);
} else { } else {
when = atol(tm); when = atol(tm);
} }

View File

@ -220,7 +220,7 @@ SWITCH_STANDARD_APP(sched_transfer_function)
time_t when; time_t when;
if (*argv[0] == '+') { if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1); when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else { } else {
when = atol(argv[0]); when = atol(argv[0]);
} }
@ -245,7 +245,7 @@ SWITCH_STANDARD_APP(sched_hangup_function)
switch_bool_t bleg = SWITCH_FALSE; switch_bool_t bleg = SWITCH_FALSE;
if (*argv[0] == '+') { if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1); when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else { } else {
when = atol(argv[0]); when = atol(argv[0]);
} }
@ -277,7 +277,7 @@ SWITCH_STANDARD_APP(sched_broadcast_function)
switch_media_flag_t flags = SMF_NONE; switch_media_flag_t flags = SMF_NONE;
if (*argv[0] == '+') { if (*argv[0] == '+') {
when = time(NULL) + atol(argv[0] + 1); when = switch_timestamp(NULL) + atol(argv[0] + 1);
} else { } else {
when = atol(argv[0]); when = atol(argv[0]);
} }
@ -749,7 +749,7 @@ SWITCH_STANDARD_APP(strftime_function)
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
assert(channel != NULL); 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_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_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", argv[0], date);
switch_channel_set_variable(channel, 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; switch_time_t out;
if (switch_strlen_zero(cmd)) { if (switch_strlen_zero(cmd)) {
out = switch_time_now(); out = switch_timestamp_now();
} else { } else {
out = switch_str_time(cmd); out = switch_str_time(cmd);
} }
@ -782,7 +782,7 @@ SWITCH_STANDARD_API(strftime_api_function)
thetime = switch_time_make(atoi(cmd),0); thetime = switch_time_make(atoi(cmd),0);
cmd = p+1; cmd = p+1;
} else { } else {
thetime = switch_time_now(); thetime = switch_timestamp_now();
} }
switch_time_exp_lt(&tm, thetime); switch_time_exp_lt(&tm, thetime);
switch_strftime(date, &retsize, sizeof(date), switch_strlen_zero(cmd) ? "%Y-%m-%d %T" : cmd, &tm); 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; uint32_t mto;
if (*argv[3] == '+') { if (*argv[3] == '+') {
if ((mto = atol(argv[3]+1)) > 0) { if ((mto = atol(argv[3]+1)) > 0) {
to = time(NULL) + mto; to = switch_timestamp(NULL) + mto;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
} }
} else { } 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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
to = 0; to = 0;
} }

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_sec = i;
tv.tv_usec = 0; tv.tv_usec = 0;
i = select((int) (fd + 1), &fds, 0, 0, &tv); i = select((int) (fd + 1), &fds, 0, 0, &tv);
now = time(NULL); now = switch_timestamp(NULL);
if (i > 0) { if (i > 0) {
dns_ioevent(nctx, now); dns_ioevent(nctx, now);
} }

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.command = htonl(LS_START_BCAST);
control_packet.ip = inet_addr(mcast_ip); control_packet.ip = inet_addr(mcast_ip);
control_packet.port = htonl(mcast_port); 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); control_packet.command = htonl(LS_STOP_BCAST);
bytes = 8; bytes = 8;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes); switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);

View File

@ -484,7 +484,7 @@ SWITCH_STANDARD_APP(rss_function)
switch_size_t retsize; switch_size_t retsize;
char dtmf[5] = ""; 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); switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);

View File

@ -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'", 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); 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); 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); vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL);
@ -1891,7 +1891,7 @@ greet:
int total_new_urgent_messages = 0; int total_new_urgent_messages = 0;
int total_saved_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, id, domain_name, uuid, caller_profile->caller_id_name, caller_profile->caller_id_number,
myfolder, file_path, message_len, read_flags); myfolder, file_path, message_len, read_flags);
vm_execute_sql(profile, usql, profile->mutex); 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, message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
&total_new_urgent_messages, &total_saved_urgent_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_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
switch_channel_set_variable(channel, "voicemail_current_folder", myfolder); 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; struct holder holder;
sql = switch_mprintf("update voicemail_data set read_epoch=%ld where user='%s' and domain='%s' and file_path like '%%%s'", 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); vm_execute_sql(profile, sql, profile->mutex);
free(sql); free(sql);

View File

@ -637,7 +637,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
{ {
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL; private_t *tech_pvt = NULL;
switch_time_t started = switch_time_now(); switch_time_t started = switch_timestamp_now();
unsigned int elapsed; unsigned int elapsed;
switch_byte_t *data; switch_byte_t *data;
@ -680,7 +680,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
} }
if (timeout > -1) { if (timeout > -1) {
elapsed = (unsigned int) ((switch_time_now() - started) / 1000); elapsed = (unsigned int) ((switch_timestamp_now() - started) / 1000);
if (elapsed >= (unsigned int) timeout) { if (elapsed >= (unsigned int) timeout) {
return SWITCH_STATUS_SUCCESS; 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); switch_swap_linear(frame->data, (int) frame->datalen / 2);
} }
#endif #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); 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; return SWITCH_STATUS_SUCCESS;

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); 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]); 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) { 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"); 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")) { if (!strcasecmp(argv[1], "stop") || !strcasecmp(argv[1], "restart")) {
int rsec = 3; int rsec = 3;
int diff = (int) (time(NULL) - profile->started); int diff = (int) (switch_timestamp(NULL) - profile->started);
int remain = rsec - diff; int remain = rsec - diff;
if (diff < rsec) { 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", stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",

View File

@ -345,7 +345,7 @@ void event_handler(switch_event_t *event)
char *rpid = switch_event_get_header(event, "orig-rpid"); char *rpid = switch_event_get_header(event, "orig-rpid");
char *call_id = switch_event_get_header(event, "orig-call-id"); char *call_id = switch_event_get_header(event, "orig-call-id");
char *user_agent = switch_event_get_header(event, "user-agent"); 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"); char *profile_name = switch_event_get_header(event, "orig-profile-name");
sofia_profile_t *profile = NULL; 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); 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); switch_yield(1000000);
sofia_set_pflag_locked(profile, PFLAG_RUNNING); sofia_set_pflag_locked(profile, PFLAG_RUNNING);
while (mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) { while (mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) {
if (++ireg_loops >= IREG_SECONDS) { if (++ireg_loops >= IREG_SECONDS) {
sofia_reg_check_expire(profile, time(NULL)); sofia_reg_check_expire(profile, switch_timestamp(NULL));
ireg_loops = 0; ireg_loops = 0;
} }
if (++gateway_loops >= GATEWAY_SECONDS) { if (++gateway_loops >= GATEWAY_SECONDS) {
sofia_reg_check_gateway(profile, time(NULL)); sofia_reg_check_gateway(profile, switch_timestamp(NULL));
gateway_loops = 0; gateway_loops = 0;
} }

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) { 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) { 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) { 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; goto end;
} }
} }

View File

@ -608,13 +608,13 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
char *prpid; char *prpid;
int done = 0; int done = 0;
const char *ct; const char *ct;
time_t exptime = time(NULL) + 3600; time_t exptime = switch_timestamp(NULL) + 3600;
char exp[80] = ""; char exp[80] = "";
if (expires) { if (expires) {
long tmp = atol(expires); long tmp = atol(expires);
if (tmp > 0) { 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); 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) { if (expire_sec < 0) {
expire_sec = 3600; 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); full_via = sip_header_as_string(profile->home, (void *) sip->sip_via);
exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600); 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); switch_mutex_lock(profile->ireg_mutex);

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); switch_mutex_lock(profile->ireg_mutex);
sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)", 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); switch_assert(sql != NULL);
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL); sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
switch_safe_free(sql); 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, 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", 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) { if (sql) {

View File

@ -87,7 +87,7 @@ static void do_rotate(cdr_fd_t *fd)
close(fd->fd); close(fd->fd);
if (globals.rotate) { 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); switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
len = strlen(fd->path) + strlen(date) + 2; len = strlen(fd->path) + strlen(date) + 2;

View File

@ -354,7 +354,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
uint32_t max_len = sizeof(mbuf); uint32_t max_len = sizeof(mbuf);
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
*event = NULL; *event = NULL;
start = time(NULL); start = switch_timestamp(NULL);
ptr = mbuf; ptr = mbuf;
@ -436,7 +436,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
} }
if (timeout) { if (timeout) {
elapsed = (uint32_t) (time(NULL) - start); elapsed = (uint32_t) (switch_timestamp(NULL) - start);
if (elapsed >= timeout) { if (elapsed >= timeout) {
switch_clear_flag_locked(listener, LFLAG_RUNNING); switch_clear_flag_locked(listener, LFLAG_RUNNING);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;

View File

@ -2077,14 +2077,14 @@ static JSBool session_wait_for_media(JSContext * cx, JSObject * obj, uintN argc,
channel = switch_core_session_get_channel(jss->session); channel = switch_core_session_get_channel(jss->session);
switch_assert(channel != NULL); switch_assert(channel != NULL);
started = switch_time_now(); started = switch_timestamp_now();
if (argc > 0) { if (argc > 0) {
JS_ValueToInt32(cx, argv[0], &timeout); JS_ValueToInt32(cx, argv[0], &timeout);
} }
for (;;) { 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) { || switch_channel_get_state(channel) >= CS_HANGUP) {
*rval = BOOLEAN_TO_JSVAL(JS_FALSE); *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
break; 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); channel = switch_core_session_get_channel(jss->session);
switch_assert(channel != NULL); switch_assert(channel != NULL);
started = switch_time_now(); started = switch_timestamp_now();
if (argc > 0) { if (argc > 0) {
JS_ValueToInt32(cx, argv[0], &timeout); JS_ValueToInt32(cx, argv[0], &timeout);
} }
for (;;) { 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) { || switch_channel_get_state(channel) >= CS_HANGUP) {
*rval = BOOLEAN_TO_JSVAL(JS_FALSE); *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
break; break;

View File

@ -123,7 +123,7 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
switch_mutex_lock(globals.mutex); 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); switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
profile->log_size = 0; profile->log_size = 0;

View File

@ -303,7 +303,7 @@ static switch_status_t de_say_time(switch_core_session_t *session, char *tosay,
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL); seconds = (int64_t) switch_timestamp(NULL);
} }
if (seconds >= 60) { if (seconds >= 60) {

View File

@ -303,7 +303,7 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay,
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL); seconds = (int64_t) switch_timestamp(NULL);
} }
if (seconds >= 60) { if (seconds >= 60) {

View File

@ -303,7 +303,7 @@ static switch_status_t es_say_time(switch_core_session_t *session, char *tosay,
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL); seconds = (int64_t) switch_timestamp(NULL);
} }
if (seconds >= 60) { if (seconds >= 60) {

View File

@ -303,7 +303,7 @@ static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay,
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL); seconds = (int64_t) switch_timestamp(NULL);
} }
if (seconds >= 60) { if (seconds >= 60) {

View File

@ -303,7 +303,7 @@ static switch_status_t it_say_time(switch_core_session_t *session, char *tosay,
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL); seconds = (int64_t) switch_timestamp(NULL);
} }
if (seconds >= 60) { if (seconds >= 60) {

View File

@ -303,7 +303,7 @@ static switch_status_t nl_say_time(switch_core_session_t *session, char *tosay,
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atoi(tosay)) <= 0) {
seconds = (int64_t) time(NULL); seconds = (int64_t) switch_timestamp(NULL);
} }
if (seconds >= 60) { if (seconds >= 60) {

View File

@ -1048,7 +1048,7 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel
} }
caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times)); caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times));
caller_profile->times->profile_created = switch_time_now(); caller_profile->times->profile_created = switch_timestamp_now();
if (channel->caller_profile && channel->caller_profile->times) { if (channel->caller_profile && channel->caller_profile->times) {
channel->caller_profile->times->transferred = caller_profile->times->profile_created; channel->caller_profile->times->transferred = caller_profile->times->profile_created;
@ -1056,7 +1056,7 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel
caller_profile->times->created = channel->caller_profile->times->created; caller_profile->times->created = channel->caller_profile->times->created;
caller_profile->times->hungup = channel->caller_profile->times->hungup; caller_profile->times->hungup = channel->caller_profile->times->hungup;
} else { } else {
caller_profile->times->created = switch_time_now(); caller_profile->times->created = switch_timestamp_now();
} }
caller_profile->next = channel->caller_profile; caller_profile->next = channel->caller_profile;
@ -1246,7 +1246,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) { if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) {
switch_mutex_lock(channel->profile_mutex); switch_mutex_lock(channel->profile_mutex);
channel->caller_profile->times->hungup = switch_time_now(); channel->caller_profile->times->hungup = switch_timestamp_now();
switch_mutex_unlock(channel->profile_mutex); switch_mutex_unlock(channel->profile_mutex);
} }
@ -1403,7 +1403,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
if (channel->caller_profile && channel->caller_profile->times) { if (channel->caller_profile && channel->caller_profile->times) {
switch_mutex_lock(channel->profile_mutex); switch_mutex_lock(channel->profile_mutex);
channel->caller_profile->times->answered = switch_time_now(); channel->caller_profile->times->answered = switch_timestamp_now();
switch_mutex_unlock(channel->profile_mutex); switch_mutex_unlock(channel->profile_mutex);
} }

View File

@ -80,13 +80,9 @@ SWITCH_STANDARD_SCHED_FUNC(heartbeat_callback)
send_heartbeat(); send_heartbeat();
/* reschedule this task */ /* reschedule this task */
task->runtime = time(NULL) + 20; task->runtime = switch_timestamp(NULL) + 20;
} }
SWITCH_DECLARE(switch_time_t) switch_timestamp_now(void)
{
return runtime.timestamp ? runtime.timestamp : switch_time_now();
}
SWITCH_DECLARE(switch_status_t) switch_core_set_console(const char *console) SWITCH_DECLARE(switch_status_t) switch_core_set_console(const char *console)
{ {
@ -832,7 +828,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
switch_scheduler_task_thread_start(); switch_scheduler_task_thread_start();
runtime.initiated = switch_time_now(); runtime.initiated = switch_time_now();
switch_scheduler_add_task(time(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL); switch_scheduler_add_task(switch_timestamp(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
switch_uuid_get(&uuid); switch_uuid_get(&uuid);
@ -966,7 +962,7 @@ SWITCH_DECLARE(void) switch_core_measure_time(switch_time_t total_ms, switch_cor
SWITCH_DECLARE(switch_time_t) switch_core_uptime(void) SWITCH_DECLARE(switch_time_t) switch_core_uptime(void)
{ {
return switch_time_now() - runtime.initiated; return switch_timestamp_now() - runtime.initiated;
} }
SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t * val) SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t * val)
@ -976,6 +972,10 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_
} }
switch (cmd) { switch (cmd) {
case SCSC_SYNC_CLOCK:
switch_time_sync();
*val = 0;
break;
case SCSC_PAUSE_INBOUND: case SCSC_PAUSE_INBOUND:
if (*val) { if (*val) {
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS); switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);

View File

@ -270,7 +270,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_mutex_lock(bp->read_mutex); switch_mutex_lock(bp->read_mutex);
switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
if (bp->callback) { if (bp->callback) {
if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= time(NULL))) { if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= switch_timestamp(NULL))) {
ok = SWITCH_FALSE; ok = SWITCH_FALSE;
} }
} }
@ -404,7 +404,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) { if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) {
switch_mutex_lock(bp->read_mutex); switch_mutex_lock(bp->read_mutex);
if (bp->callback) { if (bp->callback) {
if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_PING) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= time(NULL))) { if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_PING) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= switch_timestamp(NULL))) {
ok = SWITCH_FALSE; ok = SWITCH_FALSE;
} }
} }
@ -616,7 +616,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
} }
} }
if (bp->stop_time && bp->stop_time <= time(NULL)) { if (bp->stop_time && bp->stop_time <= switch_timestamp(NULL)) {
ok = SWITCH_FALSE; ok = SWITCH_FALSE;
} }

View File

@ -118,7 +118,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_request_port(switch_c
int odd = switch_test_flag(alloc, SPF_ODD); int odd = switch_test_flag(alloc, SPF_ODD);
switch_mutex_lock(alloc->mutex); switch_mutex_lock(alloc->mutex);
srand(getpid() + (unsigned)time(NULL)); srand(getpid() + (unsigned)switch_timestamp(NULL));
while(alloc->track_used < alloc->track_len) { while(alloc->track_used < alloc->track_len) {
double r; double r;

View File

@ -40,17 +40,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
{ {
switch_channel_t *channel; switch_channel_t *channel;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_time_t start, now, done = switch_time_now() + (ms * 1000); switch_time_t start, now, done = switch_timestamp_now() + (ms * 1000);
switch_frame_t *read_frame; switch_frame_t *read_frame;
int32_t left, elapsed; int32_t left, elapsed;
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL); switch_assert(channel != NULL);
start = switch_time_now(); start = switch_timestamp_now();
for (;;) { for (;;) {
now = switch_time_now(); now = switch_timestamp_now();
elapsed = (int32_t) ((now - start) / 1000); elapsed = (int32_t) ((now - start) / 1000);
left = ms - elapsed; left = ms - elapsed;
@ -548,7 +548,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
} }
if (timeout) { if (timeout) {
started = switch_time_now(); started = switch_timestamp_now();
} }
while (switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
@ -557,7 +557,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = {0};
if (timeout) { if (timeout) {
elapsed = (uint32_t) ((switch_time_now() - started) / 1000); elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000);
if (elapsed >= timeout) { if (elapsed >= timeout) {
break; break;
} }
@ -1191,12 +1191,12 @@ SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stre
stream->digits = tmp; stream->digits = tmp;
*(stream->digits + (len++)) = digit; *(stream->digits + (len++)) = digit;
*(stream->digits + len) = '\0'; *(stream->digits + len) = '\0';
stream->last_digit_time = switch_time_now() / 1000; stream->last_digit_time = switch_timestamp_now() / 1000;
} }
} }
} }
// don't allow collected digit string testing if there are varying sized keys until timeout // don't allow collected digit string testing if there are varying sized keys until timeout
if (parser->maxlen - parser->minlen > 0 && (switch_time_now() / 1000) - stream->last_digit_time < parser->digit_timeout_ms) { if (parser->maxlen - parser->minlen > 0 && (switch_timestamp_now() / 1000) - stream->last_digit_time < parser->digit_timeout_ms) {
len = 0; len = 0;
} }
// if we have digits to test // if we have digits to test

View File

@ -307,7 +307,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
if (limit) { if (limit) {
to = time(NULL) + limit; to = switch_timestamp(NULL) + limit;
} }
if (flags && strchr(flags, 'm')) { if (flags && strchr(flags, 'm')) {
@ -763,7 +763,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
} }
if (limit) { if (limit) {
to = time(NULL) + limit; to = switch_timestamp(NULL) + limit;
} }
if ((status = switch_core_media_bug_add(session, record_callback, fh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_media_bug_add(session, record_callback, fh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {

View File

@ -899,7 +899,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
time(&start); switch_timestamp(&start);
for (;;) { for (;;) {
uint32_t valid_channels = 0; uint32_t valid_channels = 0;
@ -922,7 +922,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
goto notready; goto notready;
} }
if ((time(NULL) - start) > (time_t) timelimit_sec) { if ((switch_timestamp(NULL) - start) > (time_t) timelimit_sec) {
to++; to++;
idx = IDX_CANCEL; idx = IDX_CANCEL;
goto notready; goto notready;
@ -1036,7 +1036,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
// When the AND operator is being used, and fail_on_single_reject is set, a hangup indicates that the call should fail. // When the AND operator is being used, and fail_on_single_reject is set, a hangup indicates that the call should fail.
if ((to = (uint8_t) ((time(NULL) - start) >= (time_t) timelimit_sec)) if ((to = (uint8_t) ((switch_timestamp(NULL) - start) >= (time_t) timelimit_sec))
|| (fail_on_single_reject && hups)) { || (fail_on_single_reject && hups)) {
idx = IDX_CANCEL; idx = IDX_CANCEL;
goto notready; goto notready;

View File

@ -434,7 +434,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
} }
if (limit) { if (limit) {
start = time(NULL); start = switch_timestamp(NULL);
} }
if (fh->thresh) { if (fh->thresh) {
@ -464,7 +464,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
switch_ivr_parse_all_events(session); switch_ivr_parse_all_events(session);
} }
if (start && (time(NULL) - start) > limit) { if (start && (switch_timestamp(NULL) - start) > limit) {
break; break;
} }

View File

@ -1063,7 +1063,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
uint16_t in_digit_seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq); uint16_t in_digit_seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
/* SHEESH.... Curse you RFC2833 inventors!!!! */ /* SHEESH.... Curse you RFC2833 inventors!!!! */
if ((time(NULL) - rtp_session->dtmf_data.last_digit_time) > 2) { if ((switch_timestamp(NULL) - rtp_session->dtmf_data.last_digit_time) > 2) {
rtp_session->dtmf_data.last_digit = 0; rtp_session->dtmf_data.last_digit = 0;
rtp_session->dtmf_data.dc = 0; rtp_session->dtmf_data.dc = 0;
rtp_session->dtmf_data.in_digit_seq = 0; rtp_session->dtmf_data.in_digit_seq = 0;
@ -1073,7 +1073,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (duration && end) { if (duration && end) {
if (key != rtp_session->dtmf_data.last_digit) { if (key != rtp_session->dtmf_data.last_digit) {
switch_dtmf_t dtmf = { key, duration }; switch_dtmf_t dtmf = { key, duration };
time(&rtp_session->dtmf_data.last_digit_time); switch_timestamp(&rtp_session->dtmf_data.last_digit_time);
switch_rtp_queue_rfc2833_in(rtp_session, &dtmf); switch_rtp_queue_rfc2833_in(rtp_session, &dtmf);
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
} }
@ -1347,7 +1347,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
uint32_t rate = 0; uint32_t rate = 0;
uint32_t codec_flags = 0; uint32_t codec_flags = 0;
uint32_t len = sizeof(decoded); uint32_t len = sizeof(decoded);
time_t now = time(NULL); time_t now = switch_timestamp(NULL);
send = 0; send = 0;
@ -1523,7 +1523,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session,
rtp_session->vad_data.cng_freq = 50; rtp_session->vad_data.cng_freq = 50;
rtp_session->vad_data.ts = 1; rtp_session->vad_data.ts = 1;
rtp_session->vad_data.start = 0; rtp_session->vad_data.start = 0;
rtp_session->vad_data.next_scan = time(NULL); rtp_session->vad_data.next_scan = switch_timestamp(NULL);
rtp_session->vad_data.scan_freq = 0; rtp_session->vad_data.scan_freq = 0;
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_VAD); switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_VAD);
switch_set_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_CNG); switch_set_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_CNG);

View File

@ -77,7 +77,7 @@ static int task_thread_loop(int done)
if (done) { if (done) {
tp->destroyed = 1; tp->destroyed = 1;
} else { } else {
int64_t now = time(NULL); int64_t now = switch_timestamp(NULL);
if (now >= tp->task.runtime && !tp->in_thread) { if (now >= tp->task.runtime && !tp->in_thread) {
int32_t diff = (int32_t)(now - tp->task.runtime); int32_t diff = (int32_t)(now - tp->task.runtime);
if (diff > 1) { if (diff > 1) {
@ -160,7 +160,7 @@ SWITCH_DECLARE(uint32_t) switch_scheduler_add_task(time_t task_runtime,
switch_zmalloc(container, sizeof(*container)); switch_zmalloc(container, sizeof(*container));
switch_assert(func); switch_assert(func);
container->func = func; container->func = func;
container->task.created = time(NULL); container->task.created = switch_timestamp(NULL);
container->task.runtime = task_runtime; container->task.runtime = task_runtime;
container->task.group = strdup(group ? group : "none"); container->task.group = strdup(group ? group : "none");
container->task.cmd_id = cmd_id; container->task.cmd_id = cmd_id;

View File

@ -314,7 +314,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
switch_stun_packet_attribute_add_username(packet, username, 32); switch_stun_packet_attribute_add_username(packet, username, 32);
bytes = switch_stun_packet_length(packet); bytes = switch_stun_packet_length(packet);
switch_socket_sendto(sock, remote_addr, 0, (void *) packet, &bytes); switch_socket_sendto(sock, remote_addr, 0, (void *) packet, &bytes);
started = switch_time_now(); started = switch_timestamp_now();
*ip = NULL; *ip = NULL;
*port = 0; *port = 0;
@ -326,7 +326,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
break; break;
} }
if ((elapsed = (unsigned int) ((switch_time_now() - started) / 1000)) > 5000) { if ((elapsed = (unsigned int) ((switch_timestamp_now() - started) / 1000)) > 5000) {
*err = "Timeout"; *err = "Timeout";
switch_socket_shutdown(sock, SWITCH_SHUTDOWN_READWRITE); switch_socket_shutdown(sock, SWITCH_SHUTDOWN_READWRITE);
switch_socket_close(sock); switch_socket_close(sock);

View File

@ -59,6 +59,9 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime);
SWITCH_MODULE_DEFINITION(softtimer, softtimer_load, softtimer_shutdown, softtimer_runtime); SWITCH_MODULE_DEFINITION(softtimer, softtimer_load, softtimer_shutdown, softtimer_runtime);
#define MAX_ELEMENTS 1000 #define MAX_ELEMENTS 1000
#define IDLE_SPEED 100
#define STEP_MS 1
#define STEP_MIC 1000
struct timer_private { struct timer_private {
switch_size_t reference; switch_size_t reference;
@ -77,7 +80,45 @@ typedef struct timer_matrix timer_matrix_t;
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS + 1]; static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS + 1];
#define IDLE_SPEED 100
SWITCH_DECLARE(switch_time_t) switch_timestamp_now(void)
{
return runtime.timestamp ? runtime.timestamp : switch_time_now();
}
SWITCH_DECLARE(time_t) switch_timestamp(time_t *t)
{
time_t now = switch_timestamp_now() / APR_USEC_PER_SEC;
if (t) {
*t = now;
}
return now;
}
static switch_time_t time_now(int64_t offset)
{
switch_time_t now;
#if defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset;
#else
now = switch_time_now();
#endif
return now;
}
SWITCH_DECLARE(void) switch_time_sync(void)
{
runtime.reference = switch_time_now();
runtime.offset = runtime.reference - time_now(0);
runtime.reference = time_now(runtime.offset);
}
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t) SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
@ -225,15 +266,14 @@ static switch_status_t timer_destroy(switch_timer_t *timer)
} }
#define STEP_MS 1
#define STEP_MIC 1000
SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime) SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
{ {
switch_time_t reference = switch_time_now(); switch_time_t too_late = STEP_MIC * 128;
uint32_t current_ms = 0; uint32_t current_ms = 0;
uint32_t x, tick = 0; uint32_t x, tick = 0;
switch_time_t ts = 0; switch_time_t ts = 0, last = 0;
switch_time_sync();
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
@ -243,15 +283,35 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
runtime.sps = runtime.sps_total; runtime.sps = runtime.sps_total;
switch_mutex_unlock(runtime.throttle_mutex); switch_mutex_unlock(runtime.throttle_mutex);
while (globals.RUNNING == 1) { while (globals.RUNNING == 1) {
reference += STEP_MIC; runtime.reference += STEP_MIC;
while ((ts = switch_time_now()) < reference) { while ((ts = time_now(runtime.offset)) < runtime.reference) {
if (ts < last) {
int64_t diff = (int64_t)(ts - last);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Reverse Clock Skew Detected!\n");
runtime.reference = switch_time_now();
current_ms = 0;
tick = 0;
runtime.initiated += diff;
}
switch_yield(STEP_MIC); switch_yield(STEP_MIC);
last = ts;
} }
if (ts > (runtime.reference + too_late)) {
switch_time_t diff = ts - runtime.reference - STEP_MIC;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Forward Clock Skew Detected!\n");
runtime.reference = switch_time_now();
current_ms = 0;
tick = 0;
runtime.initiated += diff;
}
runtime.timestamp = ts; runtime.timestamp = ts;
current_ms += STEP_MS; current_ms += STEP_MS;
tick += STEP_MS; tick += STEP_MS;
if (tick >= 1000) { if (tick >= 1000) {
if (runtime.sps <= 0) { if (runtime.sps <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Rate of %d!\n", runtime.sps_total); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Rate of %d!\n", runtime.sps_total);

View File

@ -230,7 +230,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
unsigned char in[B64BUFFLEN]; unsigned char in[B64BUFFLEN];
unsigned char out[B64BUFFLEN + 512]; unsigned char out[B64BUFFLEN + 512];
switch_snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int)time(NULL), rand() & 0xffff); switch_snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int)switch_timestamp(NULL), rand() & 0xffff);
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) { if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
if (file) { if (file) {
@ -691,7 +691,7 @@ SWITCH_DECLARE(switch_time_t) switch_str_time(const char *in)
switch_time_t ret = 0; switch_time_t ret = 0;
char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)"; char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
switch_time_exp_lt(&tm, switch_time_now()); switch_time_exp_lt(&tm, switch_timestamp_now());
tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0; tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
if ((proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { if ((proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {