Skip to content

Commit c25be62

Browse files
committed
feat(local): close POSIX/Windows gaps for local stream sockets
- Add Windows make_local_stream_pair() via temp-listener emulation of socketpair(), enabling socket-pair tests on IOCP - Implement assign_socket() in win_local_stream_service so raw SOCKET handles can be registered with the IOCP port - Replace ConnectEx/AcceptEx with blocking connect()/accept() on worker threads for AF_UNIX — the IOCP extension functions are not reliable for AF_UNIX on all Windows versions - Enable local_stream_socket tests on Windows (construction, open, move, connect/accept, read/write, available, release) - Add portable temp_socket_dir helper using std::filesystem for temp paths across platforms - Guard local datagram code (SOCK_DGRAM) as POSIX-only at compile time — Windows does not support AF_UNIX SOCK_DGRAM - Remove dead IOCP datagram implementation files (win_local_dgram_service.hpp, win_local_dgram_socket.hpp) - Document Windows limitation on local_datagram_socket and local_datagram headers
1 parent f17d881 commit c25be62

18 files changed

Lines changed: 400 additions & 1733 deletions

include/boost/corosio.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@
3535
#include <boost/corosio/local_stream.hpp>
3636
#include <boost/corosio/local_stream_socket.hpp>
3737
#include <boost/corosio/local_stream_acceptor.hpp>
38+
#include <boost/corosio/local_socket_pair.hpp>
39+
40+
// local_datagram.hpp and local_datagram_socket.hpp are POSIX-only;
41+
// Windows does not support AF_UNIX datagram sockets (SOCK_DGRAM).
42+
#include <boost/corosio/detail/platform.hpp>
43+
#if BOOST_COROSIO_POSIX
3844
#include <boost/corosio/local_datagram.hpp>
3945
#include <boost/corosio/local_datagram_socket.hpp>
40-
#include <boost/corosio/local_socket_pair.hpp>
46+
#endif
4147

4248
#include <boost/corosio/tls_context.hpp>
4349
#include <boost/corosio/openssl_stream.hpp>

include/boost/corosio/backend.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ class win_local_stream_socket;
214214
class win_local_stream_service;
215215
class win_local_stream_acceptor;
216216
class win_local_stream_acceptor_service;
217-
class win_local_dgram_socket;
218-
class win_local_dgram_service;
219217

220218
class win_signal;
221219
class win_signals;
@@ -251,8 +249,6 @@ struct iocp_t
251249
using local_stream_service_type = detail::win_local_stream_service;
252250
using local_stream_acceptor_type = detail::win_local_stream_acceptor;
253251
using local_stream_acceptor_service_type = detail::win_local_stream_acceptor_service;
254-
using local_datagram_socket_type = detail::win_local_dgram_socket;
255-
using local_datagram_service_type = detail::win_local_dgram_service;
256252
/// @}
257253

258254
using signal_type = detail::win_signal;

include/boost/corosio/detail/local_datagram_service.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOOST_COROSIO_DETAIL_LOCAL_DATAGRAM_SERVICE_HPP
1212

1313
#include <boost/corosio/detail/config.hpp>
14+
#include <boost/corosio/detail/platform.hpp>
15+
16+
#if BOOST_COROSIO_POSIX
17+
1418
#include <boost/corosio/local_datagram_socket.hpp>
1519
#include <boost/corosio/local_endpoint.hpp>
1620
#include <boost/capy/ex/execution_context.hpp>
@@ -90,4 +94,6 @@ class BOOST_COROSIO_DECL local_datagram_service
9094

9195
} // namespace boost::corosio::detail
9296

97+
#endif // BOOST_COROSIO_POSIX
98+
9399
#endif // BOOST_COROSIO_DETAIL_LOCAL_DATAGRAM_SERVICE_HPP

include/boost/corosio/local_datagram.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#define BOOST_COROSIO_LOCAL_DATAGRAM_HPP
1212

1313
#include <boost/corosio/detail/config.hpp>
14+
#include <boost/corosio/detail/platform.hpp>
15+
16+
#if BOOST_COROSIO_POSIX
1417

