~brianaker/libmemcached/1164440

« back to all changes in this revision

Viewing changes to libtest/fatal.cc

  • Committer: Continuous Integration
  • Date: 2012-10-22 05:56:09 UTC
  • mfrom: (1086.1.8 libmemcached-1.0)
  • Revision ID: ci@tangent.org-20121022055609-cbooaw9bcdal4qge
Merge lp:~tangent-org/libmemcached/1.0-build Build: jenkins-Libmemcached-1.0-87

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
namespace libtest {
42
42
 
43
 
exception::exception(const char *file_, int line_, const char *func_) :
44
 
  std::runtime_error(func_),
45
 
  _file(file_),
46
 
  _line(line_),
47
 
  _func(func_)
48
 
  {
49
 
  }
50
 
 
51
 
#ifndef __INTEL_COMPILER
52
43
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
53
 
#endif
54
 
 
55
 
fatal::fatal(const char *file_, int line_, const char *func_, const char *format, ...) :
56
 
  exception(file_, line_, func_)
 
44
fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const char *format, ...) :
 
45
  std::runtime_error(func_arg),
 
46
  _line(line_arg),
 
47
  _file(file_arg),
 
48
  _func(func_arg)
57
49
  {
58
50
    va_list args;
59
51
    va_start(args, format);
61
53
    int last_error_length= vsnprintf(last_error, sizeof(last_error), format, args);
62
54
    va_end(args);
63
55
 
 
56
    strncpy(_mesg, last_error, sizeof(_mesg));
 
57
 
64
58
    snprintf(_error_message, sizeof(_error_message), "%.*s", last_error_length, last_error);
65
59
  }
66
60
 
74
68
 
75
69
void fatal::disable()
76
70
{
 
71
  _counter= 0;
77
72
  _disabled= true;
78
73
}
79
74
 
80
75
void fatal::enable()
81
76
{
 
77
  _counter= 0;
82
78
  _disabled= false;
83
79
}
84
80
 
92
88
  _counter++;
93
89
}
94
90
 
95
 
disconnected::disconnected(const char *file_, int line_, const char *func_,
 
91
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 
92
disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg,
96
93
                           const std::string& instance, const in_port_t port,
97
94
                           const char *format, ...) :
98
 
  exception(file_, line_, func_),
99
 
  _port(port)
100
 
{
101
 
  va_list args;
102
 
  va_start(args, format);
103
 
  char last_error[BUFSIZ];
104
 
  (void)vsnprintf(last_error, sizeof(last_error), format, args);
105
 
  va_end(args);
106
 
 
107
 
  snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error);
108
 
}
109
 
 
110
 
start::start(const char *file_, int line_, const char *func_,
111
 
             const std::string& instance, const in_port_t port,
112
 
             const char *format, ...) :
113
 
  exception(file_, line_, func_),
114
 
  _port(port)
 
95
  std::runtime_error(func_arg),
 
96
  _port(port),
 
97
  _line(line_arg),
 
98
  _file(file_arg),
 
99
  _func(func_arg)
115
100
{
116
101
  va_list args;
117
102
  va_start(args, format);