listener_ = nullptr;
server_.reset();
+ if (port_path_.empty()) {
+ _W("Delete port path=%s", port_path_.c_str());
+ unlink(port_path_.c_str());
+ }
+
freed_stubs_.insert(this);
}
if (getenv("AUL_APPID") == nullptr) {
std::string name = Aul::GetName(getpid());
if (!name.empty()) {
- std::string endpoint = Aul::GetPortPath(name, GetPortName(), getuid());
- int fd = GetFdFromSystemd(endpoint);
+ port_path_ = Aul::GetPortPath(name, GetPortName(), getuid());
+ int fd = GetFdFromSystemd();
if (fd > -1) return fd;
- fd = CreateServerSocket(endpoint);
+ fd = CreateServerSocket();
if (fd > -1) return fd;
}
}
return fd;
}
-int Stub::GetFdFromSystemd(const std::string& endpoint) {
+int Stub::GetFdFromSystemd() {
int fds = sd_listen_fds(0);
for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fds; ++fd) {
- if (sd_is_socket_unix(fd, SOCK_STREAM, 1, endpoint.c_str(), 0) > 0)
+ if (sd_is_socket_unix(fd, SOCK_STREAM, 1, port_path_.c_str(), 0) > 0)
return fd;
}
return -1;
}
-int Stub::CreateServerSocket(const std::string& endpoint) {
+int Stub::CreateServerSocket() {
try {
ServerSocket socket;
- socket.Bind(endpoint);
+ socket.Bind(port_path_);
socket.Listen(128);
return socket.RemoveFd();
} catch (const Exception& e) {
const std::string& instance, const std::string& port_type, int fd);
void RemoveAcceptedPorts(std::string instance);
std::recursive_mutex& GetMutex() const;
- int GetFdFromSystemd(const std::string& endpoint);
- int CreateServerSocket(const std::string& endpoint);
+ int GetFdFromSystemd();
+ int CreateServerSocket();
private:
std::shared_ptr<AccessController> access_controller_ =
std::make_shared<AccessController>();
std::string port_name_;
+ std::string port_path_;
std::list<std::shared_ptr<AcceptedPort>> ports_;
IEventListener* listener_ = nullptr;
std::unique_ptr<Server> server_;