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
02f19fc0
Commit
02f19fc0
authored
Jan 17, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using mg_handler_t for iterate_over_connections()
parent
7690f9e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
websocket.c
examples/websocket.c
+4
-2
mongoose.c
mongoose.c
+6
-6
mongoose.h
mongoose.h
+2
-4
No files found.
examples/websocket.c
View file @
02f19fc0
#include <string.h>
#include "mongoose.h"
extern
const
char
*
find_embedded_file
(
const
char
*
,
size_t
*
);
static
void
iterate_callback
(
struct
mg_connection
*
c
,
void
*
param
)
{
static
int
iterate_callback
(
struct
mg_connection
*
c
)
{
if
(
c
->
is_websocket
)
{
char
buf
[
20
];
int
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%d"
,
*
(
int
*
)
param
);
int
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%d"
,
*
(
int
*
)
c
->
connection_
param
);
mg_websocket_write
(
c
,
1
,
buf
,
len
);
}
return
1
;
}
// This handler is called for each incoming websocket frame, one or more
...
...
mongoose.c
View file @
02f19fc0
...
...
@@ -3651,12 +3651,13 @@ struct mg_connection *mg_connect(struct mg_server *server, const char *host,
static
void
execute_iteration
(
struct
mg_server
*
server
)
{
struct
ll
*
lp
,
*
tmp
;
struct
connection
*
conn
;
union
{
void
(
*
f
)(
struct
mg_connection
*
,
void
*
)
;
void
*
p
;
}
msg
[
2
];
union
{
mg_handler_t
f
;
void
*
p
;
}
msg
[
2
];
recv
(
server
->
ctl
[
1
],
(
void
*
)
msg
,
sizeof
(
msg
),
0
);
LINKED_LIST_FOREACH
(
&
server
->
active_connections
,
lp
,
tmp
)
{
conn
=
LINKED_LIST_ENTRY
(
lp
,
struct
connection
,
link
);
msg
[
0
].
f
(
&
conn
->
mg_conn
,
msg
[
1
].
p
);
conn
->
mg_conn
.
connection_param
=
msg
[
1
].
p
;
msg
[
0
].
f
(
&
conn
->
mg_conn
);
}
}
...
...
@@ -3781,12 +3782,11 @@ void mg_destroy_server(struct mg_server **server) {
}
// Apply function to all active connections.
void
mg_iterate_over_connections
(
struct
mg_server
*
server
,
void
(
*
func
)(
struct
mg_connection
*
,
void
*
),
void
mg_iterate_over_connections
(
struct
mg_server
*
server
,
mg_handler_t
handler
,
void
*
param
)
{
// Send closure (function + parameter) to the IO thread to execute
union
{
void
(
*
f
)(
struct
mg_connection
*
,
void
*
)
;
void
*
p
;
}
msg
[
2
];
msg
[
0
].
f
=
func
;
union
{
mg_handler_t
f
;
void
*
p
;
}
msg
[
2
];
msg
[
0
].
f
=
handler
;
msg
[
1
].
p
=
param
;
send
(
server
->
ctl
[
0
],
(
void
*
)
msg
,
sizeof
(
msg
),
0
);
}
...
...
mongoose.h
View file @
02f19fc0
// Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
// Copyright (c) 2013 Cesanta Software Limited
// Copyright (c) 2013
-2014
Cesanta Software Limited
// All rights reserved
//
// This library is dual-licensed: you can redistribute it and/or modify
...
...
@@ -69,9 +69,7 @@ const char **mg_get_valid_option_names(void);
const
char
*
mg_get_option
(
const
struct
mg_server
*
server
,
const
char
*
name
);
void
mg_set_listening_socket
(
struct
mg_server
*
,
int
sock
);
int
mg_get_listening_socket
(
struct
mg_server
*
);
void
mg_iterate_over_connections
(
struct
mg_server
*
,
void
(
*
func
)(
struct
mg_connection
*
,
void
*
),
void
*
param
);
void
mg_iterate_over_connections
(
struct
mg_server
*
,
mg_handler_t
,
void
*
);
// Connection management functions
void
mg_send_status
(
struct
mg_connection
*
,
int
status_code
);
...
...
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