mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-15 06:32:31 +00:00
Add support for SCGI systemd socket activation
Add a new command, `network.scgi.open_systemd`, that binds to a file descriptor passed in via systemd socket activation.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/un.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
@@ -80,6 +81,20 @@ SCgi::open_named(const std::string& filename) {
|
||||
m_path = filename;
|
||||
}
|
||||
|
||||
void
|
||||
SCgi::open_fd(int fd) {
|
||||
torrent::runtime::socket_manager()->open_event_or_throw(this, [&]() {
|
||||
int flags = ::fcntl(fd, F_GETFL, 0);
|
||||
if (flags == -1 || ::fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
|
||||
throw torrent::resource_error("Could not set non-blocking on systemd fd: " +
|
||||
std::string(std::strerror(errno)));
|
||||
set_file_descriptor(fd);
|
||||
// fd is already bound and listening; no bind()/listen() needed.
|
||||
});
|
||||
|
||||
torrent::connection_manager()->inc_socket_count();
|
||||
}
|
||||
|
||||
void
|
||||
SCgi::open(sockaddr* sa, unsigned int length) {
|
||||
try {
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
void open_port(sockaddr* sa, unsigned int length, bool dont_route);
|
||||
void open_named(const std::string& filename);
|
||||
void open_fd(int fd);
|
||||
|
||||
void activate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user