// abstract Connection, for keeping per-connection state
class Messenger;
+
+#ifdef UNIT_TESTS_BUILT
class Interceptor;
+#endif
struct Connection : public RefCountedObject {
mutable Mutex lock;
EntityName peer_name;
uint64_t peer_global_id = 0;
+#ifdef UNIT_TESTS_BUILT
Interceptor *interceptor;
+#endif
friend class boost::intrusive_ptr<Connection>;
friend class PipeConnection;
class AuthClient;
class AuthServer;
+#ifdef UNIT_TESTS_BUILT
+
struct Interceptor {
std::mutex lock;
std::condition_variable cond_var;
virtual ACTION intercept(Connection *conn, uint32_t step) = 0;
};
+#endif
+
class Messenger {
private:
std::deque<Dispatcher*> dispatchers;
public:
AuthClient *auth_client = 0;
AuthServer *auth_server = 0;
+
+#ifdef UNIT_TESTS_BUILT
Interceptor *interceptor = nullptr;
+#endif
/**
* Various Messenger conditional config/type flags to allow
msgr2(m2), state_offset(0),
worker(w), center(&w->center),read_buffer(nullptr)
{
+#ifdef UNIT_TESTS_BUILT
this->interceptor = m->interceptor;
+#endif
read_handler = new C_handle_read(this);
write_handler = new C_handle_write(this);
write_callback_handler = new C_handle_write_callback(this);
#define READB(L, B, C) read(CONTINUATION(C), L, B)
+#ifdef UNIT_TESTS_BUILT
+
#define INTERCEPT(S) { \
if(connection->interceptor) { \
auto a = connection->interceptor->intercept(connection, (S)); \
connection->dispatch_queue->queue_reset(connection); \
return nullptr; \
}}}
+
+#else
+#define INTERCEPT(S)
+#endif
static void alloc_aligned_buffer(bufferlist &data, unsigned len, unsigned off) {
// create a buffer to read into that matches the data alignment