2 +--------------------------------------------------------------------+
3 | libmemcached-awesome - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ |
13 +--------------------------------------------------------------------+
18 #include "options.hpp"
19 #include "libmemcached/common.h"
25 bool check_buffering(const client_options &opt, memcached_st &memc) {
26 if (opt.isset("buffer")) {
27 if (MEMCACHED_SUCCESS != memcached_flush_buffers(&memc)) {
28 if (!opt.isset("quiet")) {
29 std::cerr << memcached_last_error_message(&memc) << "\n";
37 bool check_argp(const client_options &opt, char **argp, const char *error_msg) {
41 if (!opt.isset("quiet")) {
42 std::cerr << error_msg << "\n";
47 bool check_memcached(const client_options &opt, memcached_st &memc) {
48 if (!memcached_create(&memc)) {
49 if (!opt.isset("quiet")) {
50 std::cerr << "Failed to initialize memcached client.\n";
57 bool check_return(const client_options &opt, memcached_st &memc, memcached_return_t rc) {
58 if (!memcached_success(rc)) {
59 if (!opt.isset("quiet")) {
60 if (!memcached_fatal(rc)) {
61 if (opt.isset("verbose")) {
62 std::cerr << "Failed: " << memcached_strerror(&memc, rc) << "\n";;
65 std::cerr << "Fatal error: " << memcached_last_error_message(&memc) << "\n";
73 bool check_return(const client_options &opt, memcached_st &memc, const char *key,
74 memcached_return_t rc) {
75 if (!memcached_success(rc)) {
76 if (!opt.isset("quiet")) {
77 if (MEMCACHED_NOTFOUND == rc) {
78 if (opt.isset("verbose")) {
79 std::cerr << "Could not find key '" << key
80 << "': " << memcached_strerror(&memc, rc) << "\n";;
83 std::cerr << "Fatal error for key '" << key
84 << "': " << memcached_last_error_message(&memc) << "\n";
92 std::ostream *check_ostream(const client_options &opt, const char *file, std::ofstream &stream) {
94 if (opt.isset("debug")) {
95 std::cerr << "Opening '" << file << "' for writing.\n";
98 stream.open(file, std::ios::binary | std::ios::out);
99 if (stream.is_open()) {
101 } else if (!opt.isset("quiet")) {
102 std::cerr << "Failed to open '" << file << "' for writing: " << strerror(errno) << ".\n";
108 std::istream *check_istream(const client_options &opt, const char *file, std::ifstream &stream) {
110 if (file[0] != '-' || file[1] != 0) {
111 if (opt.isset("debug")) {
112 std::cerr << "Opening '" << file << "' for reading.\n";
115 stream.open(file, std::ios::binary | std::ios::in);
116 if (stream.is_open()) {
118 } else if (!opt.isset("quiet")) {
119 std::cerr << "Failed to open '" << file << "' for reading: " << strerror(errno) << ".\n";