Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
c7862b5e
Commit
c7862b5e
authored
Jul 23, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split check_socket_io_res into multiple functions
parent
fc119f23
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
22 deletions
+35
-22
libcaf_net/caf/net/pipe_socket.hpp
libcaf_net/caf/net/pipe_socket.hpp
+6
-0
libcaf_net/caf/net/socket.hpp
libcaf_net/caf/net/socket.hpp
+0
-5
libcaf_net/caf/net/stream_socket.hpp
libcaf_net/caf/net/stream_socket.hpp
+6
-0
libcaf_net/src/pipe_socket.cpp
libcaf_net/src/pipe_socket.cpp
+7
-2
libcaf_net/src/socket.cpp
libcaf_net/src/socket.cpp
+0
-13
libcaf_net/src/stream_socket.cpp
libcaf_net/src/stream_socket.cpp
+16
-2
No files found.
libcaf_net/caf/net/pipe_socket.hpp
View file @
c7862b5e
...
...
@@ -62,5 +62,11 @@ variant<size_t, sec> write(pipe_socket x, const void* buf, size_t buf_size);
/// @relates pipe_socket
variant
<
size_t
,
sec
>
read
(
pipe_socket
x
,
void
*
buf
,
size_t
buf_size
);
/// Converts the result from I/O operation on a ::pipe_socket to either an
/// error code or a non-zero positive integer.
/// @relates pipe_socket
variant
<
size_t
,
sec
>
check_pipe_socket_io_res
(
std
::
make_signed
<
size_t
>::
type
res
);
}
// namespace net
}
// namespace caf
libcaf_net/caf/net/socket.hpp
View file @
c7862b5e
...
...
@@ -68,10 +68,5 @@ error child_process_inherit(socket x, bool new_value);
/// @relates socket
error
nonblocking
(
socket
x
,
bool
new_value
);
/// Converts the result from `recv` or `send` to either an error code or a
/// non-zero positive integer.
/// @relates socket
variant
<
size_t
,
sec
>
check_socket_io_res
(
std
::
make_signed
<
size_t
>::
type
res
);
}
// namespace net
}
// namespace caf
libcaf_net/caf/net/stream_socket.hpp
View file @
c7862b5e
...
...
@@ -71,5 +71,11 @@ variant<size_t, sec> read(stream_socket x, void* buf, size_t buf_size);
/// @post either the result is a `sec` or a positive (non-zero) integer
variant
<
size_t
,
sec
>
write
(
stream_socket
x
,
const
void
*
buf
,
size_t
buf_size
);
/// Converts the result from I/O operation on a ::stream_socket to either an
/// error code or a non-zero positive integer.
/// @relates stream_socket
variant
<
size_t
,
sec
>
check_stream_socket_io_res
(
std
::
make_signed
<
size_t
>::
type
res
);
}
// namespace net
}
// namespace caf
libcaf_net/src/pipe_socket.cpp
View file @
c7862b5e
...
...
@@ -82,15 +82,20 @@ expected<std::pair<pipe_socket, pipe_socket>> make_pipe() {
variant
<
size_t
,
sec
>
write
(
pipe_socket
x
,
const
void
*
buf
,
size_t
buf_size
)
{
auto
res
=
::
write
(
x
.
id
,
buf
,
buf_size
);
return
check_socket_io_res
(
res
);
return
check_
pipe_
socket_io_res
(
res
);
}
variant
<
size_t
,
sec
>
read
(
pipe_socket
x
,
void
*
buf
,
size_t
buf_size
)
{
auto
res
=
::
read
(
x
.
id
,
buf
,
buf_size
);
return
check_socket_io_res
(
res
);
return
check_
pipe_
socket_io_res
(
res
);
}
#endif // CAF_WINDOWS
variant
<
size_t
,
sec
>
check_pipe_socket_io_res
(
std
::
make_signed
<
size_t
>::
type
res
)
{
return
check_stream_socket_io_res
(
res
);
}
}
// namespace net
}
// namespace caf
libcaf_net/src/socket.cpp
View file @
c7862b5e
...
...
@@ -180,18 +180,5 @@ error nonblocking(socket x, bool new_value) {
#endif // CAF_WINDOWS
variant
<
size_t
,
sec
>
check_socket_io_res
(
std
::
make_signed
<
size_t
>::
type
res
)
{
if
(
res
==
0
)
return
sec
::
socket_disconnected
;
if
(
res
<
0
)
{
auto
code
=
last_socket_error
();
if
(
code
==
std
::
errc
::
operation_would_block
||
code
==
std
::
errc
::
resource_unavailable_try_again
)
return
sec
::
unavailable_or_would_block
;
return
sec
::
socket_operation_failed
;
}
return
static_cast
<
size_t
>
(
res
);
}
}
// namespace net
}
// namespace caf
libcaf_net/src/stream_socket.cpp
View file @
c7862b5e
...
...
@@ -164,13 +164,27 @@ error nodelay(stream_socket x, bool new_value) {
variant
<
size_t
,
sec
>
read
(
stream_socket
x
,
void
*
buf
,
size_t
buf_size
)
{
auto
res
=
::
recv
(
x
.
id
,
reinterpret_cast
<
socket_recv_ptr
>
(
buf
),
buf_size
,
no_sigpipe_io_flag
);
return
check_socket_io_res
(
res
);
return
check_s
tream_s
ocket_io_res
(
res
);
}
variant
<
size_t
,
sec
>
write
(
stream_socket
x
,
const
void
*
buf
,
size_t
buf_size
)
{
auto
res
=
::
send
(
x
.
id
,
reinterpret_cast
<
socket_send_ptr
>
(
buf
),
buf_size
,
no_sigpipe_io_flag
);
return
check_socket_io_res
(
res
);
return
check_stream_socket_io_res
(
res
);
}
variant
<
size_t
,
sec
>
check_stream_socket_io_res
(
std
::
make_signed
<
size_t
>::
type
res
)
{
if
(
res
==
0
)
return
sec
::
socket_disconnected
;
if
(
res
<
0
)
{
auto
code
=
last_socket_error
();
if
(
code
==
std
::
errc
::
operation_would_block
||
code
==
std
::
errc
::
resource_unavailable_try_again
)
return
sec
::
unavailable_or_would_block
;
return
sec
::
socket_operation_failed
;
}
return
static_cast
<
size_t
>
(
res
);
}
}
// namespace net
...
...
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