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
b80157b7
Commit
b80157b7
authored
Feb 03, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Setting user data pointer properly
parent
f9311f0b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
mongoose.c
mongoose.c
+2
-1
unit_test.c
test/unit_test.c
+23
-0
No files found.
mongoose.c
View file @
b80157b7
...
...
@@ -4878,12 +4878,13 @@ static void *worker_thread(void *thread_func_param) {
}
else
{
conn
->
buf_size
=
MAX_REQUEST_SIZE
;
conn
->
buf
=
(
char
*
)
(
conn
+
1
);
conn
->
ctx
=
ctx
;
conn
->
request_info
.
user_data
=
ctx
->
user_data
;
// Call consume_socket() even when ctx->stop_flag > 0, to let it signal
// sq_empty condvar to wake up the master waiting in produce_socket()
while
(
consume_socket
(
ctx
,
&
conn
->
client
))
{
conn
->
birth_time
=
time
(
NULL
);
conn
->
ctx
=
ctx
;
// Fill in IP, port info early so even if SSL setup below fails,
// error handler would have the corresponding info.
...
...
test/unit_test.c
View file @
b80157b7
...
...
@@ -539,6 +539,28 @@ static void test_request_replies(void) {
mg_stop
(
ctx
);
}
static
int
user_data_callback
(
struct
mg_connection
*
conn
)
{
ASSERT
(
mg_get_request_info
(
conn
)
->
user_data
==
(
void
*
)
123
);
mg_printf
(
conn
,
"HTTP/1.0 200 OK
\r\n\r\n
hi"
);
return
1
;
}
static
void
test_user_data
(
void
)
{
char
ebuf
[
100
];
struct
mg_callbacks
callbacks
;
struct
mg_connection
*
conn
;
struct
mg_context
*
ctx
;
memset
(
&
callbacks
,
0
,
sizeof
(
callbacks
));
callbacks
.
begin_request
=
user_data_callback
;
ASSERT
((
ctx
=
mg_start
(
&
callbacks
,
(
void
*
)
123
,
OPTIONS
))
!=
NULL
);
ASSERT
((
conn
=
mg_download
(
"localhost"
,
atoi
(
HTTPS_PORT
),
1
,
ebuf
,
sizeof
(
ebuf
),
"%s"
,
"GET / HTTP/1.0
\r\n\r\n
"
))
!=
NULL
);
mg_close_connection
(
conn
);
mg_stop
(
ctx
);
}
int
__cdecl
main
(
void
)
{
test_alloc_vprintf
();
test_base64_encode
();
...
...
@@ -554,6 +576,7 @@ int __cdecl main(void) {
test_skip_quoted
();
test_mg_upload
();
test_request_replies
();
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