Skip to content

Instantly share code, notes, and snippets.

@avsej
Created December 13, 2013 12:37
Show Gist options
  • Select an option

  • Save avsej/7943632 to your computer and use it in GitHub Desktop.

Select an option

Save avsej/7943632 to your computer and use it in GitHub Desktop.
#include <libcouchbase/couchbase.h>
#include <iostream>
#include <cassert>
extern "C"
{
static void error_callback(lcb_t, lcb_error_t err, const char*)
{
assert( !"error callback" );
}
}
int main( int argc, char **argv )
{
if ( argc != 2 )
{
std::cerr <<
"USAGE " << argv[ 0 ] << " <server:port>\n" <<
"\n"
"This program will try to connect to bucket default\n"
"We have found that it loops endlessly when the server\n"
"exists but the port is closed.\n"
"\n"
"It seems that some errors from the connect() system call\n"
"are not seen by libcouchbase 2.2.0 (check with strace)\n";
return 1;
}
struct lcb_create_st create_options;
lcb_t instance;
memset(&create_options, 0, sizeof(create_options));
create_options.v.v0.host = argv[ 1 ];
if ( lcb_create(&instance, &create_options) != LCB_SUCCESS )
assert( !"lcb_create failed" );
lcb_set_error_callback(instance, error_callback);
if ( lcb_connect(instance) != LCB_SUCCESS)
assert( !"lcb_connect failed" );
if ( lcb_wait(instance) != LCB_SUCCESS )
assert( !"lcb_wait failed" );
std::cout << "We never get here when server exists but port is closed\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment