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
8ce1562f
Commit
8ce1562f
authored
Jul 16, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using SetHandleInformation() to make socket handles on Windows non-inheritable
parent
49d90162
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
mongoose.c
mongoose.c
+7
-3
No files found.
mongoose.c
View file @
8ce1562f
...
@@ -1258,7 +1258,9 @@ static int poll(struct pollfd *pfd, int n, int milliseconds) {
...
@@ -1258,7 +1258,9 @@ static int poll(struct pollfd *pfd, int n, int milliseconds) {
}
}
#endif // HAVE_POLL
#endif // HAVE_POLL
#define set_close_on_exec(x) // No FD_CLOEXEC on Windows
static
void
set_close_on_exec
(
SOCKET
sock
)
{
(
void
)
SetHandleInformation
((
HANDLE
)
sock
,
HANDLE_FLAG_INHERIT
,
0
);
}
int
mg_start_thread
(
mg_thread_func_t
f
,
void
*
p
)
{
int
mg_start_thread
(
mg_thread_func_t
f
,
void
*
p
)
{
return
(
long
)
_beginthread
((
void
(
__cdecl
*
)(
void
*
))
f
,
0
,
p
)
==
-
1L
?
-
1
:
0
;
return
(
long
)
_beginthread
((
void
(
__cdecl
*
)(
void
*
))
f
,
0
,
p
)
==
-
1L
?
-
1
:
0
;
...
@@ -2563,6 +2565,7 @@ static int conn2(const char *host, int port, int use_ssl,
...
@@ -2563,6 +2565,7 @@ static int conn2(const char *host, int port, int use_ssl,
}
else
if
((
sock
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
))
==
INVALID_SOCKET
)
{
}
else
if
((
sock
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
))
==
INVALID_SOCKET
)
{
snprintf
(
ebuf
,
ebuf_len
,
"socket(): %s"
,
strerror
(
ERRNO
));
snprintf
(
ebuf
,
ebuf_len
,
"socket(): %s"
,
strerror
(
ERRNO
));
}
else
{
}
else
{
set_close_on_exec
(
sock
);
sin
.
sin_family
=
AF_INET
;
sin
.
sin_family
=
AF_INET
;
sin
.
sin_port
=
htons
((
uint16_t
)
port
);
sin
.
sin_port
=
htons
((
uint16_t
)
port
);
sin
.
sin_addr
=
*
(
struct
in_addr
*
)
he
->
h_addr_list
[
0
];
sin
.
sin_addr
=
*
(
struct
in_addr
*
)
he
->
h_addr_list
[
0
];
...
@@ -4549,8 +4552,8 @@ static int set_ports_option(struct mg_context *ctx) {
...
@@ -4549,8 +4552,8 @@ static int set_ports_option(struct mg_context *ctx) {
#endif
#endif
bind
(
so
.
sock
,
&
so
.
lsa
.
sa
,
sizeof
(
so
.
lsa
))
!=
0
||
bind
(
so
.
sock
,
&
so
.
lsa
.
sa
,
sizeof
(
so
.
lsa
))
!=
0
||
listen
(
so
.
sock
,
SOMAXCONN
)
!=
0
)
{
listen
(
so
.
sock
,
SOMAXCONN
)
!=
0
)
{
cry
(
fc
(
ctx
),
"%s: cannot bind to %.*s: %
s
"
,
__func__
,
cry
(
fc
(
ctx
),
"%s: cannot bind to %.*s: %
d
"
,
__func__
,
(
int
)
vec
.
len
,
vec
.
ptr
,
strerror
(
ERRNO
)
);
(
int
)
vec
.
len
,
vec
.
ptr
,
ERRNO
);
closesocket
(
so
.
sock
);
closesocket
(
so
.
sock
);
success
=
0
;
success
=
0
;
}
else
if
((
ptr
=
realloc
(
ctx
->
listening_sockets
,
}
else
if
((
ptr
=
realloc
(
ctx
->
listening_sockets
,
...
@@ -5170,6 +5173,7 @@ static void accept_new_connection(const struct socket *listener,
...
@@ -5170,6 +5173,7 @@ static void accept_new_connection(const struct socket *listener,
}
else
{
}
else
{
// Put so socket structure into the queue
// Put so socket structure into the queue
DEBUG_TRACE
((
"Accepted socket %d"
,
(
int
)
so
.
sock
));
DEBUG_TRACE
((
"Accepted socket %d"
,
(
int
)
so
.
sock
));
set_close_on_exec
(
so
.
sock
);
so
.
is_ssl
=
listener
->
is_ssl
;
so
.
is_ssl
=
listener
->
is_ssl
;
so
.
ssl_redir
=
listener
->
ssl_redir
;
so
.
ssl_redir
=
listener
->
ssl_redir
;
getsockname
(
so
.
sock
,
&
so
.
lsa
.
sa
,
&
len
);
getsockname
(
so
.
sock
,
&
so
.
lsa
.
sa
,
&
len
);
...
...
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