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
5cc4fcee
Commit
5cc4fcee
authored
Jul 11, 2018
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing includes and function to close sockets
parent
80d1dd81
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
22 deletions
+42
-22
libcaf_io/caf/io/network/native_socket.hpp
libcaf_io/caf/io/network/native_socket.hpp
+4
-2
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+3
-3
libcaf_io/src/event_handler.cpp
libcaf_io/src/event_handler.cpp
+1
-1
libcaf_io/src/native_socket.cpp
libcaf_io/src/native_socket.cpp
+28
-14
libcaf_io/src/socket_guard.cpp
libcaf_io/src/socket_guard.cpp
+6
-2
No files found.
libcaf_io/caf/io/network/native_socket.hpp
View file @
5cc4fcee
...
...
@@ -34,14 +34,13 @@ namespace network {
using
getsockopt_ptr
=
char
*
;
using
socket_send_ptr
=
const
char
*
;
using
socket_recv_ptr
=
char
*
;
//
using socket_size_type = int;
using
socket_size_type
=
int
;
#else
using
setsockopt_ptr
=
const
void
*
;
using
getsockopt_ptr
=
void
*
;
using
socket_send_ptr
=
const
void
*
;
using
socket_recv_ptr
=
void
*
;
using
socket_size_type
=
unsigned
;
void
closesocket
(
int
fd
);
#endif
using
signed_size_type
=
std
::
make_signed
<
size_t
>::
type
;
...
...
@@ -69,6 +68,9 @@ extern const int no_sigpipe_io_flag;
/// Returns the last socket error as an integer.
int
last_socket_error
();
/// Close socket `fd`.
void
close_socket
(
native_socket
fd
);
/// Returns true if `errcode` indicates that an operation would
/// block or return nothing at the moment and can be tried again
/// at a later point.
...
...
libcaf_io/src/default_multiplexer.cpp
View file @
5cc4fcee
...
...
@@ -628,9 +628,9 @@ void default_multiplexer::resume(intrusive_ptr<resumable> ptr) {
default_multiplexer
::~
default_multiplexer
()
{
if
(
epollfd_
!=
invalid_native_socket
)
closesocket
(
epollfd_
);
close
_
socket
(
epollfd_
);
// close write handle first
closesocket
(
pipe_
.
second
);
close
_
socket
(
pipe_
.
second
);
// flush pipe before closing it
nonblocking
(
pipe_
.
first
,
true
);
auto
ptr
=
pipe_reader_
.
try_read_next
();
...
...
@@ -639,7 +639,7 @@ default_multiplexer::~default_multiplexer() {
ptr
=
pipe_reader_
.
try_read_next
();
}
// do cleanup for pipe reader manually, since WSACleanup needs to happen last
closesocket
(
pipe_reader_
.
fd
());
close
_
socket
(
pipe_reader_
.
fd
());
pipe_reader_
.
init
(
invalid_native_socket
);
# ifdef CAF_WINDOWS
WSACleanup
();
...
...
libcaf_io/src/event_handler.cpp
View file @
5cc4fcee
...
...
@@ -43,7 +43,7 @@ event_handler::event_handler(default_multiplexer& dm, native_socket sockfd)
event_handler
::~
event_handler
()
{
if
(
fd_
!=
invalid_native_socket
)
{
CAF_LOG_DEBUG
(
"close socket"
<<
CAF_ARG
(
fd_
));
closesocket
(
fd_
);
close
_
socket
(
fd_
);
}
}
...
...
libcaf_io/src/native_socket.cpp
View file @
5cc4fcee
...
...
@@ -85,23 +85,13 @@ namespace io {
namespace
network
{
#ifdef CAF_WINDOWS
int
last_socket_error
()
{
return
WSAGetLastError
();
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
WSAEWOULDBLOCK
||
errcode
==
WSATRY_AGAIN
;
}
const
int
ec_out_of_memory
=
WSAENOBUFS
;
const
int
ec_interrupted_syscall
=
WSAEINTR
;
#else
void
closesocket
(
int
fd
)
{
close
(
fd
);
}
int
last_socket_error
()
{
return
errno
;
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
EAGAIN
||
errcode
==
EWOULDBLOCK
;
}
const
int
ec_out_of_memory
=
ENOMEM
;
const
int
ec_interrupted_syscall
=
EINTR
;
#endif
// platform-dependent SIGPIPE setup
#if defined(CAF_MACOS) || defined(CAF_IOS) || defined(CAF_BSD)
// Use the socket option but no flags to recv/send on macOS/iOS/BSD.
...
...
@@ -119,6 +109,18 @@ namespace network {
#ifndef CAF_WINDOWS
int
last_socket_error
()
{
return
errno
;
}
void
close_socket
(
native_socket
fd
)
{
close
(
fd
);
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
EAGAIN
||
errcode
==
EWOULDBLOCK
;
}
string
last_socket_error_as_string
()
{
return
strerror
(
errno
);
}
...
...
@@ -159,6 +161,18 @@ namespace network {
#else // CAF_WINDOWS
int
last_socket_error
()
{
return
WSAGetLastError
();
}
void
close_socket
(
native_socket
fd
)
{
closesocket
(
fd
);
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
WSAEWOULDBLOCK
||
errcode
==
WSATRY_AGAIN
;
}
string
last_socket_error_as_string
()
{
LPTSTR
errorText
=
NULL
;
auto
hresult
=
last_socket_error
();
...
...
@@ -250,9 +264,9 @@ namespace network {
// makes sure all sockets are closed in case of an error
auto
guard
=
detail
::
make_scope_guard
([
&
]
{
auto
e
=
WSAGetLastError
();
closesocket
(
listener
);
closesocket
(
socks
[
0
]);
closesocket
(
socks
[
1
]);
close
_
socket
(
listener
);
close
_
socket
(
socks
[
0
]);
close
_
socket
(
socks
[
1
]);
WSASetLastError
(
e
);
});
// bind listener to a local port
...
...
@@ -283,7 +297,7 @@ namespace network {
// get write-only end of the pipe
CALL_CRITICAL_CFUN
(
write_fd
,
detail
::
cc_valid_socket
,
"accept"
,
accept
(
listener
,
nullptr
,
nullptr
));
closesocket
(
listener
);
close
_
socket
(
listener
);
guard
.
disable
();
return
std
::
make_pair
(
read_fd
,
write_fd
);
}
...
...
libcaf_io/src/socket_guard.cpp
View file @
5cc4fcee
...
...
@@ -18,7 +18,11 @@
#include "caf/detail/socket_guard.hpp"
#include <unistd.h>
#ifdef CAF_WINDOWS
# include <winsock2.h>
#else
# include <unistd.h>
#endif
#include "caf/logger.hpp"
...
...
@@ -42,7 +46,7 @@ io::network::native_socket socket_guard::release() {
void
socket_guard
::
close
()
{
if
(
fd_
!=
io
::
network
::
invalid_native_socket
)
{
CAF_LOG_DEBUG
(
"close socket"
<<
CAF_ARG
(
fd_
));
io
::
network
::
closesocket
(
fd_
);
io
::
network
::
close
_
socket
(
fd_
);
fd_
=
io
::
network
::
invalid_native_socket
;
}
}
...
...
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