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
b597da34
Commit
b597da34
authored
Oct 05, 2012
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass user_data to the callback
parent
bf387f95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
mongoose.c
mongoose.c
+3
-0
unit_test.c
test/unit_test.c
+17
-0
No files found.
mongoose.c
View file @
b597da34
...
...
@@ -518,6 +518,9 @@ const char **mg_get_valid_option_names(void) {
}
static
void
*
call_user
(
struct
mg_connection
*
conn
,
enum
mg_event
event
)
{
if
(
conn
!=
NULL
&&
conn
->
ctx
!=
NULL
)
{
conn
->
request_info
.
user_data
=
conn
->
ctx
->
user_data
;
}
return
conn
==
NULL
||
conn
->
ctx
==
NULL
||
conn
->
ctx
->
user_callback
==
NULL
?
NULL
:
conn
->
ctx
->
user_callback
(
event
,
conn
);
}
...
...
test/unit_test.c
View file @
b597da34
...
...
@@ -333,6 +333,22 @@ static void test_lua(void) {
}
#endif
static
void
*
user_data_tester
(
enum
mg_event
event
,
struct
mg_connection
*
conn
)
{
struct
mg_request_info
*
ri
=
mg_get_request_info
(
conn
);
ASSERT
(
ri
->
user_data
==
(
void
*
)
123
);
ASSERT
(
event
==
MG_NEW_REQUEST
);
return
NULL
;
}
static
void
test_user_data
(
void
)
{
static
const
char
*
options
[]
=
{
"listening_ports"
,
UNUSED_PORT
,
NULL
};
struct
mg_context
*
ctx
;
ASSERT
((
ctx
=
mg_start
(
user_data_tester
,
(
void
*
)
123
,
options
))
!=
NULL
);
ASSERT
(
ctx
->
user_data
==
(
void
*
)
123
);
call_user
(
fc
(
ctx
),
MG_NEW_REQUEST
);
}
int
main
(
void
)
{
test_base64_encode
();
test_match_prefix
();
...
...
@@ -343,6 +359,7 @@ int main(void) {
test_mg_get_var
();
test_set_throttle
();
test_next_option
();
test_user_data
();
#ifdef USE_LUA
test_lua
();
#endif
...
...
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