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
e4549f7b
Commit
e4549f7b
authored
Mar 02, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an option for a sockstreambuf to automatically flush its output
buffers before performing any network reads.
parent
10cf3028
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
5 deletions
+60
-5
sockstreambuf.cpp
dlib/sockstreambuf/sockstreambuf.cpp
+9
-0
sockstreambuf.h
dlib/sockstreambuf/sockstreambuf.h
+19
-2
sockstreambuf_abstract.h
dlib/sockstreambuf/sockstreambuf_abstract.h
+24
-0
sockstreambuf_unbuffered.h
dlib/sockstreambuf/sockstreambuf_unbuffered.h
+8
-3
No files found.
dlib/sockstreambuf/sockstreambuf.cpp
View file @
e4549f7b
...
@@ -109,6 +109,15 @@ namespace dlib
...
@@ -109,6 +109,15 @@ namespace dlib
// copy the putback characters into the putback end of the in_buffer
// copy the putback characters into the putback end of the in_buffer
std
::
memmove
(
in_buffer
+
(
max_putback
-
num_put_back
),
gptr
()
-
num_put_back
,
num_put_back
);
std
::
memmove
(
in_buffer
+
(
max_putback
-
num_put_back
),
gptr
()
-
num_put_back
,
num_put_back
);
if
(
flushes_output_on_read
())
{
if
(
flush_out_buffer
()
==
EOF
)
{
// an error occurred
return
EOF
;
}
}
int
num
=
con
.
read
(
in_buffer
+
max_putback
,
in_buffer_size
-
max_putback
);
int
num
=
con
.
read
(
in_buffer
+
max_putback
,
in_buffer_size
-
max_putback
);
if
(
num
<=
0
)
if
(
num
<=
0
)
{
{
...
...
dlib/sockstreambuf/sockstreambuf.h
View file @
e4549f7b
...
@@ -40,7 +40,8 @@ namespace dlib
...
@@ -40,7 +40,8 @@ namespace dlib
)
:
)
:
con
(
*
con_
),
con
(
*
con_
),
out_buffer
(
0
),
out_buffer
(
0
),
in_buffer
(
0
)
in_buffer
(
0
),
autoflush
(
false
)
{
{
init
();
init
();
}
}
...
@@ -50,7 +51,8 @@ namespace dlib
...
@@ -50,7 +51,8 @@ namespace dlib
)
:
)
:
con
(
*
con_
),
con
(
*
con_
),
out_buffer
(
0
),
out_buffer
(
0
),
in_buffer
(
0
)
in_buffer
(
0
),
autoflush
(
false
)
{
{
init
();
init
();
}
}
...
@@ -66,6 +68,20 @@ namespace dlib
...
@@ -66,6 +68,20 @@ namespace dlib
connection
*
get_connection
(
connection
*
get_connection
(
)
{
return
&
con
;
}
)
{
return
&
con
;
}
void
flush_output_on_read
()
{
autoflush
=
true
;
}
bool
flushes_output_on_read
()
const
{
return
autoflush
;
}
void
do_not_flush_output_on_read
()
{
autoflush
=
false
;
}
protected
:
protected
:
...
@@ -140,6 +156,7 @@ namespace dlib
...
@@ -140,6 +156,7 @@ namespace dlib
static
const
std
::
streamsize
in_buffer_size
=
10000
;
static
const
std
::
streamsize
in_buffer_size
=
10000
;
char
*
out_buffer
;
char
*
out_buffer
;
char
*
in_buffer
;
char
*
in_buffer
;
bool
autoflush
;
};
};
...
...
dlib/sockstreambuf/sockstreambuf_abstract.h
View file @
e4549f7b
...
@@ -53,6 +53,7 @@ namespace dlib
...
@@ -53,6 +53,7 @@ namespace dlib
- con == a valid connection object
- con == a valid connection object
ensures
ensures
- *this will read from and write to con
- *this will read from and write to con
- #flushes_output_on_read() == false
throws
throws
- std::bad_alloc
- std::bad_alloc
!*/
!*/
...
@@ -65,6 +66,7 @@ namespace dlib
...
@@ -65,6 +66,7 @@ namespace dlib
- con == a valid connection object
- con == a valid connection object
ensures
ensures
- *this will read from and write to con
- *this will read from and write to con
- #flushes_output_on_read() == false
throws
throws
- std::bad_alloc
- std::bad_alloc
!*/
!*/
...
@@ -88,6 +90,28 @@ namespace dlib
...
@@ -88,6 +90,28 @@ namespace dlib
reads from and writes to
reads from and writes to
!*/
!*/
void
flush_output_on_read
(
);
/*!
ensures
- #flushes_output_on_read() == true
!*/
bool
flushes_output_on_read
(
)
const
;
/*!
ensures
- This function returns true if this object will flush its output buffer
to the network socket before performing any network read.
!*/
void
do_not_flush_output_on_read
(
);
/*!
ensures
- #flushes_output_on_read() == false
!*/
};
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/sockstreambuf/sockstreambuf_unbuffered.h
View file @
e4549f7b
...
@@ -17,9 +17,14 @@ namespace dlib
...
@@ -17,9 +17,14 @@ namespace dlib
{
{
/*!
/*!
WHAT THIS OBJECT REPRESENTS
WHAT THIS OBJECT REPRESENTS
This is an implementation of the interface defined in sockstreambuf_abstract.h
This is an implementation of the interface defined in
except that it doesn't do any kind of buffering at all. It just writes
sockstreambuf_abstract.h except that it doesn't do any kind of buffering at
data directly to a connection.
all. It just writes data directly to a connection. However, note that we
don't implement the flushes_output_on_read() routine as this object always
flushes immediately (since it isn't buffers. Moreover, it should be
pointed out that this object is deprecated and only present for backwards
compatibility with previous versions of dlib. So you really should use the
sockstreambuf object instead.
INITIAL VALUE
INITIAL VALUE
con == a connection
con == a connection
...
...
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