Remove accept_result
This commit is contained in:
4
httpd.cc
4
httpd.cc
@@ -31,9 +31,7 @@ public:
|
||||
do_accepts(_listeners.size() - 1);
|
||||
}
|
||||
void do_accepts(int which) {
|
||||
_listeners[which].accept().then([this, which] (accept_result&& ar) mutable {
|
||||
auto fd = std::move(std::get<0>(ar));
|
||||
auto addr = std::get<1>(ar);
|
||||
_listeners[which].accept().then([this, which] (pollable_fd fd, socket_address addr) mutable {
|
||||
(new connection(*this, std::move(fd), addr))->read();
|
||||
do_accepts(which);
|
||||
});
|
||||
|
||||
14
reactor.hh
14
reactor.hh
@@ -275,8 +275,6 @@ future<T...> make_ready_future(T&&... value) {
|
||||
return future<T...>(s);
|
||||
}
|
||||
|
||||
using accept_result = std::tuple<pollable_fd, socket_address>;
|
||||
|
||||
struct listen_options {
|
||||
bool reuse_address = false;
|
||||
};
|
||||
@@ -301,7 +299,7 @@ public:
|
||||
|
||||
pollable_fd listen(socket_address sa, listen_options opts = {});
|
||||
|
||||
future<accept_result> accept(pollable_fd_state& listen_fd);
|
||||
future<pollable_fd, socket_address> accept(pollable_fd_state& listen_fd);
|
||||
|
||||
future<size_t> read_some(pollable_fd_state& fd, void* buffer, size_t size);
|
||||
future<size_t> read_some(pollable_fd_state& fd, const std::vector<iovec>& iov);
|
||||
@@ -359,7 +357,7 @@ public:
|
||||
future<size_t> read_some(const std::vector<iovec>& iov) { return the_reactor.read_some(*_s, iov); }
|
||||
future<size_t> write_all(const char* buffer, size_t size) { return the_reactor.write_all(*_s, buffer, size); }
|
||||
future<size_t> write_all(const uint8_t* buffer, size_t size) { return the_reactor.write_all(*_s, buffer, size); }
|
||||
future<accept_result> accept() { return the_reactor.accept(*_s); }
|
||||
future<pollable_fd, socket_address> accept() { return the_reactor.accept(*_s); }
|
||||
friend class reactor;
|
||||
};
|
||||
|
||||
@@ -475,16 +473,16 @@ size_t iovec_len(const std::vector<iovec>& iov)
|
||||
}
|
||||
|
||||
inline
|
||||
future<accept_result>
|
||||
future<pollable_fd, socket_address>
|
||||
reactor::accept(pollable_fd_state& listenfd) {
|
||||
promise<accept_result> pr;
|
||||
future<accept_result> fut = pr.get_future();
|
||||
promise<pollable_fd, socket_address> pr;
|
||||
future<pollable_fd, socket_address> fut = pr.get_future();
|
||||
readable(listenfd).then([this, pr = std::move(pr), lfd = listenfd.fd] () mutable {
|
||||
socket_address sa;
|
||||
socklen_t sl = sizeof(&sa.u.sas);
|
||||
int fd = ::accept4(lfd, &sa.u.sa, &sl, SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||
assert(fd != -1);
|
||||
pr.set_value(accept_result{pollable_fd(fd, pollable_fd::speculation(EPOLLOUT)), sa});
|
||||
pr.set_value(pollable_fd(fd, pollable_fd::speculation(EPOLLOUT)), sa);
|
||||
});
|
||||
return fut;
|
||||
}
|
||||
|
||||
@@ -29,13 +29,13 @@ struct test {
|
||||
});
|
||||
}
|
||||
};
|
||||
void new_connection(accept_result&& accepted) {
|
||||
auto c = new connection(std::move(std::get<0>(accepted)));
|
||||
void new_connection(pollable_fd fd, socket_address sa) {
|
||||
auto c = new connection(std::move(fd));
|
||||
c->copy_data();
|
||||
}
|
||||
void start_accept() {
|
||||
listener.accept().then([this] (accept_result&& ar) {
|
||||
new_connection(std::move(ar));
|
||||
listener.accept().then([this] (pollable_fd fd, socket_address sa) {
|
||||
new_connection(std::move(fd), std::move(sa));
|
||||
start_accept();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user