~brianaker/gearmand/fork-tests

« back to all changes in this revision

Viewing changes to libgearman/check.cc

  • Committer: Brian Aker
  • Date: 2013-06-30 02:48:43 UTC
  • Revision ID: brian@tangent.org-20130630024843-cyeuwxib5634s6tr
Fix for fork test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
#include "libgearman/error_code.h"
43
43
 
 
44
#include <algorithm>
 
45
 
44
46
EchoCheck::EchoCheck(gearman_universal_st& universal_,
45
47
    const void *workload_, const size_t workload_size_) :
46
48
    _universal(universal_),
56
58
    return gearman_error(_universal, GEARMAN_INVALID_COMMAND, "Wrong command sent in response to ECHO request");
57
59
  }
58
60
 
59
 
  if (con->_packet.data_size != _workload_size or
60
 
      memcmp(_workload, con->_packet.data, _workload_size))
61
 
  {
62
 
    return gearman_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, "corruption during echo");
 
61
  size_t compared= std::min(con->_packet.size(), _workload_size);
 
62
 
 
63
  if (compared != _workload_size or compared != con->_packet.size())
 
64
  {
 
65
    // If the workload_size is smaller
 
66
    if (memcmp(_workload, con->_packet.value(), compared) == 0)
 
67
    {
 
68
      return gearman_universal_set_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_AT,
 
69
                                         "Truncation occured, Expected %u, received %u",
 
70
                                         uint32_t(_workload_size), uint32_t(con->_packet.data_size));
 
71
    }
 
72
 
 
73
    return gearman_universal_set_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_AT,
 
74
                                       "Expected data was not received, expected %u, received %u",
 
75
                                       uint32_t(_workload_size), uint32_t(con->_packet.data_size));
 
76
  }
 
77
  assert(compared == _workload_size);
 
78
 
 
79
  if (memcmp(_workload, con->_packet.value(), compared))
 
80
  {
 
81
    return gearman_universal_set_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_AT,
 
82
                                       "Data sent was not what was received %u == %u == %u",
 
83
                                       uint32_t(_workload_size), uint32_t(con->_packet.data_size), uint32_t(compared));
63
84
  }
64
85
 
65
86
  return GEARMAN_SUCCESS;