Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
81d977c7
Commit
81d977c7
authored
9 years ago
by
Deomid Ryabkov
Committed by
rojer
9 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce mg_time() and use it internally
PUBLISHED_FROM=024a2d7849a800381d58460877eacccfc93b1cdd
parent
f477898c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
13 deletions
+17
-13
mongoose.c
mongoose.c
+11
-8
mongoose.h
mongoose.h
+6
-5
No files found.
mongoose.c
View file @
81d977c7
...
...
@@ -2161,7 +2161,7 @@ MG_INTERNAL struct mg_connection *mg_create_connection(
conn
->
sock
=
INVALID_SOCKET
;
conn
->
handler
=
callback
;
conn
->
mgr
=
mgr
;
conn
->
last_io_time
=
cs
_time
();
conn
->
last_io_time
=
mg
_time
();
conn
->
flags
=
opts
.
flags
&
_MG_ALLOWED_CONNECT_FLAGS_MASK
;
conn
->
user_data
=
opts
.
user_data
;
/*
...
...
@@ -2460,7 +2460,7 @@ MG_INTERNAL size_t recv_avail_size(struct mg_connection *conn, size_t max) {
}
void
mg_send
(
struct
mg_connection
*
nc
,
const
void
*
buf
,
int
len
)
{
nc
->
last_io_time
=
cs
_time
();
nc
->
last_io_time
=
mg
_time
();
if
(
nc
->
flags
&
MG_F_UDP
)
{
mg_if_udp_send
(
nc
,
buf
,
len
);
}
else
{
...
...
@@ -2491,7 +2491,7 @@ static void mg_recv_common(struct mg_connection *nc, void *buf, int len) {
MG_FREE
(
buf
);
return
;
}
nc
->
last_io_time
=
cs
_time
();
nc
->
last_io_time
=
mg
_time
();
if
(
nc
->
recv_mbuf
.
len
==
0
)
{
/* Adopt buf as recv_mbuf's backing store. */
mbuf_free
(
&
nc
->
recv_mbuf
);
...
...
@@ -2618,7 +2618,7 @@ static void resolve_cb(struct mg_dns_message *msg, void *data,
}
if
(
e
==
MG_RESOLVE_TIMEOUT
)
{
double
now
=
cs
_time
();
double
now
=
mg
_time
();
mg_call
(
nc
,
NULL
,
MG_EV_TIMER
,
&
now
);
}
...
...
@@ -2832,6 +2832,10 @@ double mg_set_timer(struct mg_connection *c, double timestamp) {
}
return
result
;
}
double
mg_time
()
{
return
cs_time
();
}
#ifdef NS_MODULE_LINES
#line 1 "./src/net_if_socket.c"
/**/
...
...
@@ -2840,7 +2844,6 @@ double mg_set_timer(struct mg_connection *c, double timestamp) {
/* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/util.h" */
/* Amalgamated: #include "common/cs_time.h" */
#define MG_TCP_RECV_BUFFER_SIZE 1024
#define MG_UDP_RECV_BUFFER_SIZE 1500
...
...
@@ -3420,7 +3423,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
double
now
;
num_ev
=
epoll_wait
(
epoll_fd
,
events
,
MG_EPOLL_MAX_EVENTS
,
timeout_ms
);
now
=
cs
_time
();
now
=
mg
_time
();
DBG
((
"epoll_wait @ %ld num_ev=%d"
,
(
long
)
now
,
num_ev
));
while
(
num_ev
--
>
0
)
{
...
...
@@ -3501,7 +3504,7 @@ void mg_add_to_set(sock_t sock, fd_set *set, sock_t *max_fd) {
}
time_t
mg_mgr_poll
(
struct
mg_mgr
*
mgr
,
int
milli
)
{
double
now
=
cs
_time
();
double
now
=
mg
_time
();
struct
mg_connection
*
nc
,
*
tmp
;
struct
timeval
tv
;
fd_set
read_set
,
write_set
,
err_set
;
...
...
@@ -3542,7 +3545,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
tv
.
tv_usec
=
(
milli
%
1000
)
*
1000
;
num_selected
=
select
((
int
)
max_fd
+
1
,
&
read_set
,
&
write_set
,
&
err_set
,
&
tv
);
now
=
cs
_time
();
now
=
mg
_time
();
DBG
((
"select @ %ld num_ev=%d of %d"
,
(
long
)
now
,
num_selected
,
num_fds
));
#ifndef MG_DISABLE_SOCKETPAIR
...
...
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
81d977c7
...
...
@@ -1119,7 +1119,7 @@ enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
*
* ```
* c = mg_connect(&mgr, "cesanta.com", ev_handler);
* mg_set_timer(c,
time(NULL
) + 1.5);
* mg_set_timer(c,
mg_time(
) + 1.5);
* ...
*
* void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
...
...
@@ -1131,13 +1131,14 @@ enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
* log("Connect timeout");
* c->flags |= MG_F_CLOSE_IMMEDIATELY;
* break;
```
*
* NOTE: sub-second precision is not implemented yet, current granularity
* is 1 second.
*/
double
mg_set_timer
(
struct
mg_connection
*
c
,
double
timestamp
);
/*
* A sub-second precision version of time().
*/
double
mg_time
();
#ifdef __cplusplus
}
#endif
/* __cplusplus */
...
...
This diff is collapsed.
Click to expand it.
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