Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
56b474c3
Commit
56b474c3
authored
Oct 28, 2008
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use timeval instead of the unix-only timespec
parent
bae32229
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
14 deletions
+19
-14
stun/usages/timer.c
stun/usages/timer.c
+14
-13
stun/usages/timer.h
stun/usages/timer.h
+5
-1
No files found.
stun/usages/timer.c
View file @
56b474c3
...
...
@@ -67,29 +67,30 @@
* Clock used throughout the STUN code.
* STUN requires a monotonic 1kHz clock to operate properly.
*/
static
void
stun_gettime
(
struct
time
spec
*
restrict
now
)
static
void
stun_gettime
(
struct
time
val
*
restrict
now
)
{
#if defined (_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK >= 0)
if
(
clock_gettime
(
CLOCK_MONOTONIC
,
now
))
struct
timespec
spec
;
if
(
!
clock_gettime
(
CLOCK_MONOTONIC
,
&
spec
))
{
now
->
tv_sec
=
spec
.
tv_sec
;
now
->
tv_usec
=
spec
.
tv_nsec
/
1000
;
}
else
#endif
{
// fallback to wall clock
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
now
->
tv_sec
=
tv
.
tv_sec
;
now
->
tv_nsec
=
tv
.
tv_usec
*
1000
;
gettimeofday
(
now
,
NULL
);
}
}
static
void
add_delay
(
struct
time
spec
*
ts
,
unsigned
delay
)
static
void
add_delay
(
struct
time
val
*
ts
,
unsigned
delay
)
{
div_t
d
=
div
(
delay
,
1000
);
ts
->
tv_sec
+=
d
.
quot
;
ts
->
tv_
nsec
+=
d
.
rem
*
1000
000
;
ts
->
tv_
usec
+=
d
.
rem
*
1
000
;
while
(
ts
->
tv_
nsec
>
1000
000000
)
while
(
ts
->
tv_
usec
>
1
000000
)
{
ts
->
tv_
nsec
-=
1000
000000
;
ts
->
tv_
usec
-=
1
000000
;
ts
->
tv_sec
++
;
}
}
...
...
@@ -113,18 +114,18 @@ void stun_timer_start_reliable (stun_timer_t *timer)
unsigned
stun_timer_remainder
(
const
stun_timer_t
*
timer
)
{
unsigned
delay
;
struct
time
spec
now
;
struct
time
val
now
;
stun_gettime
(
&
now
);
if
(
now
.
tv_sec
>
timer
->
deadline
.
tv_sec
)
return
0
;
delay
=
timer
->
deadline
.
tv_sec
-
now
.
tv_sec
;
if
((
delay
==
0
)
&&
(
now
.
tv_
nsec
>=
timer
->
deadline
.
tv_n
sec
))
if
((
delay
==
0
)
&&
(
now
.
tv_
usec
>=
timer
->
deadline
.
tv_u
sec
))
return
0
;
delay
*=
1000
;
delay
+=
((
signed
)(
timer
->
deadline
.
tv_
nsec
-
now
.
tv_nsec
))
/
1000
000
;
delay
+=
((
signed
)(
timer
->
deadline
.
tv_
usec
-
now
.
tv_usec
))
/
1
000
;
return
delay
;
}
...
...
stun/usages/timer.h
View file @
56b474c3
...
...
@@ -41,12 +41,16 @@
* @brief STUN retransmission timer
*/
#ifdef _WIN32
#include <winsock2.h>
#else
# include <sys/types.h>
# include <time.h>
#endif
typedef
struct
stun_timer_s
{
struct
time
spec
deadline
;
struct
time
val
deadline
;
unsigned
delay
;
}
stun_timer_t
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment