.arg(id_);
}
// New entry.
- SocketCallbackInfo x;
- x.socket_ = socketfd;
+ SocketCallbackInfo x(socketfd);
x.callback_ = callback;
std::lock_guard<std::mutex> lock(callbacks_mutex_);
auto& idx = callbacks_.get<1>();
}
// Let's find out which external socket has the data
- SocketCallbackInfo ex_sock;
+ boost::scoped_ptr<SocketCallbackInfo> ex_sock;
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = *it;
+ ex_sock.reset(new SocketCallbackInfo(*it));
break;
}
}
}
}
- if (ex_sock.callback_) {
+ if (ex_sock && ex_sock->callback_) {
// Calling the external socket's callback provides its service
// layer access without integrating any specific features
// in IfaceMgr
- ex_sock.callback_(ex_sock.socket_);
+ ex_sock->callback_(ex_sock->socket_);
}
if (found) {
return (Pkt4Ptr());
}
// Let's find out which socket has the data
- SocketCallbackInfo ex_sock;
+ boost::scoped_ptr<SocketCallbackInfo> ex_sock;
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = *it;
+ ex_sock.reset(new SocketCallbackInfo(*it));
break;
}
}
}
}
- if (ex_sock.callback_) {
+ if (ex_sock && ex_sock->callback_) {
// Calling the external socket's callback provides its service
// layer access without integrating any specific features
// in IfaceMgr
- ex_sock.callback_(ex_sock.socket_);
+ ex_sock->callback_(ex_sock->socket_);
}
if (found) {
return (Pkt4Ptr());
}
// Let's find out which socket has the data
- SocketCallbackInfo ex_sock;
+ boost::scoped_ptr<SocketCallbackInfo> ex_sock;
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = *it;
+ ex_sock.reset(new SocketCallbackInfo(*it));
break;
}
}
}
}
- if (ex_sock.callback_) {
+ if (ex_sock && ex_sock->callback_) {
// Calling the external socket's callback provides its service
// layer access without integrating any specific features
// in IfaceMgr
- ex_sock.callback_(ex_sock.socket_);
+ ex_sock->callback_(ex_sock->socket_);
}
if (found) {
return (Pkt6Ptr());
}
// Let's find out which external socket has the data
- SocketCallbackInfo ex_sock;
+ boost::scoped_ptr<SocketCallbackInfo> ex_sock;
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = *it;
+ ex_sock.reset(new SocketCallbackInfo(*it));
break;
}
}
}
}
- if (ex_sock.callback_) {
+ if (ex_sock && ex_sock->callback_) {
// Calling the external socket's callback provides its service
// layer access without integrating any specific features
// in IfaceMgr
- ex_sock.callback_(ex_sock.socket_);
+ ex_sock->callback_(ex_sock->socket_);
}
if (found) {
return (Pkt6Ptr());
bool unusable_;
/// @brief Constructor.
- SocketCallbackInfo() : socket_(-1), unusable_(false) {
+ ///
+ /// @param socket The socket descriptor.
+ SocketCallbackInfo(int socket)
+ : socket_(socket), callback_(0), unusable_(false) {
}
};
/// @brief Handle closed external socket.
///
+ /// @note: the caller must take the lock when it generates
+ /// the argument and calls this method.
+ ///
/// @param it The external socket info iterator.
void handleClosedExternalSocket(SocketCallbackInfoIterator it);
return (seq.str());
};
for (int i = 0; i < 9; ++i) {
- IfaceMgr::SocketCallbackInfo s;
- s.socket_ = i;
+ IfaceMgr::SocketCallbackInfo s(i);
callbacks.push_back(s);
}
EXPECT_EQ("0\n1\n2\n3\n4\n5\n6\n7\n8\n", getSequence());
auto& idx = callbacks.get<1>();
auto it = idx.find(5);
ASSERT_NE(it, idx.end());
- IfaceMgr::SocketCallbackInfo x;
- x.socket_ = 9;
+ IfaceMgr::SocketCallbackInfo x(9);
EXPECT_TRUE(idx.replace(it, x));
EXPECT_EQ("0\n1\n2\n3\n4\n9\n6\n7\n8\n", getSequence());
}