Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
paho.mqtt.c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eclipse
paho.mqtt.c
Commits
5f68068c
Commit
5f68068c
authored
May 21, 2018
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for #284 time change into past
parent
a66faf8c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
15 deletions
+40
-15
MQTTAsync.c
src/MQTTAsync.c
+11
-4
MQTTClient.c
src/MQTTClient.c
+11
-4
Thread.c
src/Thread.c
+18
-7
No files found.
src/MQTTAsync.c
View file @
5f68068c
...
...
@@ -198,7 +198,7 @@ START_TIME_TYPE MQTTAsync_start_clock(void)
START_TIME_TYPE
MQTTAsync_start_clock
(
void
)
{
static
struct
timespec
start
;
clock_gettime
(
CLOCK_
REALTIME
,
&
start
);
clock_gettime
(
CLOCK_
MONOTONIC
,
&
start
);
return
start
;
}
#else
...
...
@@ -206,7 +206,11 @@ START_TIME_TYPE MQTTAsync_start_clock(void)
START_TIME_TYPE
MQTTAsync_start_clock
(
void
)
{
static
struct
timeval
start
;
gettimeofday
(
&
start
,
NULL
);
static
struct
timespec
start_ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
start_ts
);
start
.
tv_sec
=
start_ts
.
tv_sec
;
start
.
tv_usec
=
start_ts
.
tv_nsec
/
1000
;
return
start
;
}
#endif
...
...
@@ -223,7 +227,7 @@ long MQTTAsync_elapsed(struct timespec start)
{
struct
timespec
now
,
res
;
clock_gettime
(
CLOCK_
REALTIME
,
&
now
);
clock_gettime
(
CLOCK_
MONOTONIC
,
&
now
);
ntimersub
(
now
,
start
,
res
);
return
(
res
.
tv_sec
)
*
1000L
+
(
res
.
tv_nsec
)
/
1000000L
;
}
...
...
@@ -231,8 +235,11 @@ long MQTTAsync_elapsed(struct timespec start)
long
MQTTAsync_elapsed
(
struct
timeval
start
)
{
struct
timeval
now
,
res
;
static
struct
timespec
now_ts
;
gettimeofday
(
&
now
,
NULL
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
now_ts
);
now
.
tv_sec
=
now_ts
.
tv_sec
;
now
.
tv_usec
=
now_ts
.
tv_nsec
/
1000
;
timersub
(
&
now
,
&
start
,
&
res
);
return
(
res
.
tv_sec
)
*
1000
+
(
res
.
tv_usec
)
/
1000
;
}
...
...
src/MQTTClient.c
View file @
5f68068c
...
...
@@ -233,7 +233,7 @@ START_TIME_TYPE MQTTClient_start_clock(void)
START_TIME_TYPE
MQTTClient_start_clock
(
void
)
{
static
struct
timespec
start
;
clock_gettime
(
CLOCK_
REALTIME
,
&
start
);
clock_gettime
(
CLOCK_
MONOTONIC
,
&
start
);
return
start
;
}
#else
...
...
@@ -241,7 +241,11 @@ START_TIME_TYPE MQTTClient_start_clock(void)
START_TIME_TYPE
MQTTClient_start_clock
(
void
)
{
static
struct
timeval
start
;
gettimeofday
(
&
start
,
NULL
);
static
struct
timespec
start_ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
start_ts
);
start
.
tv_sec
=
start_ts
.
tv_sec
;
start
.
tv_usec
=
start_ts
.
tv_nsec
/
1000
;
return
start
;
}
#endif
...
...
@@ -258,7 +262,7 @@ long MQTTClient_elapsed(struct timespec start)
{
struct
timespec
now
,
res
;
clock_gettime
(
CLOCK_
REALTIME
,
&
now
);
clock_gettime
(
CLOCK_
MONOTONIC
,
&
now
);
ntimersub
(
now
,
start
,
res
);
return
(
res
.
tv_sec
)
*
1000L
+
(
res
.
tv_nsec
)
/
1000000L
;
}
...
...
@@ -266,8 +270,11 @@ long MQTTClient_elapsed(struct timespec start)
long
MQTTClient_elapsed
(
struct
timeval
start
)
{
struct
timeval
now
,
res
;
static
struct
timespec
now_ts
;
gettimeofday
(
&
now
,
NULL
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
now_ts
);
now
.
tv_sec
=
now_ts
.
tv_sec
;
now
.
tv_usec
=
now_ts
.
tv_nsec
/
1000
;
timersub
(
&
now
,
&
start
,
&
res
);
return
(
res
.
tv_sec
)
*
1000
+
(
res
.
tv_usec
)
/
1000
;
}
...
...
src/Thread.c
View file @
5f68068c
/*******************************************************************************
* Copyright (c) 2009, 201
7
IBM Corp.
* Copyright (c) 2009, 201
8
IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
...
...
@@ -16,6 +16,7 @@
* Ian Craggs - bug #415042 - start Linux thread as disconnected
* Ian Craggs - fix for bug #420851
* Ian Craggs - change MacOS semaphore implementation
* Ian Craggs - fix for clock #284
*******************************************************************************/
/**
...
...
@@ -247,6 +248,9 @@ int Thread_wait_sem(sem_type sem, int timeout)
usleep
(
interval
);
/* microseconds - .1 of a second */
}
#else
/* We have to use CLOCK_REALTIME rather than MONOTONIC for sem_timedwait interval.
* Does this make it susceptible to system clock changes?
*/
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
ts
)
!=
-
1
)
{
ts
.
tv_sec
+=
timeout
;
...
...
@@ -333,11 +337,17 @@ int Thread_destroy_sem(sem_type sem)
cond_type
Thread_create_cond
(
void
)
{
cond_type
condvar
=
NULL
;
pthread_condattr_t
attr
;
int
rc
=
0
;
FUNC_ENTRY
;
pthread_condattr_init
(
&
attr
);
#if !defined(OSX)
pthread_condattr_setclock
(
&
attr
,
CLOCK_MONOTONIC
);
#endif
condvar
=
malloc
(
sizeof
(
cond_type_struct
));
rc
=
pthread_cond_init
(
&
condvar
->
cond
,
NULL
);
rc
=
pthread_cond_init
(
&
condvar
->
cond
,
&
attr
);
rc
=
pthread_mutex_init
(
&
condvar
->
mutex
,
NULL
);
FUNC_EXIT_RC
(
rc
);
...
...
@@ -368,13 +378,14 @@ int Thread_wait_cond(cond_type condvar, int timeout)
FUNC_ENTRY
;
int
rc
=
0
;
struct
timespec
cond_timeout
;
struct
timeval
cur_time
;
gettimeofday
(
&
cur_time
,
NULL
);
cond_timeout
.
tv_sec
=
cur_time
.
tv_sec
+
timeout
;
cond_timeout
.
tv_nsec
=
cur_time
.
tv_usec
*
1000
;
#if defined(OSX)
clock_gettime
(
CLOCK_REALTIME
,
&
cond_timeout
);
#else
clock_gettime
(
CLOCK_MONOTONIC
,
&
cond_timeout
);
#endif
cond_timeout
.
tv_sec
+=
timeout
;
pthread_mutex_lock
(
&
condvar
->
mutex
);
rc
=
pthread_cond_timedwait
(
&
condvar
->
cond
,
&
condvar
->
mutex
,
&
cond_timeout
);
pthread_mutex_unlock
(
&
condvar
->
mutex
);
...
...
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