diff --git a/example/couchview.c b/example/couchview.c index d3d31134c..ab430e1f0 100644 --- a/example/couchview.c +++ b/example/couchview.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -44,9 +43,9 @@ static void set_flag(char cmd, const void *arg, void *cookie) { } static void set_char_ptr(char cmd, const void *arg, void *cookie) { - (void)cmd; const char **myptr = cookie; *myptr = arg; + (void)cmd; } const char *host = "localhost:8091"; @@ -74,10 +73,11 @@ static void set_auth_data(char cmd, const void *arg, void *cookie) { } } else { char buffer[80]; + size_t len; if (fgets(buffer, sizeof(buffer), stdin) == NULL) { exit(EXIT_FAILURE); } - size_t len = strlen(buffer) - 1; + len = strlen(buffer) - 1; while (len > 0 && isspace(buffer[len])) { buffer[len] = '\0'; --len; @@ -93,7 +93,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -101,21 +101,21 @@ static struct { ['?'] = { .name = "help", .description = "\t-?\t\tPrint program usage information", - .argument = false, + .argument = 0, .letter = '?', .handler = usage }, ['u'] = { .name = "username", .description = "\t-u name\t\tSpecify username", - .argument = true, + .argument = 1, .letter = 'u', .handler = set_auth_data }, ['h'] = { .name = "host", .description = "\t-h host\t\tHost to read configuration from", - .argument = true, + .argument = 1, .letter = 'h', .handler = set_char_ptr, .cookie = &host @@ -123,7 +123,7 @@ static struct { ['b'] = { .name = "bucket", .description = "\t-b bucket\tThe bucket to connect to", - .argument = true, + .argument = 1, .letter = 'b', .handler = set_char_ptr, .cookie = &bucket @@ -131,7 +131,7 @@ static struct { ['o'] = { .name = "file", .description = "\t-o filename\tSend the output to this file", - .argument = true, + .argument = 1, .letter = 'o', .handler = set_char_ptr, .cookie = &filename @@ -139,7 +139,7 @@ static struct { ['c'] = { .name = "chunked", .description = "\t-c\t\tUse chunked callback to stream the data", - .argument = false, + .argument = 0, .letter = 'c', .handler = set_flag, .cookie = &chunked @@ -147,7 +147,7 @@ static struct { ['d'] = { .name = "data", .description = "\t-d\t\tPOST data, e.g. {\"keys\": [\"key1\", \"key2\", ...]}", - .argument = true, + .argument = 1, .letter = 'd', .handler = set_char_ptr, .cookie = &post_data @@ -167,6 +167,7 @@ static void handle_options(int argc, char **argv) { char shortopts[128] = { 0 }; int jj = 0; int kk = 0; + int c; for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { opts[jj].name = (char*)my_options[ii].name; @@ -180,7 +181,6 @@ static void handle_options(int argc, char **argv) { } } - int c; while ((c = getopt_long(argc, argv, shortopts, opts, NULL)) != EOF) { if (my_options[c].handler != NULL) { my_options[c].handler((char)c, optarg, my_options[c].cookie); @@ -250,6 +250,8 @@ int main(int argc, char **argv) size_t nbytes = 0; struct cookie_st cookie; libcouchbase_error_t rc; + libcouchbase_t instance; + handle_options(argc, argv); if (strcmp(filename, "-") == 0) { @@ -273,7 +275,7 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to create IO instance\n"); return 1; } - libcouchbase_t instance = libcouchbase_create(host, username, + instance = libcouchbase_create(host, username, passwd, bucket, cookie.io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); @@ -289,7 +291,7 @@ int main(int argc, char **argv) return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); bytes = post_data; @@ -314,12 +316,14 @@ int main(int argc, char **argv) static void usage(char cmd, const void *arg, void *cookie) { + int ii; + (void)cmd; (void)arg; (void)cookie; fprintf(stderr, "Usage: ./couchview [options] viewid\n"); - for (int ii = 0; ii < 256; ++ii) { + for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { fprintf(stderr, "%s\n", my_options[ii].description); } diff --git a/example/couchview_yajl.c b/example/couchview_yajl.c index 34b74661c..467f1406d 100644 --- a/example/couchview_yajl.c +++ b/example/couchview_yajl.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include diff --git a/example/memcat.c b/example/memcat.c index 8d167ad00..ddd706a79 100644 --- a/example/memcat.c +++ b/example/memcat.c @@ -22,14 +22,13 @@ * @todo add documentation */ -// @todo figure out what I need to include for win32 in the headers! +/* @todo figure out what I need to include for win32 in the headers! */ #include "config.h" #include #include #include #include -#include #include #include #include @@ -39,9 +38,9 @@ #ifdef WIN32 #define PRIu64 "llu" -static bool isatty(int a) { +static int isatty(int a) { (void)a; - return true; + return 1; } static char *getpass(const char *prompt) @@ -111,7 +110,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -121,29 +120,29 @@ static void setup_options(void) { my_options['?'].name = "help"; my_options['?'].description = "\t-?\tPrint program usage information"; - my_options['?'].argument = false; + my_options['?'].argument = 0; my_options['?'].letter = '?'; my_options['?'].handler = usage; my_options['u'].name = "username"; my_options['u'].description = "\t-u nm\tSpecify username"; - my_options['u'].argument = true; + my_options['u'].argument = 1; my_options['u'].letter = 'u'; my_options['u'].handler = set_auth_data; my_options['h'].name = "host"; my_options['h'].description = "\t-h host\tHost to read configuration from"; - my_options['h'].argument = true; + my_options['h'].argument = 1; my_options['h'].letter = 'h'; my_options['h'].handler = set_char_ptr; my_options['h'].cookie = &host; my_options['b'].name = "bucket"; my_options['b'].description = "\t-b bucket\tThe bucket to connect to"; - my_options['b'].argument = true; + my_options['b'].argument = 1; my_options['b'].letter = 'b'; my_options['b'].handler = set_char_ptr; my_options['b'].cookie = &bucket; my_options['o'].name = "file"; my_options['o'].description = "\t-o filename\tSend the output to this file"; - my_options['o'].argument = true; + my_options['o'].argument = 1; my_options['o'].letter = 'o'; my_options['o'].handler = set_char_ptr; my_options['o'].cookie = &filename; @@ -281,7 +280,7 @@ int main(int argc, char **argv) libcouchbase_strerror(instance, ret)); return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_get_callback(instance, get_callback); diff --git a/example/memcp.c b/example/memcp.c index 5fcc2b9db..4c64a6e28 100644 --- a/example/memcp.c +++ b/example/memcp.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -39,9 +38,9 @@ static void usage(char cmd, const void *arg, void *cookie); static void set_char_ptr(char cmd, const void *arg, void *cookie) { - (void)cmd; const char **myptr = cookie; *myptr = arg; + (void)cmd; } const char *host = "localhost:8091"; @@ -63,10 +62,11 @@ static void set_auth_data(char cmd, const void *arg, void *cookie) { } } else { char buffer[80]; + size_t len; if (fgets(buffer, sizeof(buffer), stdin) == NULL) { exit(EXIT_FAILURE); } - size_t len = strlen(buffer) - 1; + len = strlen(buffer) - 1; while (len > 0 && isspace(buffer[len])) { buffer[len] = '\0'; --len; @@ -82,7 +82,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -90,21 +90,21 @@ static struct { ['?'] = { .name = "help", .description = "\t-?\tPrint program usage information", - .argument = false, + .argument = 0, .letter = '?', .handler = usage }, ['u'] = { .name = "username", .description = "\t-u nm\tSpecify username", - .argument = true, + .argument = 1, .letter = 'u', .handler = set_auth_data }, ['h'] = { .name = "host", .description = "\t-h host\tHost to read configuration from", - .argument = true, + .argument = 1, .letter = 'h', .handler = set_char_ptr, .cookie = &host @@ -112,7 +112,7 @@ static struct { ['b'] = { .name = "bucket", .description = "\t-b bucket\tThe bucket to connect to", - .argument = true, + .argument = 1, .letter = 'b', .handler = set_char_ptr, .cookie = &bucket @@ -120,7 +120,7 @@ static struct { ['o'] = { .name = "file", .description = "\t-o filename\tSend the output to this file", - .argument = true, + .argument = 1, .letter = 'o', .handler = set_char_ptr, .cookie = &filename @@ -140,6 +140,8 @@ static void handle_options(int argc, char **argv) { char shortopts[128] = { 0 }; int jj = 0; int kk = 0; + int c; + for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { opts[jj].name = (char*)my_options[ii].name; @@ -153,7 +155,6 @@ static void handle_options(int argc, char **argv) { } } - int c; while ((c = getopt_long(argc, argv, shortopts, opts, NULL)) != EOF) { if (my_options[c].handler != NULL) { my_options[c].handler((char)c, optarg, my_options[c].cookie); @@ -194,6 +195,10 @@ static void error_callback(libcouchbase_t instance, int main(int argc, char **argv) { + struct libcouchbase_io_opt_st *io; + libcouchbase_t instance; + int ii; + handle_options(argc, argv); if (strcmp(filename, "-") == 0) { @@ -207,14 +212,13 @@ int main(int argc, char **argv) } } - struct libcouchbase_io_opt_st *io; io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_DEFAULT, NULL, NULL); if (io == NULL) { fprintf(stderr, "Failed to create IO instance\n"); return 1; } - libcouchbase_t instance = libcouchbase_create(host, username, + instance = libcouchbase_create(host, username, passwd, bucket, io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); @@ -227,12 +231,12 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to connect libcouchbase instance to server\n"); return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_storage_callback(instance, storage_callback); - for (int ii = optind; ii < argc; ++ii) { + for (ii = optind; ii < argc; ++ii) { const char *key = argv[ii]; size_t nkey = strlen(key); @@ -263,12 +267,13 @@ int main(int argc, char **argv) static void usage(char cmd, const void *arg, void *cookie) { + int ii; (void)cmd; (void)arg; (void)cookie; fprintf(stderr, "Usage: ./memcp [options] keys\n"); - for (int ii = 0; ii < 256; ++ii) { + for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { fprintf(stderr, "%s\n", my_options[ii].description); } diff --git a/example/memdump.c b/example/memdump.c index 03d8a2069..9b24c1036 100644 --- a/example/memdump.c +++ b/example/memdump.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -34,9 +33,9 @@ static void usage(char cmd, const void *arg, void *cookie); static void set_char_ptr(char cmd, const void *arg, void *cookie) { - (void)cmd; const char **myptr = cookie; *myptr = arg; + (void)cmd; } const char *host = "localhost:8091"; @@ -58,10 +57,11 @@ static void set_auth_data(char cmd, const void *arg, void *cookie) { } } else { char buffer[80]; + size_t len; if (fgets(buffer, sizeof(buffer), stdin) == NULL) { exit(EXIT_FAILURE); } - size_t len = strlen(buffer) - 1; + len = strlen(buffer) - 1; while (len > 0 && isspace(buffer[len])) { buffer[len] = '\0'; --len; @@ -77,7 +77,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -85,21 +85,21 @@ static struct { ['?'] = { .name = "help", .description = "\t-?\tPrint program usage information", - .argument = false, + .argument = 0, .letter = '?', .handler = usage }, ['u'] = { .name = "username", .description = "\t-u nm\tSpecify username", - .argument = true, + .argument = 1, .letter = 'u', .handler = set_auth_data }, ['h'] = { .name = "host", .description = "\t-h host\tHost to read configuration from", - .argument = true, + .argument = 1, .letter = 'h', .handler = set_char_ptr, .cookie = &host @@ -107,7 +107,7 @@ static struct { ['b'] = { .name = "bucket", .description = "\t-b bucket\tThe bucket to connect to", - .argument = true, + .argument = 1, .letter = 'b', .handler = set_char_ptr, .cookie = &bucket @@ -115,7 +115,7 @@ static struct { ['o'] = { .name = "file", .description = "\t-o filename\tSend the output to this file", - .argument = true, + .argument = 1, .letter = 'o', .handler = set_char_ptr, .cookie = &filename @@ -135,6 +135,7 @@ static void handle_options(int argc, char **argv) { char shortopts[128] = { 0 }; int jj = 0; int kk = 0; + int c; for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { opts[jj].name = (char*)my_options[ii].name; @@ -148,7 +149,6 @@ static void handle_options(int argc, char **argv) { } } - int c; while ((c = getopt_long(argc, argv, shortopts, opts, NULL)) != EOF) { if (my_options[c].handler != NULL) { my_options[c].handler((char)c, optarg, my_options[c].cookie); @@ -197,6 +197,9 @@ static void error_callback(libcouchbase_t instance, int main(int argc, char **argv) { + struct libcouchbase_io_opt_st *io; + libcouchbase_t instance; + handle_options(argc, argv); if (strcmp(filename, "-") == 0) { @@ -210,13 +213,12 @@ int main(int argc, char **argv) } } - struct libcouchbase_io_opt_st *io; io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_DEFAULT, NULL, NULL); if (io == NULL) { fprintf(stderr, "Failed to create IO instance\n"); return 1; } - libcouchbase_t instance = libcouchbase_create(host, username, + instance = libcouchbase_create(host, username, passwd, bucket, io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); @@ -230,23 +232,24 @@ int main(int argc, char **argv) return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_tap_mutation_callback(instance, tap_mutation); - libcouchbase_tap_cluster(instance, NULL, NULL, true); + libcouchbase_tap_cluster(instance, NULL, NULL, 1); return 0; } static void usage(char cmd, const void *arg, void *cookie) { + int ii; (void)cmd; (void)arg; (void)cookie; fprintf(stderr, "Usage: ./memdump [options]\n"); - for (int ii = 0; ii < 256; ++ii) { + for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { fprintf(stderr, "%s\n", my_options[ii].description); } diff --git a/example/memflush.c b/example/memflush.c index 7360da921..e2af5d807 100644 --- a/example/memflush.c +++ b/example/memflush.c @@ -22,14 +22,13 @@ * @todo add documentation */ -// @todo figure out what I need to include for win32 in the headers! +/* @todo figure out what I need to include for win32 in the headers! */ #include "config.h" #include #include #include #include -#include #include #include #include @@ -38,9 +37,9 @@ #include #ifdef WIN32 -static bool isatty(int a) { +static int isatty(int a) { (void)a; - return true; + return 1; } static char *getpass(const char *prompt) @@ -109,7 +108,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -119,23 +118,23 @@ static void setup_options(void) { my_options['?'].name = "help"; my_options['?'].description = "\t-?\tPrint program usage information"; - my_options['?'].argument = false; + my_options['?'].argument = 0; my_options['?'].letter = '?'; my_options['?'].handler = usage; my_options['u'].name = "username"; my_options['u'].description = "\t-u nm\tSpecify username"; - my_options['u'].argument = true; + my_options['u'].argument = 1; my_options['u'].letter = 'u'; my_options['u'].handler = set_auth_data; my_options['h'].name = "host"; my_options['h'].description = "\t-h host\tHost to read configuration from"; - my_options['h'].argument = true; + my_options['h'].argument = 1; my_options['h'].letter = 'h'; my_options['h'].handler = set_char_ptr; my_options['h'].cookie = &host; my_options['b'].name = "bucket"; my_options['b'].description = "\t-b bucket\tThe bucket to connect to"; - my_options['b'].argument = true; + my_options['b'].argument = 1; my_options['b'].letter = 'b'; my_options['b'].handler = set_char_ptr; my_options['b'].cookie = &bucket; @@ -238,7 +237,7 @@ int main(int argc, char **argv) libcouchbase_strerror(instance, ret)); return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_flush_callback(instance, flush_callback); diff --git a/example/memrm.c b/example/memrm.c index cb09a483b..64d0f08a3 100644 --- a/example/memrm.c +++ b/example/memrm.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -39,9 +38,9 @@ static void usage(char cmd, const void *arg, void *cookie); static void set_char_ptr(char cmd, const void *arg, void *cookie) { - (void)cmd; const char **myptr = cookie; *myptr = arg; + (void)cmd; } const char *host = "localhost:8091"; @@ -63,10 +62,11 @@ static void set_auth_data(char cmd, const void *arg, void *cookie) { } } else { char buffer[80]; + size_t len; if (fgets(buffer, sizeof(buffer), stdin) == NULL) { exit(EXIT_FAILURE); } - size_t len = strlen(buffer) - 1; + len = strlen(buffer) - 1; while (len > 0 && isspace(buffer[len])) { buffer[len] = '\0'; --len; @@ -82,7 +82,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -90,21 +90,21 @@ static struct { ['?'] = { .name = "help", .description = "\t-?\tPrint program usage information", - .argument = false, + .argument = 0, .letter = '?', .handler = usage }, ['u'] = { .name = "username", .description = "\t-u nm\tSpecify username", - .argument = true, + .argument = 1, .letter = 'u', .handler = set_auth_data }, ['h'] = { .name = "host", .description = "\t-h host\tHost to read configuration from", - .argument = true, + .argument = 1, .letter = 'h', .handler = set_char_ptr, .cookie = &host @@ -112,7 +112,7 @@ static struct { ['b'] = { .name = "bucket", .description = "\t-b bucket\tThe bucket to connect to", - .argument = true, + .argument = 1, .letter = 'b', .handler = set_char_ptr, .cookie = &bucket @@ -132,6 +132,7 @@ static void handle_options(int argc, char **argv) { char shortopts[128] = { 0 }; int jj = 0; int kk = 0; + int c; for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { opts[jj].name = (char*)my_options[ii].name; @@ -145,7 +146,6 @@ static void handle_options(int argc, char **argv) { } } - int c; while ((c = getopt_long(argc, argv, shortopts, opts, NULL)) != EOF) { if (my_options[c].handler != NULL) { my_options[c].handler((char)c, optarg, my_options[c].cookie); @@ -181,15 +181,18 @@ static void error_callback(libcouchbase_t instance, int main(int argc, char **argv) { + struct libcouchbase_io_opt_st *io; + libcouchbase_t instance; + int ii; + handle_options(argc, argv); - struct libcouchbase_io_opt_st *io; io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_DEFAULT, NULL, NULL); if (io == NULL) { fprintf(stderr, "Failed to create IO instance\n"); return 1; } - libcouchbase_t instance = libcouchbase_create(host, username, + instance = libcouchbase_create(host, username, passwd, bucket, io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); @@ -202,12 +205,12 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to connect libcouchbase instance to server\n"); return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_remove_callback(instance, remove_callback); - for (int ii = optind; ii < argc; ++ii) { + for (ii = optind; ii < argc; ++ii) { libcouchbase_remove(instance, NULL, argv[ii], strlen(argv[ii]), 0); } @@ -219,12 +222,13 @@ int main(int argc, char **argv) static void usage(char cmd, const void *arg, void *cookie) { + int ii; (void)cmd; (void)arg; (void)cookie; fprintf(stderr, "Usage: ./memrm [options] keys\n"); - for (int ii = 0; ii < 256; ++ii) { + for (ii = 0; ii < 256; ++ii) { if (my_options[ii].name != NULL) { fprintf(stderr, "%s\n", my_options[ii].description); } diff --git a/example/memstat.c b/example/memstat.c index 6af7fa603..e21f434dc 100644 --- a/example/memstat.c +++ b/example/memstat.c @@ -22,14 +22,14 @@ * @todo add documentation */ -// @todo figure out what I need to include for win32 in the headers! +/* @todo figure out what I need to include for win32 in the headers! */ #include "config.h" #include #include #include #include -#include +#include #include #include #include @@ -39,9 +39,9 @@ #ifdef WIN32 #define PRIu64 "llu" -static bool isatty(int a) { +static int isatty(int a) { (void)a; - return true; + return 1; } static char *getpass(const char *prompt) @@ -111,7 +111,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie); static struct { const char *name; const char *description; - bool argument; + int argument; char letter; OPTION_HANDLER handler; void *cookie; @@ -121,29 +121,29 @@ static void setup_options(void) { my_options['?'].name = "help"; my_options['?'].description = "\t-?\tPrint program usage information"; - my_options['?'].argument = false; + my_options['?'].argument = 0; my_options['?'].letter = '?'; my_options['?'].handler = usage; my_options['u'].name = "username"; my_options['u'].description = "\t-u nm\tSpecify username"; - my_options['u'].argument = true; + my_options['u'].argument = 1; my_options['u'].letter = 'u'; my_options['u'].handler = set_auth_data; my_options['h'].name = "host"; my_options['h'].description = "\t-h host\tHost to read configuration from"; - my_options['h'].argument = true; + my_options['h'].argument = 1; my_options['h'].letter = 'h'; my_options['h'].handler = set_char_ptr; my_options['h'].cookie = &host; my_options['b'].name = "bucket"; my_options['b'].description = "\t-b bucket\tThe bucket to connect to"; - my_options['b'].argument = true; + my_options['b'].argument = 1; my_options['b'].letter = 'b'; my_options['b'].handler = set_char_ptr; my_options['b'].cookie = &bucket; my_options['o'].name = "file"; my_options['o'].description = "\t-o filename\tSend the output to this file"; - my_options['o'].argument = true; + my_options['o'].argument = 1; my_options['o'].letter = 'o'; my_options['o'].handler = set_char_ptr; my_options['o'].cookie = &filename; @@ -274,7 +274,7 @@ int main(int argc, char **argv) libcouchbase_strerror(instance, ret)); return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_stat_callback(instance, stat_callback); diff --git a/include/libcouchbase/couchbase.h b/include/libcouchbase/couchbase.h index 16bb52e6b..5519097eb 100644 --- a/include/libcouchbase/couchbase.h +++ b/include/libcouchbase/couchbase.h @@ -27,10 +27,6 @@ #include #include -#ifndef __cplusplus -#include -#endif - #include #include #include @@ -131,7 +127,7 @@ extern "C" { void libcouchbase_tap_cluster(libcouchbase_t instance, const void *command_cookie, libcouchbase_tap_filter_t filter, - bool block); + int block); /** * Wait for the execution of all batched requests @@ -360,7 +356,7 @@ extern "C" { const void *command_cookie, const void *key, size_t nkey, int64_t delta, time_t exp, - bool create, uint64_t initial); + int create, uint64_t initial); /** * Spool an arithmetic operation to the cluster. The operation may be @@ -390,7 +386,7 @@ extern "C" { size_t nkey, int64_t delta, time_t exp, - bool create, + int create, uint64_t initial); /** @@ -482,7 +478,7 @@ extern "C" { libcouchbase_http_method_t method, const void *body, size_t nbody, - bool chunked); + int chunked); /** * Flush the entire couchbase cluster! diff --git a/include/libcouchbase/tap_filter.h b/include/libcouchbase/tap_filter.h index b0459f64a..345de4ca8 100644 --- a/include/libcouchbase/tap_filter.h +++ b/include/libcouchbase/tap_filter.h @@ -69,7 +69,7 @@ extern "C" { */ LIBCOUCHBASE_API void libcouchbase_tap_filter_set_keys_only(libcouchbase_tap_filter_t instance, - bool keys_only); + int keys_only); /** * Get whether you are interested in keys and values, or only keys in your @@ -77,7 +77,7 @@ extern "C" { * @param instance the tap filter instance to retrieve the value from. */ LIBCOUCHBASE_API - bool libcouchbase_tap_filter_get_keys_only(libcouchbase_tap_filter_t instance); + int libcouchbase_tap_filter_get_keys_only(libcouchbase_tap_filter_t instance); #ifdef __cplusplus } diff --git a/include/libcouchbase/timings.h b/include/libcouchbase/timings.h index 206aad6cb..540481ebb 100644 --- a/include/libcouchbase/timings.h +++ b/include/libcouchbase/timings.h @@ -43,7 +43,7 @@ extern "C" { LIBCOUCHBASE_TIMEUNIT_NSEC = 0, LIBCOUCHBASE_TIMEUNIT_USEC = 1, LIBCOUCHBASE_TIMEUNIT_MSEC = 2, - LIBCOUCHBASE_TIMEUNIT_SEC = 3, + LIBCOUCHBASE_TIMEUNIT_SEC = 3 } libcouchbase_timeunit_t; /** diff --git a/src/arithmetic.c b/src/arithmetic.c index 62c0b7d43..477143124 100644 --- a/src/arithmetic.c +++ b/src/arithmetic.c @@ -27,7 +27,7 @@ libcouchbase_error_t libcouchbase_arithmetic(libcouchbase_t instance, const void *command_cookie, const void *key, size_t nkey, int64_t delta, time_t exp, - bool create, uint64_t initial) + int create, uint64_t initial) { return libcouchbase_arithmetic_by_key(instance, command_cookie, NULL, 0, key, nkey, delta, exp, create, initial); @@ -40,13 +40,13 @@ libcouchbase_error_t libcouchbase_arithmetic_by_key(libcouchbase_t instance, size_t nhashkey, const void *key, size_t nkey, int64_t delta, time_t exp, - bool create, uint64_t initial) + int create, uint64_t initial) { uint16_t vb; libcouchbase_server_t *server; protocol_binary_request_incr req; - // we need a vbucket config before we can start getting data.. + /* we need a vbucket config before we can start getting data.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } diff --git a/src/error.c b/src/error.c index 94fc16445..6f31f1207 100644 --- a/src/error.c +++ b/src/error.c @@ -55,12 +55,14 @@ libcouchbase_error_t libcouchbase_get_last_error(libcouchbase_t instance) */ libcouchbase_error_t libcouchbase_error_handler(libcouchbase_t instance, libcouchbase_error_t error, const char *errinfo) { - // Set the last error value so it can be access without needing an error callback. + /* Set the last error value so it can be access without needing an + ** error callback. + */ instance->last_error = error; - // TODO: Should we call the callback anyway, even if it's a SUCCESS? + /* TODO: Should we call the callback anyway, even if it's a SUCCESS? */ if (error != LIBCOUCHBASE_SUCCESS) { - // Call the user's error callback. + /* Call the user's error callback. */ instance->callbacks.error(instance, error, errinfo); } diff --git a/src/event.c b/src/event.c index cbab9aa44..a8251b91f 100644 --- a/src/event.c +++ b/src/event.c @@ -81,12 +81,13 @@ static int parse_single(libcouchbase_server_t *c, hrtime_t stop) } packet = c->input.read_head; - // we have everything! + /* we have everything! */ if (!libcouchbase_ringbuffer_is_continous(&c->input, RINGBUFFER_READ, packetsize)) { - // The buffer isn't continous.. for now just copy it out and - // operate on the copy ;) + /* The buffer isn't continous.. for now just copy it out and + ** operate on the copy ;) + */ if ((packet = malloc(packetsize)) == NULL) { libcouchbase_error_handler(c->instance, LIBCOUCHBASE_ENOMEM, NULL); return -1; @@ -165,15 +166,19 @@ static int parse_single(libcouchbase_server_t *c, hrtime_t stop) static int do_read_data(libcouchbase_server_t *c) { - // Loop and try to parse the data... We don't want to lock up the - // event loop completely, so set a max number of packets to process - // before backing off.. + /* + ** Loop and try to parse the data... We don't want to lock up the + ** event loop completely, so set a max number of packets to process + ** before backing off.. + */ size_t processed = 0; - // @todo Make the backoff number tunable from the instance + /* @todo Make the backoff number tunable from the instance */ const size_t operations_per_call = 1000; int rv = 0; - // The timers isn't supposed to be _that_ accurate.. it's better - // to shave off system calls :) + /* + ** The timers isn't supposed to be _that_ accurate.. it's better + ** to shave off system calls :) + */ hrtime_t stop = gethrtime(); while (processed < operations_per_call) { @@ -181,9 +186,9 @@ static int do_read_data(libcouchbase_server_t *c) case -1: return -1; case 0: - // need more data + /* need more data */ if ((rv = do_fill_input_buffer(c)) < 1) { - // error or would block ;) + /* error or would block ;) */ return rv; } break; @@ -205,7 +210,7 @@ static int do_send_data(libcouchbase_server_t *c) if (nw == -1) { switch (c->instance->io->error) { case EINTR: - // retry + /* retry */ break; case EWOULDBLOCK: return 0; @@ -240,7 +245,7 @@ void libcouchbase_server_event_handler(evutil_socket_t sock, short which, void * if (which & LIBCOUCHBASE_READ_EVENT) { if (do_read_data(c) != 0) { - // TODO: Is there a better error for this? + /* TODO: Is there a better error for this? */ char errinfo[1024]; snprintf(errinfo, sizeof(errinfo), "Failed to read from connection" " to \"%s:%s\"", c->hostname, c->port); @@ -255,7 +260,7 @@ void libcouchbase_server_event_handler(evutil_socket_t sock, short which, void * char errinfo[1024]; snprintf(errinfo, sizeof(errinfo), "Failed to send to the " "connection to \"%s:%s\"", c->hostname, c->port); - // TODO: Is there a better error for this? + /* TODO: Is there a better error for this? */ libcouchbase_error_handler(c->instance, LIBCOUCHBASE_NETWORK_ERROR, errinfo); return; @@ -273,13 +278,13 @@ void libcouchbase_server_event_handler(evutil_socket_t sock, short which, void * } if (c->instance->wait) { - bool done = true; + int done = 1; libcouchbase_t instance = c->instance; size_t ii; for (ii = 0; ii < instance->nservers; ++ii) { c = instance->servers + ii; if (c->cmd_log.nbytes || c->output.nbytes || c->input.nbytes) { - done = false; + done = 0; break; } } @@ -289,6 +294,6 @@ void libcouchbase_server_event_handler(evutil_socket_t sock, short which, void * } } - // Make it known that this was a success. + /* Make it known that this was a success. */ libcouchbase_error_handler(c->instance, LIBCOUCHBASE_SUCCESS, NULL); } diff --git a/src/flush.c b/src/flush.c index 5ec0c76ac..14eb14647 100644 --- a/src/flush.c +++ b/src/flush.c @@ -25,7 +25,7 @@ libcouchbase_error_t libcouchbase_flush(libcouchbase_t instance, protocol_binary_request_no_extras flush; size_t ii; - // we need a vbucket config before we can start getting data.. + /* we need a vbucket config before we can start getting data.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } diff --git a/src/get.c b/src/get.c index f13ae39ae..95fee0cb8 100644 --- a/src/get.c +++ b/src/get.c @@ -60,7 +60,7 @@ libcouchbase_error_t libcouchbase_mget_by_key(libcouchbase_t instance, protocol_binary_request_noop noop; size_t ii; - // we need a vbucket config before we can start getting data.. + /* we need a vbucket config before we can start getting data.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } @@ -114,8 +114,10 @@ libcouchbase_error_t libcouchbase_mget_by_key(libcouchbase_t instance, noop.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; if (nhashkey == 0) { - // We don't know which server we sent the data to, so examine - // where to send the noop + /* + ** We don't know which server we sent the data to, so examine + ** where to send the noop + */ for (ii = 0; ii < instance->nservers; ++ii) { server = instance->servers + ii; if (server->output.nbytes > 0 || server->pending.nbytes > 0) { diff --git a/src/handler.c b/src/handler.c index f493ebd19..11d7cdcc4 100644 --- a/src/handler.c +++ b/src/handler.c @@ -240,10 +240,12 @@ static void storage_response_handler(libcouchbase_server_t *server, op = LIBCOUCHBASE_PREPEND; break; default: - // It is impossible to get here (since we're called from our - // lookup table... If we _DO_ get here, it must be a development - // version where the developer isn't done yet (and should be - // forced to think about what to do...) + /* + ** It is impossible to get here (since we're called from our + ** lookup table... If we _DO_ get here, it must be a development + ** version where the developer isn't done yet (and should be + ** forced to think about what to do...) + */ libcouchbase_error_handler(root, LIBCOUCHBASE_EINTERNAL, "Internal error. Received an illegal command opcode"); abort(); @@ -329,7 +331,7 @@ static void tap_mutation_handler(libcouchbase_server_t *server, const void *command_cookie, protocol_binary_request_header *req) { - // @todo verify that the size is correct! + /* @todo verify that the size is correct! */ char *packet = (char*)req; protocol_binary_request_tap_mutation *mutation = (void*)req; uint32_t flags = ntohl(mutation->message.body.item.flags); @@ -351,7 +353,7 @@ static void tap_deletion_handler(libcouchbase_server_t *server, const void *command_cookie, protocol_binary_request_header *req) { - // @todo verify that the size is correct! + /* @todo verify that the size is correct! */ char *packet = (char*)req; protocol_binary_request_tap_delete *deletion = (void*)req; uint16_t nkey = ntohs(req->request.keylen); @@ -366,7 +368,7 @@ static void tap_flush_handler(libcouchbase_server_t *server, const void *command_cookie, protocol_binary_request_header *req) { - // @todo verify that the size is correct! + /* @todo verify that the size is correct! */ char *packet = (char*)req; protocol_binary_request_tap_flush *flush = (void*)req; char *es = packet + sizeof(flush->bytes); @@ -379,7 +381,7 @@ static void tap_opaque_handler(libcouchbase_server_t *server, const void *command_cookie, protocol_binary_request_header *req) { - // @todo verify that the size is correct! + /* @todo verify that the size is correct! */ char *packet = (char*)req; protocol_binary_request_tap_opaque *opaque = (void*)req; char *es = packet + sizeof(opaque->bytes); @@ -392,7 +394,7 @@ static void tap_vbucket_set_handler(libcouchbase_server_t *server, const void *command_cookie, protocol_binary_request_header *req) { - // @todo verify that the size is correct! + /* @todo verify that the size is correct! */ libcouchbase_t root = server->instance; char *packet = (char*)req; protocol_binary_request_tap_vbucket_set *vbset = (void*)req; @@ -442,10 +444,10 @@ static void sasl_list_mech_response_handler(libcouchbase_server_t *server, libcouchbase_server_buffer_write_packet(server, &server->output, data, len); libcouchbase_server_buffer_end_packet(server, &server->output); - // send the data and add a write handler + /* send the data and add a write handler */ libcouchbase_server_event_handler(0, LIBCOUCHBASE_WRITE_EVENT, server); - // Make it known that this was a success. + /* Make it known that this was a success. */ libcouchbase_error_handler(server->instance, LIBCOUCHBASE_SUCCESS, NULL); } @@ -459,7 +461,7 @@ static void sasl_auth_response_handler(libcouchbase_server_t *server, server->sasl_conn = NULL; libcouchbase_server_connected(server); } else if (ret == PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE) { - // I don't know how to step yet ;-) + /* I don't know how to step yet ;-) */ libcouchbase_error_handler(server->instance, LIBCOUCHBASE_NOT_SUPPORTED, "We don't support sasl authentication that requires \"SASL STEP\" yet"); @@ -468,7 +470,7 @@ static void sasl_auth_response_handler(libcouchbase_server_t *server, "SASL authentication failed"); } - // Make it known that this was a success. + /* Make it known that this was a success. */ libcouchbase_error_handler(server->instance, LIBCOUCHBASE_SUCCESS, NULL); (void)command_cookie; } @@ -481,7 +483,7 @@ static void sasl_step_response_handler(libcouchbase_server_t *server, (void)res; (void)command_cookie; - // I don't have sasl step support yet ;-) + /* I don't have sasl step support yet ;-) */ libcouchbase_error_handler(server->instance, LIBCOUCHBASE_NOT_SUPPORTED, "SASL AUTH CONTINUE not supported yet"); diff --git a/src/instance.c b/src/instance.c index 3259c2512..a34483d4d 100644 --- a/src/instance.c +++ b/src/instance.c @@ -39,7 +39,7 @@ libcouchbase_t libcouchbase_create(const char *host, io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_DEFAULT, NULL, NULL); if (io == NULL) { - // You can't initialize the library without a io-handler! + /* You can't initialize the library without a io-handler! */ return NULL; } } @@ -95,10 +95,10 @@ libcouchbase_t libcouchbase_create(const char *host, ret->sock = -1; - // No error has occurred yet. + /* No error has occurred yet. */ ret->last_error = LIBCOUCHBASE_SUCCESS; - // setup io iops! + /* setup io iops! */ ret->io = io; return ret; @@ -331,9 +331,9 @@ static void libcouchbase_update_serverlist(libcouchbase_t instance) * Try to parse the piece of data we've got available to see if we got all * the data for this "chunk" * @param instance the instance containing the data - * @return true if we got all the data we need, false otherwise + * @return 1 if we got all the data we need, 0 otherwise */ -static bool parse_chunk(libcouchbase_t instance) +static int parse_chunk(libcouchbase_t instance) { buffer_t *buffer = &instance->vbucket_stream.chunk; assert(instance->vbucket_stream.chunk_size != 0); @@ -342,8 +342,8 @@ static bool parse_chunk(libcouchbase_t instance) char *ptr = strstr(buffer->data, "\r\n"); long val; if (ptr == NULL) { - // We need more data! - return false; + /* We need more data! */ + return 0; } ptr += 2; val = strtol(buffer->data, NULL, 16); @@ -355,11 +355,11 @@ static bool parse_chunk(libcouchbase_t instance) } if (buffer->avail < instance->vbucket_stream.chunk_size) { - // need more data! - return false; + /* need more data! */ + return 0; } - return true; + return 1; } /** @@ -400,7 +400,7 @@ static int parse_header(libcouchbase_t instance) } instance->vbucket_stream.header = strdup(buffer->data); - // realign remaining data.. + /* realign remaining data.. */ buffer->avail -= (size_t)(ptr - buffer->data); memmove(buffer->data, ptr, buffer->avail); buffer->data[buffer->avail] = '\0'; @@ -419,12 +419,14 @@ const size_t min_buffer_size = 2048; * * @param buffer the buffer to grow * @param min_free the minimum amount of free space I need - * @return true if success, false otherwise + * @return 1 if success, 0 otherwise */ -bool grow_buffer(buffer_t *buffer, size_t min_free) { +int grow_buffer(buffer_t *buffer, size_t min_free) { if (min_free == 0) { - // no minimum size requested, just ensure that there is at least - // one byte there... + /* + ** no minimum size requested, just ensure that there is at least + ** one byte there... + */ min_free = 1; } @@ -438,14 +440,14 @@ bool grow_buffer(buffer_t *buffer, size_t min_free) { ptr = realloc(buffer->data, next + 1); if (ptr == NULL) { - return false; + return 0; } ptr[next] = '\0'; buffer->data = ptr; buffer->size = next; } - return true; + return 1; } /** @@ -491,7 +493,6 @@ static void vbucket_stream_handler(evutil_socket_t sock, short which, void *arg) do { if (!grow_buffer(buffer, 1)) { - // ERROR MEMORY ALLOCATION! libcouchbase_error_handler(instance, LIBCOUCHBASE_ENOMEM, "Failed to allocate memory"); return ; @@ -507,7 +508,6 @@ static void vbucket_stream_handler(evutil_socket_t sock, short which, void *arg) case EWOULDBLOCK: return ; default: - /* ERROR READING SOCKET!! */ libcouchbase_error_handler(instance, LIBCOUCHBASE_NETWORK_ERROR, strerror(instance->io->error)); return ; @@ -524,17 +524,17 @@ static void vbucket_stream_handler(evutil_socket_t sock, short which, void *arg) if (instance->vbucket_stream.header == NULL) { if (parse_header(instance) == -1) { - // error already reported + /* error already reported */ return; } } if (instance->vbucket_stream.header != NULL) { - bool done; + int done; do { - done = true; + done = 1; if (parse_chunk(instance)) { - // @todo copy the data over to the input buffer there.. + /* @todo copy the data over to the input buffer there.. */ char *term; if (!grow_buffer(&instance->vbucket_stream.input, instance->vbucket_stream.chunk_size)) { @@ -543,11 +543,13 @@ static void vbucket_stream_handler(evutil_socket_t sock, short which, void *arg) memcpy(instance->vbucket_stream.input.data + instance->vbucket_stream.input.avail, buffer->data, instance->vbucket_stream.chunk_size); instance->vbucket_stream.input.avail += instance->vbucket_stream.chunk_size; - // the chunk includes the \r\n at the end.. We shouldn't add that.. + /* the chunk includes the \r\n at the end.. We shouldn't add + ** that.. + */ instance->vbucket_stream.input.avail -= 2; instance->vbucket_stream.input.data[instance->vbucket_stream.input.avail] = '\0'; - // realign buffer + /* realign buffer */ memmove(buffer->data, buffer->data + instance->vbucket_stream.chunk_size, buffer->avail - instance->vbucket_stream.chunk_size); buffer->avail -= instance->vbucket_stream.chunk_size; @@ -560,13 +562,13 @@ static void vbucket_stream_handler(evutil_socket_t sock, short which, void *arg) instance->vbucket_stream.chunk_size = (size_t)-1; if (buffer->avail > 0) { - done = false; + done = 0; } } } while (!done); } - // Make it known that this was a success. + /* Make it known that this was a success. */ libcouchbase_error_handler(instance, LIBCOUCHBASE_SUCCESS, NULL); } @@ -581,11 +583,11 @@ static void libchouchbase_instance_connect_handler(evutil_socket_t sock, short which, void *arg) { libcouchbase_t instance = arg; - bool retry; + int retry; do { if (instance->sock == INVALID_SOCKET) { - // Try to get a socket.. + /* Try to get a socket.. */ while (instance->curr_ai != NULL) { instance->sock = instance->io->socket(instance->io, instance->curr_ai->ai_family, @@ -607,18 +609,17 @@ static void libchouchbase_instance_connect_handler(evutil_socket_t sock, return ; } - retry = false; + retry = 0; if (instance->io->connect(instance->io, instance->sock, instance->curr_ai->ai_addr, (int)instance->curr_ai->ai_addrlen) == 0) { - // connected libcouchbase_instance_connected(instance); return ; } else { switch (instance->io->error) { case EINTR: - retry = true; + retry = 1; break; case EISCONN: libcouchbase_instance_connected(instance); @@ -646,7 +647,7 @@ static void libchouchbase_instance_connect_handler(evutil_socket_t sock, return ; } - retry = true; + retry = 1; instance->curr_ai = instance->curr_ai->ai_next; instance->io->delete_event(instance->io, instance->sock, diff --git a/src/internal.h b/src/internal.h index 736caea34..c060da871 100644 --- a/src/internal.h +++ b/src/internal.h @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -64,7 +63,7 @@ extern "C" { size_t size; size_t avail; } buffer_t; - bool grow_buffer(buffer_t *buffer, size_t min_free); + int grow_buffer(buffer_t *buffer, size_t min_free); /** * Data stored per command in the command-cookie buffer... @@ -158,7 +157,7 @@ extern "C" { struct libcouchbase_histogram_st *histogram; uint32_t seqno; - bool wait; + int wait; const void *cookie; libcouchbase_error_t last_error; @@ -204,7 +203,7 @@ extern "C" { /** The event item representing _this_ object */ void *event; /** Is this server in a connected state (done with sasl auth) */ - bool connected; + int connected; /** The current event handler */ EVENT_HANDLER ev_handler; /* Pointer back to the instance */ diff --git a/src/iofactory.c b/src/iofactory.c index 3bd7408fa..2f4314341 100644 --- a/src/iofactory.c +++ b/src/iofactory.c @@ -29,16 +29,18 @@ typedef libcouchbase_io_opt_t* (*create_func)(struct event_base *base); static create_func get_create_func(const char *image, libcouchbase_error_t *error) { + union my_hack { + create_func create; + void* voidptr; + } my_create ; + void *dlhandle = dlopen(image, RTLD_NOW | RTLD_LOCAL); if (dlhandle == NULL) { set_error(error, LIBCOUCHBASE_ERROR); return NULL; } - union my_hack { - create_func create; - void* voidptr; - } my_create = { .create = NULL }; + my_create.create = NULL; my_create.voidptr = dlsym(dlhandle, "libcouchbase_create_libevent_io_opts"); if (my_create.voidptr == NULL) { dlclose(dlhandle); diff --git a/src/packet.c b/src/packet.c index 5780fb579..c27ece824 100644 --- a/src/packet.c +++ b/src/packet.c @@ -64,7 +64,6 @@ void libcouchbase_server_buffer_end_packet(libcouchbase_server_t *c, { (void)c; (void)buff; - // NOOP } void libcouchbase_server_buffer_complete_packet(libcouchbase_server_t *c, diff --git a/src/plugin-libevent.c b/src/plugin-libevent.c index 79fee41c1..819a13be6 100644 --- a/src/plugin-libevent.c +++ b/src/plugin-libevent.c @@ -226,7 +226,7 @@ static int libcouchbase_io_update_event(struct libcouchbase_io_opt_st *iops, flags |= EV_PERSIST; if (flags == event_get_events(event) && handler == event_get_callback(event)) { - // no change! + /* no change! */ return 0; } @@ -282,7 +282,7 @@ struct libcouchbase_io_opt_st *libcouchbase_create_libevent_io_opts(struct event return NULL; } - // setup io iops! + /* setup io iops! */ ret->recv = libcouchbase_io_recv; ret->send = libcouchbase_io_send; ret->recvv = libcouchbase_io_recvv; diff --git a/src/remove.c b/src/remove.c index 3d8a00c76..71e64ec28 100644 --- a/src/remove.c +++ b/src/remove.c @@ -45,7 +45,7 @@ libcouchbase_error_t libcouchbase_remove_by_key(libcouchbase_t instance, libcouchbase_server_t *server; protocol_binary_request_delete req; - // we need a vbucket config before we can start removing the item.. + /* we need a vbucket config before we can start removing the item.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } diff --git a/src/ringbuffer.c b/src/ringbuffer.c index bae718f20..3e0085e67 100644 --- a/src/ringbuffer.c +++ b/src/ringbuffer.c @@ -22,17 +22,17 @@ static size_t minimum(size_t a, size_t b) return (a < b) ? a : b; } -bool libcouchbase_ringbuffer_initialize(ringbuffer_t *buffer, size_t size) +int libcouchbase_ringbuffer_initialize(ringbuffer_t *buffer, size_t size) { memset(buffer, 0, sizeof(ringbuffer_t)); buffer->root = malloc(size); if (buffer->root == NULL) { - return false; + return 0; } buffer->size = size; buffer->write_head = buffer->root; buffer->read_head = buffer->root; - return true; + return 1; } void libcouchbase_ringbuffer_destruct(ringbuffer_t *buffer) @@ -42,7 +42,7 @@ void libcouchbase_ringbuffer_destruct(ringbuffer_t *buffer) buffer->size = buffer->nbytes = 0; } -bool libcouchbase_ringbuffer_ensure_capacity(ringbuffer_t *buffer, size_t size) +int libcouchbase_ringbuffer_ensure_capacity(ringbuffer_t *buffer, size_t size) { char *new_root; size_t new_size = buffer->size << 1; @@ -51,21 +51,21 @@ bool libcouchbase_ringbuffer_ensure_capacity(ringbuffer_t *buffer, size_t size) } if (size < (buffer->size - buffer->nbytes)) { - // we've got capacity! - return true; + /* we've got capacity! */ + return 1; } - // determine the new buffer size... + /* determine the new buffer size... */ while ((new_size - buffer->nbytes) < size) { new_size <<= 1; } - // go ahead and allocate a bigger block + /* go ahead and allocate a bigger block */ if ((new_root = malloc(new_size)) == NULL) { - // Allocation failed! - return false; + /* Allocation failed! */ + return 0; } else { - // copy the data over :) + /* copy the data over :) */ char *old; size_t nbytes = buffer->nbytes; size_t nr = libcouchbase_ringbuffer_read(buffer, new_root, nbytes); @@ -79,7 +79,7 @@ bool libcouchbase_ringbuffer_ensure_capacity(ringbuffer_t *buffer, size_t size) buffer->read_head = buffer->root; buffer->write_head = buffer->root + nbytes; free(old); - return true; + return 1; } } @@ -113,7 +113,7 @@ size_t libcouchbase_ringbuffer_write(ringbuffer_t *buffer, size_t toWrite; if (buffer->write_head >= buffer->read_head) { - // write up to the end with data.. + /* write up to the end with data.. */ space = buffer->size - (size_t)(buffer->write_head - buffer->root); toWrite = minimum(space, nb); @@ -129,7 +129,7 @@ size_t libcouchbase_ringbuffer_write(ringbuffer_t *buffer, } if (nw == nb) { - // everything is written to the buffer.. + /* everything is written to the buffer.. */ return nw; } @@ -137,7 +137,7 @@ size_t libcouchbase_ringbuffer_write(ringbuffer_t *buffer, s += toWrite; } - // Copy data up until we catch up with the read head + /* Copy data up until we catch up with the read head */ space = (size_t)(buffer->read_head - buffer->write_head); toWrite = minimum(space, nb); if (src != NULL) { @@ -173,7 +173,7 @@ size_t libcouchbase_ringbuffer_read(ringbuffer_t *buffer, void *dest, size_t nb) return 0; } if (buffer->read_head >= buffer->write_head) { - // read up to the wrap point + /* read up to the wrap point */ space = buffer->size - (size_t)(buffer->read_head - buffer->root); toRead = minimum(space, nb); @@ -274,11 +274,11 @@ void libcouchbase_ringbuffer_get_iov(ringbuffer_t *buffer, } } -bool libcouchbase_ringbuffer_is_continous(ringbuffer_t *buffer, +int libcouchbase_ringbuffer_is_continous(ringbuffer_t *buffer, libcouchbase_ringbuffer_direction_t direction, size_t nb) { - bool ret; + int ret; if (direction == RINGBUFFER_READ) { ret = (nb <= buffer->nbytes); @@ -286,7 +286,7 @@ bool libcouchbase_ringbuffer_is_continous(ringbuffer_t *buffer, if (buffer->read_head >= buffer->write_head) { ptrdiff_t chunk = buffer->root + buffer->size - buffer->read_head; if (buffer->nbytes > (size_t)chunk) { - ret = false; + ret = 0; } } } else { @@ -294,14 +294,14 @@ bool libcouchbase_ringbuffer_is_continous(ringbuffer_t *buffer, if (buffer->write_head >= buffer->read_head) { ptrdiff_t chunk = buffer->root + buffer->size - buffer->write_head; if (buffer->nbytes > (size_t)chunk) { - ret = false; + ret = 0; } } } return ret; } -bool libcouchbase_ringbuffer_append(ringbuffer_t *src, ringbuffer_t *dest) +int libcouchbase_ringbuffer_append(ringbuffer_t *src, ringbuffer_t *dest) { char buffer[1024]; size_t nr, nw; @@ -310,15 +310,15 @@ bool libcouchbase_ringbuffer_append(ringbuffer_t *src, ringbuffer_t *dest) sizeof(buffer))) != 0) { if (!libcouchbase_ringbuffer_ensure_capacity(dest, nr)) { abort(); - return false; + return 0; } nw = libcouchbase_ringbuffer_write(dest, buffer, nr); if (nw != nr) { abort(); - return false; + return 0; } } - return true; + return 1; } diff --git a/src/ringbuffer.h b/src/ringbuffer.h index 747b18c0a..6cf0af87f 100644 --- a/src/ringbuffer.h +++ b/src/ringbuffer.h @@ -34,9 +34,9 @@ extern "C" { RINGBUFFER_WRITE = 0x02 } libcouchbase_ringbuffer_direction_t; - bool libcouchbase_ringbuffer_initialize(ringbuffer_t *buffer, size_t size); + int libcouchbase_ringbuffer_initialize(ringbuffer_t *buffer, size_t size); void libcouchbase_ringbuffer_destruct(ringbuffer_t *buffer); - bool libcouchbase_ringbuffer_ensure_capacity(ringbuffer_t *buffer, size_t size); + int libcouchbase_ringbuffer_ensure_capacity(ringbuffer_t *buffer, size_t size); size_t libcouchbase_ringbuffer_get_size(ringbuffer_t *buffer); void *libcouchbase_ringbuffer_get_start(ringbuffer_t *buffer); void *libcouchbase_ringbuffer_get_read_head(ringbuffer_t *buffer); @@ -52,11 +52,11 @@ extern "C" { void libcouchbase_ringbuffer_produced(ringbuffer_t *buffer, size_t nb); void libcouchbase_ringbuffer_consumed(ringbuffer_t *buffer, size_t nb); size_t libcouchbase_ringbuffer_get_nbytes(ringbuffer_t *buffer); - bool libcouchbase_ringbuffer_is_continous(ringbuffer_t *buffer, + int libcouchbase_ringbuffer_is_continous(ringbuffer_t *buffer, libcouchbase_ringbuffer_direction_t direction, size_t nb); - bool libcouchbase_ringbuffer_append(ringbuffer_t *src, ringbuffer_t *dest); + int libcouchbase_ringbuffer_append(ringbuffer_t *src, ringbuffer_t *dest); #ifdef __cplusplus } diff --git a/src/server.c b/src/server.c index ef7d79749..aca38d7b4 100644 --- a/src/server.c +++ b/src/server.c @@ -41,7 +41,7 @@ void libcouchbase_server_destroy(libcouchbase_server_t *server) sasl_dispose(&server->sasl_conn); } - // Delete the event structure itself + /* Delete the event structure itself */ server->instance->io->destroy_event(server->instance->io, server->event); @@ -69,9 +69,9 @@ void libcouchbase_server_destroy(libcouchbase_server_t *server) * @param sock The socket to query the name for * @param buffer The destination buffer * @param buffz The size of the output buffer - * @return true if success, false otherwise + * @return 1 if success, 0 otherwise */ -static bool get_local_address(evutil_socket_t sock, +static int get_local_address(evutil_socket_t sock, char *buffer, size_t bufsz) { @@ -85,10 +85,10 @@ static bool get_local_address(evutil_socket_t sock, p, sizeof(p), NI_NUMERICHOST | NI_NUMERICSERV) < 0) || (snprintf(buffer, bufsz, "%s;%s", h, p) < 0)) { - return false; + return 0; } - return true; + return 1; } /** @@ -96,9 +96,9 @@ static bool get_local_address(evutil_socket_t sock, * @param sock The socket to query the name for * @param buffer The destination buffer * @param buffz The size of the output buffer - * @return true if success, false otherwise + * @return 1 if success, 0 otherwise */ -static bool get_remote_address(evutil_socket_t sock, +static int get_remote_address(evutil_socket_t sock, char *buffer, size_t bufsz) { @@ -112,10 +112,10 @@ static bool get_remote_address(evutil_socket_t sock, p, sizeof(p), NI_NUMERICHOST | NI_NUMERICSERV) < 0) || (snprintf(buffer, bufsz, "%s;%s", h, p) < 0)) { - return false; + return 0; } - return true; + return 1; } /** @@ -134,20 +134,22 @@ static void start_sasl_auth_server(libcouchbase_server_t *server) libcouchbase_server_buffer_complete_packet(server, NULL, &server->output, &server->output_cookies, req.bytes, sizeof(req.bytes)); - // send the data and add it to libevent.. + /* send the data and add it to libevent.. */ libcouchbase_server_event_handler(server->sock, LIBCOUCHBASE_WRITE_EVENT, server); } void libcouchbase_server_connected(libcouchbase_server_t *server) { - server->connected = true; + server->connected = 1; if (server->pending.nbytes > 0) { - // @todo we might want to do this a bit more optimal later on.. - // We're only using the pending ringbuffer while we're - // doing the SASL auth, so it shouldn't contain that - // much data.. + /* + ** @todo we might want to do this a bit more optimal later on.. + ** We're only using the pending ringbuffer while we're + ** doing the SASL auth, so it shouldn't contain that + ** much data.. + */ if (!libcouchbase_ringbuffer_append(&server->pending, &server->output) || !libcouchbase_ringbuffer_append(&server->pending_cookies, &server->output_cookies)) { libcouchbase_error_handler(server->instance, @@ -155,7 +157,7 @@ void libcouchbase_server_connected(libcouchbase_server_t *server) NULL); } - // Send the pending data! + /* Send the pending data! */ libcouchbase_server_event_handler(server->sock, LIBCOUCHBASE_WRITE_EVENT, server); @@ -175,19 +177,19 @@ static void socket_connected(libcouchbase_server_t *server) &server->sasl_conn) == SASL_OK); if (vbucket_config_get_user(server->instance->vbucket_config) == NULL) { - // No SASL AUTH needed + /* No SASL AUTH needed */ libcouchbase_server_connected(server); } else { start_sasl_auth_server(server); } - // Set the correct event handler + /* Set the correct event handler */ server->instance->io->update_event(server->instance->io, server->sock, server->event, LIBCOUCHBASE_READ_EVENT, server, libcouchbase_server_event_handler); } -static bool server_connect(libcouchbase_server_t *server); +static int server_connect(libcouchbase_server_t *server); static void server_connect_handler(evutil_socket_t sock, short which, void *arg) @@ -199,11 +201,11 @@ static void server_connect_handler(evutil_socket_t sock, short which, void *arg) server_connect(server); } -static bool server_connect(libcouchbase_server_t *server) { - bool retry; +static int server_connect(libcouchbase_server_t *server) { + int retry; do { if (server->sock == INVALID_SOCKET) { - // Try to get a socket.. + /* Try to get a socket.. */ while (server->curr_ai != NULL) { server->sock = server->instance->io->socket(server->instance->io, server->curr_ai->ai_family, @@ -217,25 +219,25 @@ static bool server_connect(libcouchbase_server_t *server) { } if (server->curr_ai == NULL) { - return false; + return 0; } - retry = false; + retry = 0; if (server->instance->io->connect(server->instance->io, server->sock, server->curr_ai->ai_addr, (int)server->curr_ai->ai_addrlen) == 0) { - // connected + /* connected */ socket_connected(server); - return true; + return 1; } else { switch (server->instance->io->error) { case EINTR: - retry = true; + retry = 1; break; case EISCONN: socket_connected(server); - return true; + return 1; case EWOULDBLOCK: case EINPROGRESS: /* First call to connect */ server->instance->io->update_event(server->instance->io, @@ -244,21 +246,21 @@ static bool server_connect(libcouchbase_server_t *server) { LIBCOUCHBASE_WRITE_EVENT, server, server_connect_handler); - return true; + return 1; case EALREADY: /* Subsequent calls to connect */ - return true; + return 1; default: if (errno == ECONNREFUSED) { - retry = true; + retry = 1; server->curr_ai = server->curr_ai->ai_next; } else { fprintf(stderr, "Connection failed: %s", strerror(server->instance->io->error)); - // TODO: Is there a better error for this? + /* TODO: Is there a better error for this? */ libcouchbase_error_handler(server->instance, LIBCOUCHBASE_NETWORK_ERROR, "Connection failed"); - return false; + return 0; } server->instance->io->delete_event(server->instance->io, @@ -269,8 +271,8 @@ static bool server_connect(libcouchbase_server_t *server) { } } } while (retry); - // not reached - return false; + /* not reached */ + return 0; } void libcouchbase_server_initialize(libcouchbase_server_t *server, int servernum) @@ -328,7 +330,7 @@ int libcouchbase_server_purge_implicit_responses(libcouchbase_server_t *c, protocol_binary_request_header req; size_t nr = libcouchbase_ringbuffer_peek(&c->cmd_log, req.bytes, sizeof(req)); - // There should at _LEAST_ be _ONE_ message in here! + /* There should at _LEAST_ be _ONE_ message in here! */ assert(nr == sizeof(req)); while (req.request.opaque < seqno) { struct libcouchbase_command_data_st ct; @@ -385,7 +387,7 @@ int libcouchbase_server_purge_implicit_responses(libcouchbase_server_t *c, libcouchbase_ringbuffer_consumed(&c->cmd_log, packetsize); nr = libcouchbase_ringbuffer_peek(&c->cmd_log, req.bytes, sizeof(req)); - // The current message should also be there... + /* The current message should also be there... */ assert(nr == sizeof(req)); } diff --git a/src/stats.c b/src/stats.c index 3d3a85d5b..27b1c794a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -32,7 +32,7 @@ libcouchbase_error_t libcouchbase_server_stats(libcouchbase_t instance, protocol_binary_request_stats req; size_t ii; - // we need a vbucket config before we can start getting data.. + /* we need a vbucket config before we can start getting data.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } diff --git a/src/store.c b/src/store.c index cbf19cfd4..ada163016 100644 --- a/src/store.c +++ b/src/store.c @@ -54,7 +54,7 @@ libcouchbase_error_t libcouchbase_store_by_key(libcouchbase_t instance, size_t headersize; size_t bodylen; - // we need a vbucket config before we can start getting data.. + /* we need a vbucket config before we can start getting data.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } @@ -101,12 +101,12 @@ libcouchbase_error_t libcouchbase_store_by_key(libcouchbase_t instance, headersize -= 8; break; default: - // We were given an unknown storage operation. + /* We were given an unknown storage operation. */ return libcouchbase_error_handler(instance, LIBCOUCHBASE_EINVAL, "Invalid value passed as storage operation"); } - // Make it known that this was a success. + /* Make it known that this was a success. */ libcouchbase_error_handler(instance, LIBCOUCHBASE_SUCCESS, NULL); bodylen = nkey + nbytes + req.message.header.request.extlen; diff --git a/src/tap.c b/src/tap.c index e8936d111..b90cad8b8 100644 --- a/src/tap.c +++ b/src/tap.c @@ -28,7 +28,7 @@ struct libcouchbase_tap_filter_st { /** Represents the oldest entry (from epoch) you're interested in */ uint64_t backfill; /** If true, notifies the tap server that we don't care about values */ - bool keys_only; + int keys_only; }; /** @@ -43,9 +43,9 @@ libcouchbase_tap_filter_t libcouchbase_tap_filter_create() return NULL; } - // Set the defaults. + /* Set the defaults. */ ret->backfill = 0; - ret->keys_only = false; + ret->keys_only = 0; return ret; } @@ -89,12 +89,12 @@ uint64_t libcouchbase_tap_filter_get_backfill(libcouchbase_tap_filter_t instance * Set whether you are interested in keys and values, or only keys in your * tap stream. * @param instance the tap filter instance to modify. - * @param keys_only true if you are only interested in keys, false if + * @param keys_only 1 if you are only interested in keys, 0 if * you also want values. */ LIBCOUCHBASE_API void libcouchbase_tap_filter_set_keys_only(libcouchbase_tap_filter_t instance, - bool keys_only) + int keys_only) { instance->keys_only = keys_only; } @@ -105,7 +105,7 @@ void libcouchbase_tap_filter_set_keys_only(libcouchbase_tap_filter_t instance, * @param instance the tap filter instance to retrieve the value from. */ LIBCOUCHBASE_API -bool libcouchbase_tap_filter_get_keys_only(libcouchbase_tap_filter_t instance) +int libcouchbase_tap_filter_get_keys_only(libcouchbase_tap_filter_t instance) { return instance->keys_only; } @@ -114,7 +114,7 @@ static void tap_vbucket_state_listener(libcouchbase_server_t *server) { libcouchbase_t instance = server->instance; libcouchbase_tap_filter_t filter = instance->tap.filter; - // Locate this index: + /* Locate this index: */ size_t idx; size_t bodylen; uint16_t total = 0; @@ -132,7 +132,7 @@ static void tap_vbucket_state_listener(libcouchbase_server_t *server) } assert(idx != instance->nservers); - // Count the numbers of vbuckets for this server: + /* Count the numbers of vbuckets for this server: */ for (ii = 0; ii < instance->nvbuckets; ++ii) { if (instance->vb_server_map[ii] == idx) { ++total; @@ -163,12 +163,12 @@ static void tap_vbucket_state_listener(libcouchbase_server_t *server) libcouchbase_server_start_packet(server, NULL, req.bytes, sizeof(req.bytes)); - // Write the backfill value. + /* Write the backfill value. */ if (filter && filter->backfill != 0) { libcouchbase_server_write_packet(server, &backfill, sizeof(backfill)); } - // Write the vbucket list. + /* Write the vbucket list. */ val = htons(total); libcouchbase_server_write_packet(server, &val, sizeof(val)); for (ii = 0; ii < instance->nvbuckets; ++ii) { @@ -186,10 +186,10 @@ LIBCOUCHBASE_API void libcouchbase_tap_cluster(libcouchbase_t instance, const void *command_cookie, libcouchbase_tap_filter_t filter, - bool block) + int block) { (void)command_cookie; - // connect to the upstream server. + /* connect to the upstream server. */ instance->vbucket_state_listener = tap_vbucket_state_listener; instance->tap.filter = filter; diff --git a/src/timings.c b/src/timings.c index c760c59c4..cc5c8d486 100644 --- a/src/timings.c +++ b/src/timings.c @@ -84,8 +84,10 @@ libcouchbase_error_t libcouchbase_get_timings(libcouchbase_t instance, } max = instance->histogram->max; - // @todo I should merge "empty" sets.. currently I'm only going to report the - // nonzero ones... + /* + ** @todo I should merge "empty" sets.. currently I'm only going to + ** report the nonzero ones... + */ if (instance->histogram->nsec) { callback(instance, cookie, LIBCOUCHBASE_TIMEUNIT_NSEC, 0, 999, instance->histogram->nsec, max); diff --git a/src/touch.c b/src/touch.c index a695a63c4..7d068b2a3 100644 --- a/src/touch.c +++ b/src/touch.c @@ -51,7 +51,7 @@ libcouchbase_error_t libcouchbase_mtouch_by_key(libcouchbase_t instance, libcouchbase_server_t *server = NULL; size_t ii; - // we need a vbucket config before we can start getting data.. + /* we need a vbucket config before we can start getting data.. */ if (instance->vbucket_config == NULL) { return LIBCOUCHBASE_ETMPFAIL; } @@ -79,7 +79,7 @@ libcouchbase_error_t libcouchbase_mtouch_by_key(libcouchbase_t instance, req.message.header.request.vbucket = ntohs(vb); req.message.header.request.bodylen = ntohl((uint32_t)(nkey[ii]) + 4); req.message.header.request.opaque = ++instance->seqno; - // @todo fix the relative time! + /* @todo fix the relative time! */ req.message.body.expiration = htonl((uint32_t)exp[ii]); libcouchbase_server_start_packet(server, command_cookie, req.bytes, sizeof(req.bytes)); diff --git a/src/views.c b/src/views.c index c8262eeab..e683784e5 100644 --- a/src/views.c +++ b/src/views.c @@ -125,14 +125,14 @@ static void on_data_cb(struct evhttp_request *req, void *arg) * * libcouchbase_make_doc_request(instance, NULL, "_all_docs?limit=10", * LIBCOUCHBASE_HTTP_METHOD_GET, - * NULL, 0, true); + * NULL, 0, 1); * * @example Filter first 10 docs using POST request * * const char body[] = "{\"keys\": [\"test_1000\", \"test_10002\"]}" * libcouchbase_make_doc_request(instance, NULL, "_all_docs?limit=10", * LIBCOUCHBASE_HTTP_METHOD_GET, - * body, sizeof(body), true); + * body, sizeof(body), 1); */ LIBCOUCHBASE_API libcouchbase_error_t libcouchbase_make_doc_request(libcouchbase_t instance, @@ -141,7 +141,7 @@ libcouchbase_error_t libcouchbase_make_doc_request(libcouchbase_t instance, libcouchbase_http_method_t method, const void *body, size_t nbody, - bool chunked) + int chunked) { struct view_context_st *ctx; const char *hostname; @@ -195,7 +195,7 @@ libcouchbase_error_t libcouchbase_make_doc_request(libcouchbase_t instance, return LIBCOUCHBASE_EINVAL; } - // @TODO FIXME! + /* @TODO FIXME! */ ctx->conn = evhttp_connection_base_new(instance->io->cookie, NULL, hostname, (uint16_t)port); if (!ctx->conn) { view_context_free(ctx); diff --git a/src/wait.c b/src/wait.c index b0557a093..91254d790 100644 --- a/src/wait.c +++ b/src/wait.c @@ -36,9 +36,9 @@ void libcouchbase_wait(libcouchbase_t instance) * The API is designed for you to run your own event loop, * but should also work if you don't do that.. In order to be * able to know when to break out of the event loop, we're setting - * the wait flag to true + * the wait flag to 1 */ - instance->wait = true; + instance->wait = 1; if (instance->vbucket_config == NULL) { vbucket_state_listener_t old = instance->vbucket_state_listener; instance->vbucket_state_listener = breakout_vbucket_state_listener; @@ -47,5 +47,5 @@ void libcouchbase_wait(libcouchbase_t instance) } else { instance->io->run_event_loop(instance->io); } - instance->wait = false; + instance->wait = 0; } diff --git a/tests/arithmetic.c b/tests/arithmetic.c index 292954958..334dbb1b6 100644 --- a/tests/arithmetic.c +++ b/tests/arithmetic.c @@ -42,20 +42,20 @@ static void storage_callback(libcouchbase_t instance, static void initialize_counter(const char *host, const char *user, const char *passwd, const char *bucket) { + libcouchbase_t instance; + struct libcouchbase_io_opt_st *io; struct event_base *evbase = event_base_new(); if (evbase == NULL) { fprintf(stderr, "Failed to create event base\n"); exit(1); } - struct libcouchbase_io_opt_st *io; io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_LIBEVENT, evbase, NULL); if (io == NULL) { fprintf(stderr, "Failed to create IO instance\n"); exit(1); } - libcouchbase_t instance = libcouchbase_create(host, user, passwd, bucket, - io); + instance = libcouchbase_create(host, user, passwd, bucket, io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); event_base_free(evbase); @@ -68,7 +68,7 @@ static void initialize_counter(const char *host, const char *user, exit(1); } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_storage_callback(instance, storage_callback); @@ -99,20 +99,21 @@ static void arithmetic_callback(libcouchbase_t instance, static void do_run_arithmetic(const char *host, const char *user, const char *passwd, const char *bucket) { + int ii; + libcouchbase_t instance; + struct libcouchbase_io_opt_st *io; struct event_base *evbase = event_base_new(); if (evbase == NULL) { fprintf(stderr, "Failed to create event base\n"); exit(1); } - struct libcouchbase_io_opt_st *io; io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_LIBEVENT, evbase, NULL); if (io == NULL) { fprintf(stderr, "Failed to create IO instance\n"); exit(1); } - libcouchbase_t instance = libcouchbase_create(host, user, passwd, bucket, - io); + instance = libcouchbase_create(host, user, passwd, bucket, io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); event_base_free(evbase); @@ -125,14 +126,14 @@ static void do_run_arithmetic(const char *host, const char *user, exit(1); } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); (void)libcouchbase_set_arithmetic_callback(instance, arithmetic_callback); - for (int ii = 0; ii < 10; ++ii) { - libcouchbase_arithmetic(instance, NULL, "counter", 7, 1, 0, true, 0); + for (ii = 0; ii < 10; ++ii) { + libcouchbase_arithmetic(instance, NULL, "counter", 7, 1, 0, 1, 0); libcouchbase_wait(instance); } @@ -142,18 +143,22 @@ static void do_run_arithmetic(const char *host, const char *user, int main(int argc, char **argv) { + const void *mock; + const char *http; + int ii; + (void)argc; (void)argv; - const void *mock = start_mock_server(NULL); + mock = start_mock_server(NULL); if (mock == NULL) { fprintf(stderr, "Failed to start mock server\n"); return 1; } - const char *http = get_mock_http_server(mock); + http = get_mock_http_server(mock); initialize_counter(http, "Administrator", "password", NULL); - for (int ii = 0; ii < 10; ++ii) { + for (ii = 0; ii < 10; ++ii) { do_run_arithmetic(http, "Administrator", "password", NULL); } diff --git a/tests/ringbuffer-test.c b/tests/ringbuffer-test.c index d06084e8b..2759da718 100644 --- a/tests/ringbuffer-test.c +++ b/tests/ringbuffer-test.c @@ -16,7 +16,6 @@ */ #include "config.h" -#include #include #include #include diff --git a/tests/server.c b/tests/server.c index 02ccf48df..82c309dda 100644 --- a/tests/server.c +++ b/tests/server.c @@ -52,14 +52,17 @@ struct mock_server_info { int client; }; -static bool create_monitor(struct mock_server_info *info) { - struct addrinfo hints = { .ai_flags = AI_PASSIVE, - .ai_family = AF_UNSPEC, - .ai_socktype = SOCK_STREAM }; - info->sock = -1; +static int create_monitor(struct mock_server_info *info) { + struct addrinfo hints, *next, *ai; + int error; + + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; - struct addrinfo *ai; - int error = getaddrinfo(NULL, "0", &hints, &ai); + info->sock = -1; + error = getaddrinfo(NULL, "0", &hints, &ai); if (error != 0) { if (error != EAI_SYSTEM) { fprintf(stderr, "getaddrinfo failed: %s\n", @@ -67,17 +70,19 @@ static bool create_monitor(struct mock_server_info *info) { } else { perror("getaddrinfo failed:"); } - return false; + return 0; } - for (struct addrinfo *next = ai; next; next = next->ai_next) { + for (next = ai; next; next = next->ai_next) { + int flags = 1; + socklen_t len; + if ((info->sock = socket(next->ai_family, next->ai_socktype, next->ai_protocol)) == -1) { continue; } - int flags = 1; setsockopt(info->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)); @@ -91,8 +96,8 @@ static bool create_monitor(struct mock_server_info *info) { continue; } - // Ok, I've got a working socket :) - socklen_t len = sizeof(info->storage); + /* Ok, I've got a working socket :) */ + len = sizeof(info->storage); if (getsockname(info->sock, (struct sockaddr*)&info->storage, &len) == -1) { close(info->sock); info->sock = -1; @@ -109,15 +114,17 @@ static bool create_monitor(struct mock_server_info *info) { return info->sock != -1; } - static void wait_for_server(const char *port) { - struct addrinfo hints = { .ai_flags = AI_PASSIVE, - .ai_family = AF_UNSPEC, - .ai_socktype = SOCK_STREAM }; + struct addrinfo hints, *next, *ai; int sock = -1; + int error; - struct addrinfo *ai; - int error = getaddrinfo("localhost", port, &hints, &ai); + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + error = getaddrinfo("localhost", port, &hints, &ai); if (error != 0) { if (error != EAI_SYSTEM) { fprintf(stderr, "getaddrinfo failed: %s\n", @@ -128,8 +135,8 @@ static void wait_for_server(const char *port) { abort(); } - while (true) { - for (struct addrinfo *next = ai; next; next = next->ai_next) { + while (1) { + for (next = ai; next; next = next->ai_next) { if ((sock = socket(next->ai_family, next->ai_socktype, next->ai_protocol)) == -1) { @@ -164,10 +171,10 @@ const void *start_mock_server(char **cmdline) { if (info->pid == 0) { /* Child */ + char monitor[1024]; char *argv[1024]; int arg = 0; argv[arg++] = (char*)"./tests/start_mock.sh"; - char monitor[1024]; sprintf(monitor, "--harakiri-monitor=localhost:%d", info->port); argv[arg++] = monitor; @@ -179,20 +186,25 @@ const void *start_mock_server(char **cmdline) { } argv[arg++] = NULL; - assert(execv(argv[0], argv) != -1); + execv(argv[0], argv); + abort(); + } else { + char buffer[1024]; + ssize_t offset; + ssize_t nr; + + /* wait until the server connects */ + info->client = accept(info->sock, NULL, NULL); + assert(info->client != -1); + /* Get the port number of the http server */ + offset = snprintf(buffer, sizeof(buffer), "localhost:"); + nr = recv(info->client, buffer + offset, + sizeof(buffer) - (size_t)offset - 1, 0); + assert(nr > 0); + buffer[nr + offset] = '\0'; + info->http = strdup(buffer); + wait_for_server(buffer + offset); } - - // wait until the server connects - info->client = accept(info->sock, NULL, NULL); - assert(info->client != -1); - // Get the port number of the http server - char buffer[1024]; - ssize_t offset = snprintf(buffer, sizeof(buffer), "localhost:"); - ssize_t nr = recv(info->client, buffer + offset, sizeof(buffer) - (size_t)offset - 1, 0); - assert(nr > 0); - buffer[nr + offset] = '\0'; - info->http = strdup(buffer); - wait_for_server(buffer + offset); return info; } diff --git a/tests/server.h b/tests/server.h index a352c15cb..543ec7cfb 100644 --- a/tests/server.h +++ b/tests/server.h @@ -17,8 +17,6 @@ #ifndef LIBCOUCHBASE_TEST_SERVER_H #define LIBCOUCHBASE_TEST_SERVER_H 1 -#include - const void *start_mock_server(char **cmdline); const char *get_mock_http_server(const void *); void shutdown_mock_server(const void *); diff --git a/tests/timings-test.c b/tests/timings-test.c index c586f7a28..1fda397de 100644 --- a/tests/timings-test.c +++ b/tests/timings-test.c @@ -14,8 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// Include config.h to get the definition of hrtime_t for -// platforms without it... + +/* Include config.h to get the definition of hrtime_t for platforms +** without it... +*/ #include "config.h" #include @@ -53,6 +55,8 @@ static void timings_callback(libcouchbase_t instance, uint32_t maxtotal) { FILE *fp = (void*)cookie; + int num, ii; + fprintf(fp, "[%3u - %3u]", min, max); switch (timeunit) { case LIBCOUCHBASE_TIMEUNIT_NSEC: @@ -71,10 +75,10 @@ static void timings_callback(libcouchbase_t instance, ; } - int num = (int)((float)20.0 * (float)total / (float)maxtotal); + num = (int)((float)20.0 * (float)total / (float)maxtotal); fprintf(fp, " |"); - for (int ii = 0; ii < num; ++ii) { + for (ii = 0; ii < num; ++ii) { fprintf(fp, "#"); } @@ -86,36 +90,42 @@ static void timings_callback(libcouchbase_t instance, int main(int argc, char **argv) { + FILE *fp; + struct event_base *evbase; + const void *mock; + const char *http; + struct libcouchbase_io_opt_st *io; + libcouchbase_t instance; + int ii; + (void)argc; (void)argv; - FILE *fp = stdout; + fp = stdout; if (getenv("LIBCOUCHBASE_VERBOSE_TESTS") == NULL) { fp = fopen("/dev/null", "w"); } - struct event_base *evbase = event_base_new(); + evbase = event_base_new(); if (evbase == NULL) { fprintf(stderr, "Failed to create event base\n"); return 1; } - const void *mock = start_mock_server(NULL); + mock = start_mock_server(NULL); if (mock == NULL) { fprintf(stderr, "Failed to start mock server\n"); return 1; } - const char *http = get_mock_http_server(mock); + http = get_mock_http_server(mock); - struct libcouchbase_io_opt_st *io; io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_LIBEVENT, evbase, NULL); if (io == NULL) { fprintf(stderr, "Failed to create IO instance\n"); return 1; } - libcouchbase_t instance = libcouchbase_create(http, "Administrator", - "password", NULL, io); - + instance = libcouchbase_create(http, "Administrator", + "password", NULL, io); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); event_base_free(evbase); @@ -129,15 +139,15 @@ int main(int argc, char **argv) return 1; } - // Wait for the connect to compelete + /* Wait for the connect to compelete */ libcouchbase_wait(instance); libcouchbase_enable_timings(instance); libcouchbase_store(instance, NULL, LIBCOUCHBASE_SET, "counter", 7, "0", 1, 0, 0, 0); libcouchbase_wait(instance); - for (int ii = 0; ii < 100; ++ii) { - libcouchbase_arithmetic(instance, NULL, "counter", 7, 1, 0, true, 0); + for (ii = 0; ii < 100; ++ii) { + libcouchbase_arithmetic(instance, NULL, "counter", 7, 1, 0, 1, 0); libcouchbase_wait(instance); } fprintf(fp, " +---------+---------+\n");