From: Michal 'vorner' Vaner Date: Thu, 2 Feb 2012 12:19:15 +0000 (+0100) Subject: [1595] Application name for the socket requestor X-Git-Tag: trac2351_base~264^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bbda62a5e88e9f1e4c8aeb7924308e37ef65a7c;p=thirdparty%2Fkea.git [1595] Application name for the socket requestor It is used when the share name is not explicitly set. --- diff --git a/src/bin/auth/main.cc b/src/bin/auth/main.cc index 4a425e52d2..a980db9f29 100644 --- a/src/bin/auth/main.cc +++ b/src/bin/auth/main.cc @@ -154,7 +154,7 @@ main(int argc, char* argv[]) { cc_session = new Session(io_service.get_io_service()); LOG_DEBUG(auth_logger, DBG_AUTH_START, AUTH_CONFIG_CHANNEL_CREATED); // Initialize the Socket Requestor - isc::server_common::initSocketRequestor(*cc_session); + isc::server_common::initSocketRequestor(*cc_session, "auth"); // We delay starting listening to new commands/config just before we // go into the main loop to avoid confusion due to mixture of diff --git a/src/bin/resolver/main.cc b/src/bin/resolver/main.cc index bfcad6790a..c9c7e238c5 100644 --- a/src/bin/resolver/main.cc +++ b/src/bin/resolver/main.cc @@ -202,7 +202,7 @@ main(int argc, char* argv[]) { LOG_DEBUG(resolver_logger, RESOLVER_DBG_INIT, RESOLVER_SERVICE_CREATED); cc_session = new Session(io_service.get_io_service()); - isc::server_common::initSocketRequestor(*cc_session); + isc::server_common::initSocketRequestor(*cc_session, "resolver"); // We delay starting listening to new commands/config just before we // go into the main loop. See auth/main.cc for the rationale. diff --git a/src/lib/server_common/server_common_messages.mes b/src/lib/server_common/server_common_messages.mes index 3b3090d852..08179281bf 100644 --- a/src/lib/server_common/server_common_messages.mes +++ b/src/lib/server_common/server_common_messages.mes @@ -16,7 +16,7 @@ $NAMESPACE isc::server_common # \brief Messages for the server_common library -% SOCKETREQUESTOR_CREATED Socket requestor created +% SOCKETREQUESTOR_CREATED Socket requestor created for application %1 Debug message. A socket requesor (client of the socket creator) is created for the corresponding application. Normally this should happen at most one time throughout the lifetime of the application. diff --git a/src/lib/server_common/socket_request.cc b/src/lib/server_common/socket_request.cc index 546de05571..48412bb341 100644 --- a/src/lib/server_common/socket_request.cc +++ b/src/lib/server_common/socket_request.cc @@ -264,8 +264,10 @@ getSocketFd(const std::string& token, int sock_pass_fd) { // be closed during the lifetime of this class class SocketRequestorCCSession : public SocketRequestor { public: - explicit SocketRequestorCCSession(cc::AbstractSession& session) : - session_(session) + explicit SocketRequestorCCSession(cc::AbstractSession& session, + const std::string& app_name) : + session_(session), + app_name_(app_name) { // We need to filter SIGPIPE to prevent it from happening in // getSocketFd() while writing to the UNIX domain socket after the @@ -278,7 +280,8 @@ public: isc_throw(Unexpected, "Failed to filter SIGPIPE: " << strerror(errno)); } - LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED); + LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED). + arg(app_name); } ~SocketRequestorCCSession() { @@ -293,7 +296,9 @@ public: { const isc::data::ConstElementPtr request_msg = createRequestSocketMessage(protocol, address, port, - share_mode, share_name); + share_mode, + share_name.empty() ? app_name_ : + share_name); // Send it to boss const int seq = session_.group_sendmsg(request_msg, "Boss"); @@ -377,6 +382,7 @@ private: } cc::AbstractSession& session_; + const std::string app_name_; std::map fd_share_sockets_; }; @@ -392,12 +398,14 @@ socketRequestor() { } void -initSocketRequestor(cc::AbstractSession& session) { +initSocketRequestor(cc::AbstractSession& session, + const std::string& app_name) +{ if (requestor != NULL) { isc_throw(InvalidOperation, "The socket requestor was already initialized"); } else { - requestor = new SocketRequestorCCSession(session); + requestor = new SocketRequestorCCSession(session, app_name); } } diff --git a/src/lib/server_common/socket_request.h b/src/lib/server_common/socket_request.h index 5708cc1a34..9182ae5ad7 100644 --- a/src/lib/server_common/socket_request.h +++ b/src/lib/server_common/socket_request.h @@ -163,7 +163,8 @@ public: /// \param share_mode how the socket can be shared with other requests. /// This must be one of the defined values of ShareMode. /// \param share_name the name of sharing group, relevant for SHARE_SAME - /// (specified by us or someone else). + /// (specified by us or someone else). If left empty (the default), + /// the app_name parameter of initSocketRequestor is used. /// \return the socket, as a file descriptor and token representing it on /// the socket creator side. /// @@ -180,7 +181,7 @@ public: virtual SocketID requestSocket(Protocol protocol, const std::string& address, uint16_t port, ShareMode share_mode, - const std::string& share_name) = 0; + const std::string& share_name = "") = 0; /// \brief Tell the socket creator we no longer need the socket /// @@ -215,8 +216,11 @@ SocketRequestor& socketRequestor(); /// /// \param session the CC session that'll be used to talk to the /// socket creator. +/// \param app_name default share name if one is not provided with +/// requestSocket /// \throw InvalidOperation when it is called more than once -void initSocketRequestor(cc::AbstractSession& session); +void initSocketRequestor(cc::AbstractSession& session, + const std::string& app_name); /// \brief Initialization for tests /// diff --git a/src/lib/server_common/tests/socket_requestor_test.cc b/src/lib/server_common/tests/socket_requestor_test.cc index e917e0cb4c..28048ae2f9 100644 --- a/src/lib/server_common/tests/socket_requestor_test.cc +++ b/src/lib/server_common/tests/socket_requestor_test.cc @@ -83,7 +83,7 @@ public: ElementPtr(new ListElement), ElementPtr(new ListElement)) { - initSocketRequestor(session); + initSocketRequestor(session, "tests"); } ~SocketRequestorTest() { @@ -187,6 +187,17 @@ TEST_F(SocketRequestorTest, testSocketRequestMessages) { CCSessionError); ASSERT_EQ(1, session.getMsgQueue()->size()); ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0))); + + // A default share name equal to the app name passed on construction + clearMsgQueue(); + expected_request = createExpectedRequest("::1", 2, "UDP", + "SAMEAPP", "tests"); + ASSERT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP, + "::1", 2, + SocketRequestor::SHARE_SAME), + CCSessionError); + ASSERT_EQ(1, session.getMsgQueue()->size()); + ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0))); } TEST_F(SocketRequestorTest, invalidParameterForSocketRequest) {