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
ccc6a8bb
Commit
ccc6a8bb
authored
Oct 21, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an implicit conversion from strings to network_address objects.
parent
81c484c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
26 deletions
+72
-26
sockets_extensions.cpp
dlib/sockets/sockets_extensions.cpp
+13
-10
sockets_extensions.h
dlib/sockets/sockets_extensions.h
+19
-7
sockets_extensions_abstract.h
dlib/sockets/sockets_extensions_abstract.h
+40
-9
No files found.
dlib/sockets/sockets_extensions.cpp
View file @
ccc6a8bb
...
...
@@ -17,6 +17,19 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
network_address
::
network_address
(
const
std
::
string
&
full_address
)
{
std
::
istringstream
sin
(
full_address
);
sin
>>
*
this
;
if
(
!
sin
)
throw
invalid_network_address
(
full_address
);
}
// ----------------------------------------------------------------------------------------
void
serialize
(
...
...
@@ -242,16 +255,6 @@ namespace dlib
return
data
->
con
;
}
// ----------------------------------------------------------------------------------------
connection
*
connect
(
const
network_address
&
addr
,
unsigned
long
timeout
)
{
return
connect
(
addr
.
host_address
,
addr
.
port
,
timeout
);
}
// ----------------------------------------------------------------------------------------
bool
is_ip_address
(
...
...
dlib/sockets/sockets_extensions.h
View file @
ccc6a8bb
...
...
@@ -12,12 +12,31 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
class
invalid_network_address
:
public
dlib
::
error
{
public
:
invalid_network_address
(
const
std
::
string
&
msg
)
:
dlib
::
error
(
msg
)
{};
};
// ----------------------------------------------------------------------------------------
struct
network_address
{
network_address
()
:
port
(
0
){}
network_address
(
const
std
::
string
&
full_address
);
network_address
(
const
char
*
full_address
)
{
*
this
=
network_address
(
std
::
string
(
full_address
));
}
network_address
(
const
std
::
string
&
host_address_
,
const
unsigned
short
port_
...
...
@@ -68,13 +87,6 @@ namespace dlib
unsigned
long
timeout
);
// ----------------------------------------------------------------------------------------
connection
*
connect
(
const
network_address
&
addr
,
unsigned
long
timeout
);
// ----------------------------------------------------------------------------------------
bool
is_ip_address
(
...
...
dlib/sockets/sockets_extensions_abstract.h
View file @
ccc6a8bb
...
...
@@ -11,6 +11,17 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
class
invalid_network_address
:
public
dlib
::
error
{
/*!
WHAT THIS OBJECT REPRESENTS
This is the exception thrown by network_address's constructor if the
input is invalid.
!*/
};
// ----------------------------------------------------------------------------------------
struct
network_address
...
...
@@ -33,6 +44,33 @@ namespace dlib
- #port == 0
!*/
network_address
(
const
std
::
string
&
full_address
);
/*!
ensures
- interprets full_address as a network address of the form:
host_address:port
and assigns each part into #host_address and #port. For example,
network_address("localhost:80") would result in a network_address
object where host_address was "localhost" and port was 80.
throws
- invalid_network_address
This exception is thrown if the full_address string can't be
interpreted as a valid network address.
!*/
network_address
(
const
char
*
full_address
);
/*!
requires
- full_address == a valid pointer to a null terminated string
ensures
- Invoking this constructor is equivalent to performing
network_address(std::string(full_address))
!*/
network_address
(
const
std
::
string
&
host_address_
,
const
unsigned
short
port_
...
...
@@ -110,6 +148,8 @@ namespace dlib
- std::bad_alloc
!*/
// ----------------------------------------------------------------------------------------
connection
*
connect
(
const
network_address
&
addr
);
...
...
@@ -138,15 +178,6 @@ namespace dlib
- std::bad_alloc
!*/
connection
*
connect
(
const
network_address
&
addr
,
unsigned
long
timeout
);
/*!
ensures
- returns connect(addr.host_address, addr_port, timeout);
!*/
// ----------------------------------------------------------------------------------------
...
...
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