Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
c6eaca57
Commit
c6eaca57
authored
May 21, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed code so that the proper error code is always returned even in the event
that closesocket() fails.
parent
7e09a085
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
sockets_kernel_1.cpp
dlib/sockets/sockets_kernel_1.cpp
+15
-9
No files found.
dlib/sockets/sockets_kernel_1.cpp
View file @
c6eaca57
...
...
@@ -205,7 +205,7 @@ namespace dlib
hostent
*
address
;
unsigned
long
ipnum
=
inet_addr
(
ip
.
c_str
());
// if inet_addr cou
dl
n't convert ip then return an error
// if inet_addr cou
ld
n't convert ip then return an error
if
(
ipnum
==
INADDR_NONE
)
{
return
OTHER_ERROR
;
...
...
@@ -693,7 +693,7 @@ namespace dlib
{
// if there is a specific ip to listen on
sa
.
sin_addr
.
S_un
.
S_addr
=
inet_addr
(
ip
.
c_str
());
// if inet_addr cou
nd
't convert the ip then return an error
// if inet_addr cou
ldn
't convert the ip then return an error
if
(
sa
.
sin_addr
.
S_un
.
S_addr
==
INADDR_NONE
)
{
closesocket
(
sock
);
...
...
@@ -707,11 +707,13 @@ namespace dlib
// bind the new socket to the requested port and ip
if
(
bind
(
sock
,
reinterpret_cast
<
sockaddr
*>
(
&
sa
),
sizeof
(
sockaddr_in
))
==
SOCKET_ERROR
)
{
// if there was an error
{
const
int
err
=
WSAGetLastError
();
// if there was an error
closesocket
(
sock
);
// if the port is already bound then return PORTINUSE
if
(
WSAGetLastError
()
==
WSAEADDRINUSE
)
if
(
err
==
WSAEADDRINUSE
)
return
PORTINUSE
;
else
return
OTHER_ERROR
;
...
...
@@ -721,11 +723,12 @@ namespace dlib
// tell the new socket to listen
if
(
listen
(
sock
,
SOMAXCONN
)
==
SOCKET_ERROR
)
{
const
int
err
=
WSAGetLastError
();
// if there was an error return OTHER_ERROR
closesocket
(
sock
);
// if the port is already bound then return PORTINUSE
if
(
WSAGetLastError
()
==
WSAEADDRINUSE
)
if
(
err
==
WSAEADDRINUSE
)
return
PORTINUSE
;
else
return
OTHER_ERROR
;
...
...
@@ -810,7 +813,7 @@ namespace dlib
foreign_sa
.
sin_port
=
htons
(
foreign_port
);
foreign_sa
.
sin_addr
.
S_un
.
S_addr
=
inet_addr
(
foreign_ip
.
c_str
());
// if inet_addr cou
nd
't convert the ip then return an error
// if inet_addr cou
ldn
't convert the ip then return an error
if
(
foreign_sa
.
sin_addr
.
S_un
.
S_addr
==
INADDR_NONE
)
{
closesocket
(
sock
);
...
...
@@ -852,11 +855,13 @@ namespace dlib
sizeof
(
sockaddr_in
)
)
==
SOCKET_ERROR
)
{
// if there was an error
{
const
int
err
=
WSAGetLastError
();
// if there was an error
closesocket
(
sock
);
// if the port is already bound then return PORTINUSE
if
(
WSAGetLastError
()
==
WSAEADDRINUSE
)
if
(
err
==
WSAEADDRINUSE
)
return
PORTINUSE
;
else
return
OTHER_ERROR
;
...
...
@@ -870,9 +875,10 @@ namespace dlib
)
==
SOCKET_ERROR
)
{
const
int
err
=
WSAGetLastError
();
closesocket
(
sock
);
// if the port is already bound then return PORTINUSE
if
(
WSAGetLastError
()
==
WSAEADDRINUSE
)
if
(
err
==
WSAEADDRINUSE
)
return
PORTINUSE
;
else
return
OTHER_ERROR
;
...
...
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