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
7b125802
Unverified
Commit
7b125802
authored
Jul 21, 2020
by
Igor [hyperxor]
Committed by
GitHub
Jul 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactoring in asyncWriteImpl (#801)
* Small refactoring in asyncWriteImpl * Trigger CI * Trigger CI
parent
a61d3be1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
34 deletions
+50
-34
include/pistache/transport.h
include/pistache/transport.h
+2
-0
src/common/transport.cc
src/common/transport.cc
+48
-34
No files found.
include/pistache/transport.h
View file @
7b125802
...
@@ -194,6 +194,8 @@ private:
...
@@ -194,6 +194,8 @@ private:
// This will attempt to drain the write queue for the fd
// This will attempt to drain the write queue for the fd
void
asyncWriteImpl
(
Fd
fd
);
void
asyncWriteImpl
(
Fd
fd
);
ssize_t
sendRawBuffer
(
Fd
fd
,
const
char
*
buffer
,
size_t
len
,
int
flags
);
ssize_t
sendFile
(
Fd
fd
,
Fd
file
,
off_t
offset
,
size_t
len
);
void
handlePeerDisconnection
(
const
std
::
shared_ptr
<
Peer
>
&
peer
);
void
handlePeerDisconnection
(
const
std
::
shared_ptr
<
Peer
>
&
peer
);
void
handleIncoming
(
const
std
::
shared_ptr
<
Peer
>
&
peer
);
void
handleIncoming
(
const
std
::
shared_ptr
<
Peer
>
&
peer
);
...
...
src/common/transport.cc
View file @
7b125802
...
@@ -226,43 +226,11 @@ void Transport::asyncWriteImpl(Fd fd) {
...
@@ -226,43 +226,11 @@ void Transport::asyncWriteImpl(Fd fd) {
if
(
buffer
.
isRaw
())
{
if
(
buffer
.
isRaw
())
{
auto
raw
=
buffer
.
raw
();
auto
raw
=
buffer
.
raw
();
auto
ptr
=
raw
.
data
().
c_str
()
+
totalWritten
;
auto
ptr
=
raw
.
data
().
c_str
()
+
totalWritten
;
bytesWritten
=
sendRawBuffer
(
fd
,
ptr
,
len
,
flags
);
#ifdef PISTACHE_USE_SSL
auto
it_
=
peers
.
find
(
fd
);
if
(
it_
==
std
::
end
(
peers
))
throw
std
::
runtime_error
(
"No peer found for fd: "
+
std
::
to_string
(
fd
));
if
(
it_
->
second
->
ssl
()
!=
NULL
)
{
auto
ssl_
=
static_cast
<
SSL
*>
(
it_
->
second
->
ssl
());
bytesWritten
=
SSL_write
(
ssl_
,
ptr
,
static_cast
<
int
>
(
len
));
}
else
{
#endif
/* PISTACHE_USE_SSL */
bytesWritten
=
::
send
(
fd
,
ptr
,
len
,
flags
);
#ifdef PISTACHE_USE_SSL
}
#endif
/* PISTACHE_USE_SSL */
}
else
{
}
else
{
auto
file
=
buffer
.
fd
();
auto
file
=
buffer
.
fd
();
off_t
offset
=
totalWritten
;
off_t
offset
=
totalWritten
;
bytesWritten
=
sendFile
(
fd
,
file
,
offset
,
len
);
#ifdef PISTACHE_USE_SSL
auto
it_
=
peers
.
find
(
fd
);
if
(
it_
==
std
::
end
(
peers
))
throw
std
::
runtime_error
(
"No peer found for fd: "
+
std
::
to_string
(
fd
));
if
(
it_
->
second
->
ssl
()
!=
NULL
)
{
auto
ssl_
=
static_cast
<
SSL
*>
(
it_
->
second
->
ssl
());
bytesWritten
=
SSL_sendfile
(
ssl_
,
file
,
&
offset
,
len
);
}
else
{
#endif
/* PISTACHE_USE_SSL */
bytesWritten
=
::
sendfile
(
fd
,
file
,
&
offset
,
len
);
#ifdef PISTACHE_USE_SSL
}
#endif
/* PISTACHE_USE_SSL */
}
}
if
(
bytesWritten
<
0
)
{
if
(
bytesWritten
<
0
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
...
@@ -309,6 +277,52 @@ void Transport::asyncWriteImpl(Fd fd) {
...
@@ -309,6 +277,52 @@ void Transport::asyncWriteImpl(Fd fd) {
}
}
}
}
ssize_t
Transport
::
sendRawBuffer
(
Fd
fd
,
const
char
*
buffer
,
size_t
len
,
int
flags
)
{
ssize_t
bytesWritten
=
0
;
#ifdef PISTACHE_USE_SSL
auto
it_
=
peers
.
find
(
fd
);
if
(
it_
==
std
::
end
(
peers
))
throw
std
::
runtime_error
(
"No peer found for fd: "
+
std
::
to_string
(
fd
));
if
(
it_
->
second
->
ssl
()
!=
NULL
)
{
auto
ssl_
=
static_cast
<
SSL
*>
(
it_
->
second
->
ssl
());
bytesWritten
=
SSL_write
(
ssl_
,
buffer
,
static_cast
<
int
>
(
len
));
}
else
{
#endif
/* PISTACHE_USE_SSL */
bytesWritten
=
::
send
(
fd
,
buffer
,
len
,
flags
);
#ifdef PISTACHE_USE_SSL
}
#endif
/* PISTACHE_USE_SSL */
return
bytesWritten
;
}
ssize_t
Transport
::
sendFile
(
Fd
fd
,
Fd
file
,
off_t
offset
,
size_t
len
)
{
ssize_t
bytesWritten
=
0
;
#ifdef PISTACHE_USE_SSL
auto
it_
=
peers
.
find
(
fd
);
if
(
it_
==
std
::
end
(
peers
))
throw
std
::
runtime_error
(
"No peer found for fd: "
+
std
::
to_string
(
fd
));
if
(
it_
->
second
->
ssl
()
!=
NULL
)
{
auto
ssl_
=
static_cast
<
SSL
*>
(
it_
->
second
->
ssl
());
bytesWritten
=
SSL_sendfile
(
ssl_
,
file
,
&
offset
,
len
);
}
else
{
#endif
/* PISTACHE_USE_SSL */
bytesWritten
=
::
sendfile
(
fd
,
file
,
&
offset
,
len
);
#ifdef PISTACHE_USE_SSL
}
#endif
/* PISTACHE_USE_SSL */
return
bytesWritten
;
}
void
Transport
::
armTimerMs
(
Fd
fd
,
std
::
chrono
::
milliseconds
value
,
void
Transport
::
armTimerMs
(
Fd
fd
,
std
::
chrono
::
milliseconds
value
,
Async
::
Deferred
<
uint64_t
>
deferred
)
{
Async
::
Deferred
<
uint64_t
>
deferred
)
{
...
...
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