It is used when the share name is not explicitly set.
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
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.
# \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.
// 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
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() {
{
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");
}
cc::AbstractSession& session_;
+ const std::string app_name_;
std::map<std::string, int> fd_share_sockets_;
};
}
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);
}
}
/// \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.
///
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
///
///
/// \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
///
ElementPtr(new ListElement),
ElementPtr(new ListElement))
{
- initSocketRequestor(session);
+ initSocketRequestor(session, "tests");
}
~SocketRequestorTest() {
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) {