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
7d72cacd
Commit
7d72cacd
authored
Nov 08, 2018
by
knowledge4igor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve error handling on accept call
parent
a7ed13fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
include/pistache/errors.h
include/pistache/errors.h
+23
-0
src/server/listener.cc
src/server/listener.cc
+17
-3
No files found.
include/pistache/errors.h
0 → 100644
View file @
7d72cacd
#pragma once
#include <stdexcept>
namespace
Pistache
{
namespace
Tcp
{
class
SocketError
:
public
std
::
runtime_error
{
public:
explicit
SocketError
(
const
char
*
what_arg
)
:
std
::
runtime_error
(
what_arg
)
{
}
};
class
ServerError
:
public
std
::
runtime_error
{
public:
explicit
ServerError
(
const
char
*
what_arg
)
:
std
::
runtime_error
(
what_arg
)
{
}
};
}
// Tcp
}
// Pistache
\ No newline at end of file
src/server/listener.cc
View file @
7d72cacd
...
...
@@ -8,6 +8,7 @@
#include <pistache/common.h>
#include <pistache/os.h>
#include <pistache/transport.h>
#include <pistache/errors.h>
#include <sys/socket.h>
#include <netinet/in.h>
...
...
@@ -225,8 +226,18 @@ Listener::run() {
else
{
if
(
event
.
flags
.
hasFlag
(
Polling
::
NotifyOn
::
Read
))
{
auto
fd
=
event
.
tag
.
value
();
if
(
static_cast
<
ssize_t
>
(
fd
)
==
listen_fd
)
handleNewConnection
();
if
(
static_cast
<
ssize_t
>
(
fd
)
==
listen_fd
)
{
try
{
handleNewConnection
();
}
catch
(
SocketError
&
ex
)
{
std
::
cerr
<<
"Server: "
<<
ex
.
what
()
<<
std
::
endl
;
}
catch
(
ServerError
&
ex
)
{
std
::
cerr
<<
"Server: "
<<
ex
.
what
()
<<
std
::
endl
;
throw
;
}
}
}
}
}
...
...
@@ -313,7 +324,10 @@ Listener::handleNewConnection() {
socklen_t
peer_addr_len
=
sizeof
(
peer_addr
);
int
client_fd
=
::
accept
(
listen_fd
,
(
struct
sockaddr
*
)
&
peer_addr
,
&
peer_addr_len
);
if
(
client_fd
<
0
)
{
throw
std
::
runtime_error
(
strerror
(
errno
));
if
(
errno
==
EBADF
||
errno
==
ENOTSOCK
)
throw
ServerError
(
strerror
(
errno
));
else
throw
SocketError
(
strerror
(
errno
));
}
make_non_blocking
(
client_fd
);
...
...
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