1518
namespace boost::corosio {
1619

@@ -25,6 +28,9 @@ class local_datagram_socket;
2528
in the compiled library to avoid exposing platform socket
2629
headers.
2730
31+
@note Not available on Windows. Windows does not support
32+
AF_UNIX datagram sockets (SOCK_DGRAM).
33+
2834
@see local_datagram_socket
2935
*/
3036
class BOOST_COROSIO_DECL local_datagram
@@ -45,4 +51,6 @@ class BOOST_COROSIO_DECL local_datagram
4551

4652
} // namespace boost::corosio
4753

54+
#endif // BOOST_COROSIO_POSIX
55+
4856
#endif // BOOST_COROSIO_LOCAL_DATAGRAM_HPP

include/boost/corosio/local_datagram_socket.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include <boost/corosio/detail/config.hpp>
1414
#include <boost/corosio/detail/platform.hpp>
15+
16+
#if BOOST_COROSIO_POSIX
17+
1518
#include <boost/corosio/detail/except.hpp>
1619
#include <boost/corosio/detail/native_handle.hpp>
1720
#include <boost/corosio/detail/op_base.hpp>
@@ -56,6 +59,10 @@ namespace boost::corosio {
5659
kernel filters incoming datagrams to those from the
5760
connected peer.
5861
62+
@note Not available on Windows. Windows does not support
63+
AF_UNIX datagram sockets (SOCK_DGRAM). Attempting to
64+
open this socket on Windows will fail.
65+
5966
@par Cancellation
6067
All asynchronous operations support cancellation through
6168
`std::stop_token` via the affine protocol, or explicitly
@@ -871,4 +878,6 @@ class BOOST_COROSIO_DECL local_datagram_socket : public io_object
871878

872879
} // namespace boost::corosio
873880

881+
#endif // BOOST_COROSIO_POSIX
882+
874883
#endif // BOOST_COROSIO_LOCAL_DATAGRAM_SOCKET_HPP

include/boost/corosio/local_socket_pair.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
#include <boost/corosio/detail/config.hpp>
1414
#include <boost/corosio/detail/platform.hpp>
15+
#include <boost/corosio/local_stream_socket.hpp>
1516

1617
#if BOOST_COROSIO_POSIX
17-
18-
#include <boost/corosio/local_stream_socket.hpp>
1918
#include <boost/corosio/local_datagram_socket.hpp>
19+
#endif
2020

2121
#include <utility>
2222

@@ -26,9 +26,10 @@ class io_context;
2626

2727
/** Create a connected pair of local stream sockets.
2828
29-
Uses socketpair(AF_UNIX, SOCK_STREAM) to create two
30-
pre-connected sockets. Data written to one can be read
31-
from the other.
29+
On POSIX, uses socketpair(AF_UNIX, SOCK_STREAM). On Windows,
30+
emulates socketpair by creating a temporary listener, connecting,
31+
and accepting. Data written to one socket can be read from the
32+
other.
3233
3334
@param ctx The I/O context for the sockets.
3435
@@ -39,11 +40,15 @@ class io_context;
3940
BOOST_COROSIO_DECL std::pair<local_stream_socket, local_stream_socket>
4041
make_local_stream_pair(io_context& ctx);
4142

43+
#if BOOST_COROSIO_POSIX
4244
/** Create a connected pair of local datagram sockets.
4345
4446
Uses socketpair(AF_UNIX, SOCK_DGRAM) to create two
4547
pre-connected sockets.
4648
49+
@note Not available on Windows. Windows does not support
50+
AF_UNIX datagram sockets.
51+
4752
@param ctx The I/O context for the sockets.
4853
4954
@return A pair of connected local datagram sockets.
@@ -52,9 +57,8 @@ make_local_stream_pair(io_context& ctx);
5257
*/
5358
BOOST_COROSIO_DECL std::pair<local_datagram_socket, local_datagram_socket>
5459
make_local_datagram_pair(io_context& ctx);
60+
#endif
5561

5662
} // namespace boost::corosio
5763

58-
#endif // BOOST_COROSIO_POSIX
59-
6064
#endif // BOOST_COROSIO_LOCAL_SOCKET_PAIR_HPP

0 commit comments

Comments
 (0)