Commit 14742a09 authored by Thomas Markwalder's avatar Thomas Markwalder

[#964,!577] Added socket descriptor parameter to IfaceMgr external callback handler

src/lib/dhcp/iface_mgr.*
    typedef SocketCallback - added socket descriptpor parameter
    Added socket fd to invocations of socket ready callback

src/bin/dhcp4/dhcp4to6_ipc.*
    void Dhcp4to6Ipc::handler(int /* fd */)

src/bin/dhcp6/dhcp6to4_ipc.*
    void Dhcp6to4Ipc::handler(int /* fd */)

     Dhcp6to4Ipc& ipc = Dhcp6to4Ipc::instance();
     Pkt6Ptr pkt;

src/hooks/dhcp/high_availability/ha_service.*
    socketReadyHandler() - initial stub implementation of socket ready handler
parent 00fd7bcd
......@@ -52,7 +52,7 @@ void Dhcp4to6Ipc::open() {
}
}
void Dhcp4to6Ipc::handler() {
void Dhcp4to6Ipc::handler(int /* fd */) {
Dhcp4to6Ipc& ipc = Dhcp4to6Ipc::instance();
Pkt6Ptr pkt;
......
......@@ -47,7 +47,7 @@ public:
///
/// The handler processes the DHCPv4-query DHCPv6 packet and
/// sends the DHCPv4-response DHCPv6 packet back to the DHCPv6 server
static void handler();
static void handler(int /* fd */);
};
} // namespace isc
......
......@@ -54,7 +54,7 @@ void Dhcp6to4Ipc::open() {
}
}
void Dhcp6to4Ipc::handler() {
void Dhcp6to4Ipc::handler(int /* fd */) {
Dhcp6to4Ipc& ipc = Dhcp6to4Ipc::instance();
Pkt6Ptr pkt;
......
......@@ -44,7 +44,7 @@ public:
/// @brief On receive handler
///
/// The handler sends the DHCPv6 packet back to the remote address
static void handler();
static void handler(int /* fd */);
/// @param client_port UDP port where all responses are sent to.
/// Not zero is mostly useful for testing purposes.
......
......@@ -1632,7 +1632,9 @@ HAService::clientConnectHandler(const boost::system::error_code& ec, int tcp_nat
// run by an explicit call IOService ready in kea-dhcp<n> code.
// We are registerin the socket only to interrupt main-thread
// select().
IfaceMgr::instance().addExternalSocket(tcp_native_fd, 0);
IfaceMgr::instance().addExternalSocket(tcp_native_fd,
boost::bind(&HAService::socketReadyHandler, this, _1)
);
}
// If ec.value() == boost::asio::error::already_connected, we should already
......@@ -1642,6 +1644,16 @@ HAService::clientConnectHandler(const boost::system::error_code& ec, int tcp_nat
return (true);
}
void
HAService::socketReadyHandler(int tcp_native_fd) {
std::cout << "HAService::socketReadyHandler - ready socket:" << tcp_native_fd << std::endl;
// If the socket is not usable/or in a transaction
// we'll unregister it
// if (socket bad) /{
// IfaceMgr::instance().deleteExternalSocket(tcp_native_fd, 0);
// }
}
void
HAService::clientCloseHandler(int tcp_native_fd) {
if (tcp_native_fd >= 0) {
......
......@@ -738,6 +738,19 @@ protected:
/// error we want Connection logic to process it.
bool clientConnectHandler(const boost::system::error_code& ec, int tcp_native_fd);
/// @brief IfaceMgr external socket ready callback handler
///
/// IfaceMgr invokes this call back when a registered socket has been
/// flagged as ready to read. It is installed by the invocation to
/// register the socket with IfaceMgr made in @ref clientConnectHandler.
///
/// @todo add logic to determine if the
/// socket is involved in an ongoing transcation or not. If not, it
/// will be unregistered from IfaceMgr.
///
/// @param tcp_native_fd socket descriptor of the ready socket
void socketReadyHandler(int tcp_native_fd);
/// @brief HttpClient close callback handler
///
/// Passed into HttpClient calls to allow unregistration of client's
......
......@@ -1089,7 +1089,7 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec /
// layer access without integrating any specific features
// in IfaceMgr
if (s.callback_) {
s.callback_();
s.callback_(s.socket_);
}
return (Pkt4Ptr());
......@@ -1184,7 +1184,7 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /*
// layer access without integrating any specific features
// in IfaceMgr
if (s.callback_) {
s.callback_();
s.callback_(s.socket_);
}
return (Pkt4Ptr());
......@@ -1313,7 +1313,7 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ )
// layer access without integrating any specific features
// in IfaceMgr
if (s.callback_) {
s.callback_();
s.callback_(s.socket_);
}
return (Pkt6Ptr());
......@@ -1430,7 +1430,7 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
// layer access without integrating any specific features
// in IfaceMgr
if (s.callback_) {
s.callback_();
s.callback_(s.socket_);
}
return (Pkt6Ptr());
......
......@@ -478,7 +478,8 @@ boost::function<void(const std::string& errmsg)> IfaceMgrErrorMsgCallback;
class IfaceMgr : public boost::noncopyable {
public:
/// Defines callback used when data is received over external sockets.
typedef boost::function<void ()> SocketCallback;
/// @param fd socket descriptor of the ready socket
typedef boost::function<void (int fd)> SocketCallback;
/// Keeps callback information for external sockets.
struct SocketCallbackInfo {
......
......@@ -695,14 +695,14 @@ public:
int pipefd[2];
EXPECT_TRUE(pipe(pipefd) == 0);
EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0],
[&callback_ok](){ callback_ok = true; }));
[&callback_ok](int /* fd */){ callback_ok = true; }));
// Let's create a second pipe and register it as well
int secondpipe[2];
EXPECT_TRUE(pipe(secondpipe) == 0);
EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0],
[&callback2_ok](){ callback2_ok = true; }));
[&callback2_ok](int /* fd */){ callback2_ok = true; }));
// Verify a call with no data and normal external sockets works ok.
Pkt4Ptr pkt4;
......@@ -778,14 +778,14 @@ public:
int pipefd[2];
EXPECT_TRUE(pipe(pipefd) == 0);
EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0],
[&callback_ok](){ callback_ok = true; }));
[&callback_ok](int /* fd*/){ callback_ok = true; }));
// Let's create a second pipe and register it as well
int secondpipe[2];
EXPECT_TRUE(pipe(secondpipe) == 0);
EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0],
[&callback2_ok](){ callback2_ok = true; }));
[&callback2_ok](int /*fd */){ callback2_ok = true; }));
// Verify a call with no data and normal external sockets works ok.
Pkt6Ptr pkt6;
......@@ -2749,11 +2749,11 @@ TEST_F(IfaceMgrTest, detectIfaces) {
volatile bool callback_ok;
volatile bool callback2_ok;
void my_callback(void) {
void my_callback(int /* fd */) {
callback_ok = true;
}
void my_callback2(void) {
void my_callback2(int /* fd */) {
callback2_ok = true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment