Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
f059e41c
Commit
f059e41c
authored
Oct 14, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed mg_set_listening_socket() and mg_get_listening_socket(), added mg_copy_listeners()
parent
2cce91de
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
20 deletions
+17
-20
multi_threaded_server.c
examples/multi_threaded_server/multi_threaded_server.c
+2
-2
mongoose.c
mongoose.c
+14
-16
mongoose.h
mongoose.h
+1
-2
No files found.
examples/multi_threaded_server/multi_threaded_server.c
View file @
f059e41c
...
...
@@ -26,9 +26,9 @@ int main(void) {
server1
=
mg_create_server
((
void
*
)
"1"
,
ev_handler
);
server2
=
mg_create_server
((
void
*
)
"2"
,
ev_handler
);
// Make both server1 and server2 listen on the same socket
// Make both server1 and server2 listen on the same socket
s
mg_set_option
(
server1
,
"listening_port"
,
"8080"
);
//mg_set_listening_socket(server2, mg_get_listening_socket(server1)
);
mg_copy_listeners
(
server1
,
server2
);
// server1 goes to separate thread, server 2 runs in main thread.
// IMPORTANT: NEVER LET DIFFERENT THREADS HANDLE THE SAME SERVER.
...
...
mongoose.c
View file @
f059e41c
...
...
@@ -4807,9 +4807,8 @@ void mg_destroy_server(struct mg_server **server) {
}
struct
mg_connection
*
mg_next
(
struct
mg_server
*
s
,
struct
mg_connection
*
c
)
{
struct
connection
*
conn
=
MG_CONN_2_CONN
(
c
);
struct
ns_connection
*
nc
=
ns_next
(
&
s
->
ns_mgr
,
c
==
NULL
?
NULL
:
conn
->
ns_conn
);
struct
ns_connection
*
nc
=
ns_next
(
&
s
->
ns_mgr
,
c
==
NULL
?
NULL
:
MG_CONN_2_CONN
(
c
)
->
ns_conn
);
if
(
nc
!=
NULL
&&
nc
->
user_data
!=
NULL
)
{
return
&
((
struct
connection
*
)
nc
->
user_data
)
->
mg_conn
;
}
else
{
...
...
@@ -4923,6 +4922,18 @@ const char **mg_get_valid_option_names(void) {
return
static_config_options
;
}
void
mg_copy_listeners
(
struct
mg_server
*
s
,
struct
mg_server
*
to
)
{
struct
ns_connection
*
c
;
for
(
c
=
ns_next
(
&
s
->
ns_mgr
,
NULL
);
c
!=
NULL
;
c
=
ns_next
(
&
s
->
ns_mgr
,
c
))
{
struct
ns_connection
*
tmp
;
if
((
c
->
flags
&
NSF_LISTENING
)
&&
(
tmp
=
malloc
(
sizeof
(
*
tmp
)))
!=
NULL
)
{
memcpy
(
tmp
,
c
,
sizeof
(
*
tmp
));
tmp
->
mgr
=
&
to
->
ns_mgr
;
ns_add_conn
(
tmp
->
mgr
,
tmp
);
}
}
}
static
int
get_option_index
(
const
char
*
name
)
{
int
i
;
...
...
@@ -5209,19 +5220,6 @@ void mg_wakeup_server(struct mg_server *server) {
ns_broadcast
(
&
server
->
ns_mgr
,
NULL
,
(
void
*
)
""
,
0
);
}
#if 0
void mg_set_listening_socket(struct mg_server *server, int sock) {
if (server->ns_mgr.listening_sock != INVALID_SOCKET) {
closesocket(server->ns_mgr.listening_sock);
}
server->ns_mgr.listening_sock = (sock_t) sock;
}
int mg_get_listening_socket(struct mg_server *server) {
return server->ns_mgr.listening_sock;
}
#endif
const
char
*
mg_get_option
(
const
struct
mg_server
*
server
,
const
char
*
name
)
{
const
char
**
opts
=
(
const
char
**
)
server
->
config_options
;
int
i
=
get_option_index
(
name
);
...
...
mongoose.h
View file @
f059e41c
...
...
@@ -93,8 +93,7 @@ const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
int
mg_poll_server
(
struct
mg_server
*
,
int
milliseconds
);
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_copy_listeners
(
struct
mg_server
*
from
,
struct
mg_server
*
to
);
struct
mg_connection
*
mg_next
(
struct
mg_server
*
,
struct
mg_connection
*
);
void
mg_wakeup_server
(
struct
mg_server
*
);
void
mg_wakeup_server_ex
(
struct
mg_server
*
,
mg_handler_t
,
const
char
*
,
...);
...
...
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