Skip to content

Commit 8549271

Browse files
committed
Merge 'Internalize reactor::posix_... API methods' from Pavel Emelyanov
There are two of those -- posix_connect() and posix_listen(). Both have nothing to do with reactor and are only called by posix_stack.cc. Despite both just deserve being in posix_stack.cc, they are public methods, and need to be deprecated first, for safety. Closes #3031 * github.com:scylladb/seastar: reactor: Deprecate and internalize posix_connect() reactor: Deprecate and internalize posix_listen()
2 parents aac34fb + 33d591a commit 8549271

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

include/seastar/core/reactor.hh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ void at_destroy(Func&& func);
135135
void at_exit(noncopyable_function<future<> ()> func);
136136
void set_current_task(task* t);
137137

138+
pollable_fd posix_listen(socket_address sa, listen_options opts = {});
139+
future<> posix_connect(pollable_fd pfd, socket_address sa, socket_address local);
140+
138141
}
139142

140143
class io_queue;
@@ -506,15 +509,21 @@ public:
506509
future<connected_socket> connect(socket_address sa);
507510
future<connected_socket> connect(socket_address, socket_address, transport proto = transport::TCP);
508511

509-
pollable_fd posix_listen(socket_address sa, listen_options opts = {});
512+
[[deprecated("Internal reactor function, consider using seastar::listen()")]]
513+
pollable_fd posix_listen(socket_address sa, listen_options opts = {}) {
514+
return internal::posix_listen(sa, opts);
515+
}
510516

511517
// FIXME: reuseport currently leads to heavy load imbalance.
512518
// Until we fix that, just disable it unconditionally.
513519
bool posix_reuseport_available() const { return false; }
514520

515521
pollable_fd make_pollable_fd(socket_address sa, int proto);
516522

517-
future<> posix_connect(pollable_fd pfd, socket_address sa, socket_address local);
523+
[[deprecated("Internal reactor function, consider using seastar::connect)")]]
524+
future<> posix_connect(pollable_fd pfd, socket_address sa, socket_address local) {
525+
return internal::posix_connect(std::move(pfd), sa, local);
526+
}
518527

519528
future<> send_all(pollable_fd_state& fd, const void* buffer, size_t size);
520529

src/core/reactor.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,9 @@ void reactor::configure(const reactor_options& opts) {
15201520
}
15211521
}
15221522

1523-
pollable_fd
1524-
reactor::posix_listen(socket_address sa, listen_options opts) {
1523+
namespace internal {
1524+
1525+
pollable_fd posix_listen(socket_address sa, listen_options opts) {
15251526
auto specific_protocol = (int)(opts.proto);
15261527
if (sa.is_af_unix()) {
15271528
// no type-safe way to create listen_opts with proto=0
@@ -1579,6 +1580,8 @@ reactor::posix_listen(socket_address sa, listen_options opts) {
15791580
return pollable_fd(std::move(fd));
15801581
}
15811582

1583+
} // internel namespace
1584+
15821585
void pollable_fd_state::maybe_no_more_recv() {
15831586
if (shutdown_mask & posix::rcv_shutdown) {
15841587
throw std::system_error(std::error_code(ECONNABORTED, std::system_category()));
@@ -1626,8 +1629,9 @@ reactor::make_pollable_fd(socket_address sa, int proto) {
16261629
return pollable_fd(std::move(fd));
16271630
}
16281631

1629-
future<>
1630-
reactor::posix_connect(pollable_fd pfd, socket_address sa, socket_address local) {
1632+
namespace internal {
1633+
1634+
future<> posix_connect(pollable_fd pfd, socket_address sa, socket_address local) {
16311635
#ifdef IP_BIND_ADDRESS_NO_PORT
16321636
if (!sa.is_af_unix()) {
16331637
try {
@@ -1650,6 +1654,8 @@ reactor::posix_connect(pollable_fd pfd, socket_address sa, socket_address local)
16501654
return pfd.connect(sa).finally([pfd] {});
16511655
}
16521656

1657+
} // internal namespace
1658+
16531659
server_socket
16541660
reactor::listen(socket_address sa, listen_options opt) {
16551661
return server_socket(_network_stack->listen(sa, opt));

src/net/posix-stack.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class posix_socket_impl final : public socket_impl {
429429
_fd.get_file_desc().setsockopt(SOL_SOCKET, SO_REUSEADDR, int(_reuseaddr));
430430
uint16_t port = attempts++ < 5 && requested_port == 0 && proto == transport::TCP ? u(random_engine) * smp::count + this_shard_id() : requested_port;
431431
local.as_posix_sockaddr_in().sin_port = hton(port);
432-
return futurize_invoke([this, sa, local] { return engine().posix_connect(_fd, sa, local); }).then_wrapped([port, requested_port] (future<> f) {
432+
return futurize_invoke([this, sa, local] { return internal::posix_connect(_fd, sa, local); }).then_wrapped([port, requested_port] (future<> f) {
433433
try {
434434
f.get();
435435
return stop_iteration::yes;
@@ -451,7 +451,7 @@ class posix_socket_impl final : public socket_impl {
451451
}
452452

453453
_fd = engine().make_pollable_fd(sa, 0);
454-
return engine().posix_connect(_fd, sa, local).then(
454+
return internal::posix_connect(_fd, sa, local).then(
455455
[fd = _fd, allocator = _allocator](){
456456
// a problem with 'private' interaction with 'unique_ptr'
457457
std::unique_ptr<connected_socket_impl> csi(new posix_connected_socket_impl{AF_UNIX, 0, std::move(fd), allocator});
@@ -705,13 +705,13 @@ posix_network_stack::listen(socket_address sa, listen_options opt) {
705705
sa = inet_address(inet_address::family::INET);
706706
}
707707
if (sa.is_af_unix()) {
708-
return server_socket(std::make_unique<posix_server_socket_impl>(0, sa, engine().posix_listen(sa, opt), opt.lba, opt.fixed_cpu, _allocator));
708+
return server_socket(std::make_unique<posix_server_socket_impl>(0, sa, internal::posix_listen(sa, opt), opt.lba, opt.fixed_cpu, _allocator));
709709
}
710710
auto protocol = static_cast<int>(opt.proto);
711711
return _reuseport ?
712-
server_socket(std::make_unique<posix_reuseport_server_socket_impl>(protocol, sa, engine().posix_listen(sa, opt), _allocator))
712+
server_socket(std::make_unique<posix_reuseport_server_socket_impl>(protocol, sa, internal::posix_listen(sa, opt), _allocator))
713713
:
714-
server_socket(std::make_unique<posix_server_socket_impl>(protocol, sa, engine().posix_listen(sa, opt), opt.lba, opt.fixed_cpu, _allocator));
714+
server_socket(std::make_unique<posix_server_socket_impl>(protocol, sa, internal::posix_listen(sa, opt), opt.lba, opt.fixed_cpu, _allocator));
715715
}
716716

717717
::seastar::socket posix_network_stack::socket() {
@@ -734,7 +734,7 @@ posix_ap_network_stack::listen(socket_address sa, listen_options opt) {
734734
}
735735
auto protocol = static_cast<int>(opt.proto);
736736
return _reuseport ?
737-
server_socket(std::make_unique<posix_reuseport_server_socket_impl>(protocol, sa, engine().posix_listen(sa, opt), _allocator))
737+
server_socket(std::make_unique<posix_reuseport_server_socket_impl>(protocol, sa, internal::posix_listen(sa, opt), _allocator))
738738
:
739739
server_socket(std::make_unique<posix_ap_server_socket_impl>(protocol, sa, _allocator));
740740
}

0 commit comments

Comments
 (0)