Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
4b86d247
Commit
4b86d247
authored
Dec 04, 2015
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Response::send(): added an overload for char arrays to avoid string creation and memory allocation
parent
68083860
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
src/http.cc
src/http.cc
+6
-3
src/http.h
src/http.h
+23
-3
src/io.cc
src/io.cc
+1
-1
src/io.h
src/io.h
+3
-3
No files found.
src/http.cc
View file @
4b86d247
...
@@ -420,7 +420,7 @@ ResponseStream::ends() {
...
@@ -420,7 +420,7 @@ ResponseStream::ends() {
}
}
Async
::
Promise
<
ssize_t
>
Async
::
Promise
<
ssize_t
>
Response
::
putOnWire
(
const
std
::
string
&
body
)
Response
::
putOnWire
(
const
char
*
data
,
size_t
len
)
{
{
try
{
try
{
std
::
ostream
os
(
&
buf_
);
std
::
ostream
os
(
&
buf_
);
...
@@ -445,10 +445,13 @@ Response::putOnWire(const std::string& body)
...
@@ -445,10 +445,13 @@ Response::putOnWire(const std::string& body)
OUT
(
os
<<
crlf
);
OUT
(
os
<<
crlf
);
}
}
OUT
(
writeHeader
<
Header
::
ContentLength
>
(
os
,
body
.
size
()));
OUT
(
writeHeader
<
Header
::
ContentLength
>
(
os
,
len
));
OUT
(
os
<<
crlf
);
OUT
(
os
<<
crlf
);
os
<<
body
;
if
(
len
>
0
)
{
OUT
(
os
.
write
(
data
,
len
));
}
auto
buffer
=
buf_
.
buffer
();
auto
buffer
=
buf_
.
buffer
();
...
...
src/http.h
View file @
4b86d247
...
@@ -287,7 +287,7 @@ public:
...
@@ -287,7 +287,7 @@ public:
Async
::
Promise
<
ssize_t
>
send
(
Code
code
)
{
Async
::
Promise
<
ssize_t
>
send
(
Code
code
)
{
code_
=
code
;
code_
=
code
;
return
putOnWire
(
""
);
return
putOnWire
(
nullptr
,
0
);
}
}
Async
::
Promise
<
ssize_t
>
send
(
Async
::
Promise
<
ssize_t
>
send
(
Code
code
,
Code
code
,
...
@@ -304,7 +304,27 @@ public:
...
@@ -304,7 +304,27 @@ public:
headers_
.
add
(
std
::
make_shared
<
Header
::
ContentType
>
(
mime
));
headers_
.
add
(
std
::
make_shared
<
Header
::
ContentType
>
(
mime
));
}
}
return
putOnWire
(
body
);
return
putOnWire
(
body
.
c_str
(),
body
.
size
());
}
template
<
size_t
N
>
Async
::
Promise
<
ssize_t
>
send
(
Code
code
,
const
char
(
&
arr
)[
N
],
const
Mime
::
MediaType
&
mime
=
Mime
::
MediaType
())
{
/* @Refactor: code duplication */
code_
=
code
;
if
(
mime
.
isValid
())
{
auto
contentType
=
headers_
.
tryGet
<
Header
::
ContentType
>
();
if
(
contentType
)
contentType
->
setMime
(
mime
);
else
headers_
.
add
(
std
::
make_shared
<
Header
::
ContentType
>
(
mime
));
}
return
putOnWire
(
arr
,
N
-
1
);
}
}
ResponseStream
stream
(
Code
code
,
size_t
streamSize
=
DefaultStreamSize
)
{
ResponseStream
stream
(
Code
code
,
size_t
streamSize
=
DefaultStreamSize
)
{
...
@@ -336,7 +356,7 @@ private:
...
@@ -336,7 +356,7 @@ private:
peer_
=
peer
;
peer_
=
peer
;
}
}
Async
::
Promise
<
ssize_t
>
putOnWire
(
const
std
::
string
&
body
);
Async
::
Promise
<
ssize_t
>
putOnWire
(
const
char
*
data
,
size_t
len
);
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
;
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
;
DynamicStreamBuf
buf_
;
DynamicStreamBuf
buf_
;
...
...
src/io.cc
View file @
4b86d247
...
@@ -76,7 +76,7 @@ IoWorker::pin(const CpuSet& set) {
...
@@ -76,7 +76,7 @@ IoWorker::pin(const CpuSet& set) {
}
}
void
void
IoWorker
::
armTimer
(
IoWorker
::
armTimer
Ms
(
std
::
chrono
::
milliseconds
value
,
std
::
chrono
::
milliseconds
value
,
Async
::
Resolver
resolve
,
Async
::
Rejection
reject
)
Async
::
Resolver
resolve
,
Async
::
Rejection
reject
)
{
{
...
...
src/io.h
View file @
4b86d247
...
@@ -39,10 +39,10 @@ public:
...
@@ -39,10 +39,10 @@ public:
void
pin
(
const
CpuSet
&
set
);
void
pin
(
const
CpuSet
&
set
);
void
shutdown
();
void
shutdown
();
template
<
typename
Duration
>
template
<
typename
Duration
>
void
armTimer
(
Duration
timeout
,
Async
::
Resolver
resolve
,
Async
::
Rejection
reject
)
{
void
armTimer
(
Duration
timeout
,
Async
::
Resolver
resolve
,
Async
::
Rejection
reject
)
{
armTimer
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
timeout
),
armTimer
Ms
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
timeout
),
std
::
move
(
resolve
),
std
::
move
(
resolve
),
std
::
move
(
reject
));
std
::
move
(
reject
));
}
}
...
@@ -67,7 +67,7 @@ private:
...
@@ -67,7 +67,7 @@ private:
};
};
void
void
armTimer
(
std
::
chrono
::
milliseconds
value
,
Async
::
Resolver
,
Async
::
Rejection
reject
);
armTimer
Ms
(
std
::
chrono
::
milliseconds
value
,
Async
::
Resolver
,
Async
::
Rejection
reject
);
struct
Timer
{
struct
Timer
{
Timer
(
std
::
chrono
::
milliseconds
value
,
Timer
(
std
::
chrono
::
milliseconds
value
,
...
...
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