Add getListeners() method to the HttpAppFramework class (#559)
This commit is contained in:
parent
3a00ffde47
commit
e032f9bd0e
|
@ -345,6 +345,14 @@ int main()
|
|||
auto resp = HttpResponse::newFileResponse("index.html");
|
||||
resp->setExpiredTime(0);
|
||||
app().setCustom404Page(resp);
|
||||
app().addListener("0.0.0.0", 0);
|
||||
app().registerBeginningAdvice([]() {
|
||||
auto addresses = app().getListeners();
|
||||
for (auto &address : addresses)
|
||||
{
|
||||
LOG_INFO << address.toIpPort() << " LISTEN";
|
||||
}
|
||||
});
|
||||
std::cout << "Date: "
|
||||
<< std::string{drogon::utils::getHttpFullDate(
|
||||
trantor::Date::now())}
|
||||
|
|
|
@ -1143,6 +1143,15 @@ class HttpAppFramework : public trantor::NonCopyable
|
|||
*/
|
||||
virtual size_t getCurrentThreadIndex() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the addresses of listeners.
|
||||
*
|
||||
* @return std::vector<trantor::InetAddress>
|
||||
* @note This method should be called after calling the app().run(). One
|
||||
* could run this method in an AOP join point (such as the BeginningAdvice).
|
||||
*/
|
||||
virtual std::vector<trantor::InetAddress> getListeners() const = 0;
|
||||
|
||||
private:
|
||||
virtual void registerHttpController(
|
||||
const std::string &pathPattern,
|
||||
|
|
|
@ -995,3 +995,8 @@ const std::function<HttpResponsePtr(HttpStatusCode)>
|
|||
{
|
||||
return customErrorHandler_;
|
||||
}
|
||||
|
||||
std::vector<trantor::InetAddress> HttpAppFrameworkImpl::getListeners() const
|
||||
{
|
||||
return listenerManagerPtr_->getListeners();
|
||||
}
|
|
@ -441,7 +441,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
|||
const std::string &name = "default",
|
||||
const bool isFast = false,
|
||||
const std::string &characterSet = "") override;
|
||||
|
||||
virtual std::vector<trantor::InetAddress> getListeners() const override;
|
||||
inline static HttpAppFrameworkImpl &instance()
|
||||
{
|
||||
static HttpAppFrameworkImpl instance;
|
||||
|
|
|
@ -82,6 +82,11 @@ class HttpServer : trantor::NonCopyable
|
|||
server_.enableSSL(certPath, keyPath);
|
||||
}
|
||||
|
||||
const trantor::InetAddress &address() const
|
||||
{
|
||||
return server_.address();
|
||||
}
|
||||
|
||||
private:
|
||||
void onConnection(const trantor::TcpConnectionPtr &conn);
|
||||
void onMessage(const trantor::TcpConnectionPtr &, trantor::MsgBuffer *);
|
||||
|
|
|
@ -260,3 +260,13 @@ void ListenerManager::stopListening()
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<trantor::InetAddress> ListenerManager::getListeners() const
|
||||
{
|
||||
std::vector<trantor::InetAddress> listeners;
|
||||
for (auto &server : servers_)
|
||||
{
|
||||
listeners.emplace_back(server->address());
|
||||
}
|
||||
return listeners;
|
||||
}
|
|
@ -21,7 +21,10 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace trantor
|
||||
{
|
||||
class InetAddress;
|
||||
}
|
||||
namespace drogon
|
||||
{
|
||||
class ListenerManager : public trantor::NonCopyable
|
||||
|
@ -44,6 +47,7 @@ class ListenerManager : public trantor::NonCopyable
|
|||
std::function<HttpResponsePtr(const HttpRequestPtr &)>>
|
||||
&syncAdvices);
|
||||
void startListening();
|
||||
std::vector<trantor::InetAddress> getListeners() const;
|
||||
~ListenerManager();
|
||||
|
||||
trantor::EventLoop *getIOLoop(size_t id) const;
|
||||
|
|
2
trantor
2
trantor
|
@ -1 +1 @@
|
|||
Subproject commit cdf853aca05261273bf271bf6fe6011245e75e13
|
||||
Subproject commit 8ca21f124d4d6b75fded94d28b69d1448c286cbd
|
Loading…
Reference in New Issue