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
08711f9b
Commit
08711f9b
authored
Jan 29, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a shutdown() method to iosockstream.
parent
4b11f1ce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
iosockstream.h
dlib/iosockstream/iosockstream.h
+13
-0
iosockstream_abstract.h
dlib/iosockstream/iosockstream_abstract.h
+13
-2
No files found.
dlib/iosockstream/iosockstream.h
View file @
08711f9b
...
...
@@ -59,6 +59,7 @@ namespace dlib
const
network_address
&
addr
)
{
auto_mutex
lock
(
class_mutex
);
close
();
con
.
reset
(
connect
(
addr
));
buf
.
reset
(
new
sockstreambuf
(
con
.
get
()));
...
...
@@ -79,6 +80,7 @@ namespace dlib
unsigned
long
timeout
)
{
auto_mutex
lock
(
class_mutex
);
close
(
timeout
);
con
.
reset
(
connect
(
addr
.
host_address
,
addr
.
port
,
timeout
));
buf
.
reset
(
new
sockstreambuf
(
con
.
get
()));
...
...
@@ -91,6 +93,7 @@ namespace dlib
unsigned
long
timeout
=
10000
)
{
auto_mutex
lock
(
class_mutex
);
rdbuf
(
0
);
try
{
...
...
@@ -126,12 +129,21 @@ namespace dlib
unsigned
long
timeout
)
{
auto_mutex
lock
(
class_mutex
);
if
(
con
)
{
con_timeout
.
reset
(
new
dlib
::
timeout
(
*
this
,
&
iosockstream
::
terminate_connection
,
timeout
,
con
));
}
}
void
shutdown
(
)
{
auto_mutex
lock
(
class_mutex
);
if
(
con
)
con
->
shutdown
();
}
private
:
void
terminate_connection
(
...
...
@@ -142,6 +154,7 @@ namespace dlib
}
scoped_ptr
<
timeout
>
con_timeout
;
rmutex
class_mutex
;
shared_ptr_thread_safe
<
connection
>
con
;
scoped_ptr
<
sockstreambuf
>
buf
;
...
...
dlib/iosockstream/iosockstream_abstract.h
View file @
08711f9b
...
...
@@ -22,8 +22,10 @@ namespace dlib
stream's output buffers.
THREAD SAFETY
It is not safe to touch this object from more than one thread at a time.
Therefore, you should mutex lock it if you need to do so.
It is not safe for multiple threads to make concurrent accesses to the same
instance of this object (except for calls to shutdown() which are always
threadsafe). Therefore, you should mutex lock an instance of this object
if you need to touch it from multiple threads.
!*/
public
:
...
...
@@ -147,6 +149,15 @@ namespace dlib
- This function has no effect on this object.
!*/
void
shutdown
(
);
/*!
ensures
- Immediately closes the TCP connection and causes all I/O operations on
this object to return an error.
- It is safe to call this function from any thread, therefore, you can use
it to signal when you want a connection to terminate from another thread.
!*/
};
// ----------------------------------------------------------------------------------------
...
...
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