summaryrefslogtreecommitdiffstats
path: root/src/test/messenger/simple_dispatcher.cc
blob: b13958d36864bb2292fbaf13fa9c9aec05159ecd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2013 CohortFS, LLC
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#include "include/compat.h"

#include "simple_dispatcher.h"
#include "messages/MPing.h"
#include "messages/MDataPing.h"

SimpleDispatcher::SimpleDispatcher(Messenger *msgr) :
  Dispatcher(msgr->cct),
  active(false),
  messenger(msgr),
  dcount(0)
{
  // nothing
}

SimpleDispatcher::~SimpleDispatcher() {
  // nothing
}

bool SimpleDispatcher::ms_dispatch(Message *m)
{
  uint64_t dc = 0;

  dc = dcount++;

  ConnectionRef con = m->get_connection();
  Messenger* msgr = con->get_messenger();

  switch (m->get_type()) {
  case CEPH_MSG_PING:
    break;
  case MSG_DATA_PING:
  {
    MDataPing* mdp __attribute__((unused)) = static_cast<MDataPing*>(m);
    //cout << "MDataPing " << mdp->tag << " " << mdp->counter << std::endl;
    //mdp->get_data().hexdump(cout);
    ConnectionRef con = m->get_connection();
    con->send_message(m);
  }
    break;
  default:
    ceph_abort();
  }

  if (unlikely(msgr->get_magic() & MSG_MAGIC_TRACE_CTR)) {
    if (unlikely(dc % 65536) == 0) {
      struct timespec ts;
      clock_gettime(CLOCK_REALTIME_COARSE, &ts);
      std::cout << "ping " << dc << " nanos: " <<
	ts.tv_nsec + (ts.tv_sec * 1000000000)  << std::endl;
    }
  } /* trace ctr */


  con->send_message(m);

  //m->put();

  return true;
}

bool SimpleDispatcher::ms_handle_reset(Connection *con)
{
  return true;
}

void SimpleDispatcher::ms_handle_remote_reset(Connection *con)
{
  // nothing
}