2 +--------------------------------------------------------------------+
3 | libmemcached - 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 Michael Wallner <mike@php.net> |
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, const char *key,
58 memcached_return_t rc) {
59 if (!memcached_success(rc)) {
60 if (!opt.isset("quiet")) {
61 if (MEMCACHED_NOTFOUND == rc) {
62 if (opt.isset("verbose")) {
63 std::cerr << "Could not find key '" << key
64 << "': " << memcached_strerror(&memc, rc) << "\n";;
67 std::cerr << "Fatal error for key '" << key
68 << "': " << memcached_last_error_message(&memc) << "\n";
76 std::ostream *check_ostream(const client_options &opt, const char *file, std::ofstream &stream) {
78 if (opt.isset("debug")) {
79 std::cerr << "Opening '" << file << "' for writing.\n";
82 stream.open(file, std::ios::binary | std::ios::out);
83 if (stream.is_open()) {
85 } else if (!opt.isset("quiet")) {
86 std::cerr << "Failed to open '" << file << "' for writing: " << strerror(errno) << ".\n";
92 std::istream *check_istream(const client_options &opt, const char *file, std::ifstream &stream) {
94 if (file[0] != '-' || file[1] != 0) {
95 if (opt.isset("debug")) {
96 std::cerr << "Opening '" << file << "' for reading.\n";
99 stream.open(file, std::ios::binary | std::ios::in);
100 if (stream.is_open()) {
102 } else if (!opt.isset("quiet")) {
103 std::cerr << "Failed to open '" << file << "' for reading: " << strerror(errno) << ".\n";