Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed compile errors from gcc

  • Loading branch information...
commit d3dd0bb0849b029ee42a3a2834cc91c5c5289b20 1 parent 84ba839
@trondn trondn authored committed
Showing with 102 additions and 108 deletions.
  1. +6 −5 boxmuller.c
  2. +6 −0 boxmuller.h
  3. +32 −47 libmemc.c
  4. +50 −52 main.c
  5. +8 −4 metrics.c
View
11 boxmuller.c
@@ -10,16 +10,17 @@
*/
#include <math.h>
#include <stdlib.h>
+#include "boxmuller.h"
double box_muller(double m, double s) /* normal random variate generator */
{ /* mean m, standard deviation s */
- double x1, x2, w, y1;
+ double x1, x2, w, _y1;
static double y2;
static int use_last = 0;
if (use_last) /* use value from previous call */
{
- y1 = y2;
+ _y1 = y2;
use_last = 0;
}
else
@@ -31,12 +32,12 @@ double box_muller(double m, double s) /* normal random variate generator */
} while ( w >= 1.0 );
w = sqrt( (-2.0 * log( w ) ) / w );
- y1 = x1 * w;
+ _y1 = x1 * w;
y2 = x2 * w;
use_last = 1;
}
-
- double result = ( m + y1 * s );
+
+ double result = ( m + _y1 * s );
return result;
}
View
6 boxmuller.h
@@ -0,0 +1,6 @@
+#ifndef BOX_MULLER_H
+#define BOX_MULLER_H 1
+
+extern double box_muller(double m, double s);
+
+#endif
View
79 libmemc.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* CDDL HEADER START
*
@@ -25,7 +26,7 @@
#include "libmemc.h"
-#if HAVE_PROTOCOL_BINARY
+#ifdef HAVE_MEMCACHED_PROTOCOL_BINARY_H
#include <memcached/protocol_binary.h>
#endif
#include <sys/types.h>
@@ -47,7 +48,7 @@ struct Server {
const char *errmsg;
const char *peername;
char *buffer;
- int buffersize;
+ size_t buffersize;
};
enum StoreCommand {add, set, replace};
@@ -148,15 +149,14 @@ int libmemc_get(struct Memcache *handle, struct Item *item) {
static struct addrinfo *lookuphost(const char *hostname, in_port_t port)
{
struct addrinfo *ai = 0;
- struct addrinfo hints = {0};
+ struct addrinfo hints = {
+ .ai_flags = AI_PASSIVE|AI_ADDRCONFIG,
+ .ai_family = AF_UNSPEC,
+ .ai_protocol = IPPROTO_TCP,
+ .ai_socktype = SOCK_STREAM };
char service[NI_MAXSERV];
int error;
- hints.ai_flags = AI_PASSIVE|AI_ADDRCONFIG;
- hints.ai_family = AF_UNSPEC;
- hints.ai_protocol = IPPROTO_TCP;
- hints.ai_socktype = SOCK_STREAM;
-
(void)snprintf(service, NI_MAXSERV, "%d", port);
if ((error = getaddrinfo(hostname, service, &hints, &ai)) != 0) {
if (error != EAI_SYSTEM) {
@@ -238,8 +238,6 @@ static int libmemc_store(struct Memcache* handle, enum StoreCommand cmd,
static size_t server_receive(struct Server* server, char* data, size_t size, int line);
static int server_sendv(struct Server* server, struct iovec *iov, int iovcnt);
-static int server_send(struct Server* server, const void *data, size_t size);
-static int server_connect(struct Server *server);
static void server_disconnect(struct Server *server);
void server_destroy(struct Server *server) {
@@ -314,26 +312,6 @@ static int server_connect(struct Server *server)
return 0;
}
-static int server_send(struct Server* server, const void *data, size_t size) {
- size_t offset = 0;
- do {
- ssize_t sent = send(server->sock, ((const char*)data) + offset, size - offset, 0);
- if (sent == -1) {
- if (errno != EINTR) {
- char errmsg[1024];
- sprintf(errmsg, "Failed to send data to server: %s", strerror(errno));
- server->errmsg = strdup(errmsg);
- server_disconnect(server);
- return -1;
- }
- } else {
- offset += sent;
- }
- } while (offset < size);
-
- return 0;
-}
-
static int server_sendv(struct Server* server, struct iovec *iov, int iovcnt) {
#ifdef WIN32
// @todo I might have a scattered IO function on windows...
@@ -361,12 +339,12 @@ static int server_sendv(struct Server* server, struct iovec *iov, int iovcnt) {
return -1;
}
} else {
- if (sent == size) {
+ if ((size_t)sent == size) {
return 0;
}
for (int ii = 0; ii < iovcnt && sent > 0; ++ii) {
- if (iov[ii].iov_len < sent) {
+ if (iov[ii].iov_len < (size_t)sent) {
size -= iov[ii].iov_len;
sent -= iov[ii].iov_len;
iov[ii].iov_len = 0;
@@ -415,7 +393,7 @@ static size_t server_receive(struct Server* server, char* data, size_t size, int
return offset;
}
-
+#ifdef HAVE_MEMCACHED_PROTOCOL_BINARY_H
/* Byte swap a 64-bit number */
static int64_t swap64(int64_t in) {
#ifndef __sparc
@@ -433,14 +411,18 @@ static int64_t swap64(int64_t in) {
return in;
#endif
}
-
+#endif
/**
* Implementation of the Binary protocol
*/
static int binary_get(struct Server* server, struct Item* item)
{
-#if HAVE_PROTOCOL_BINARY
+#ifndef HAVE_MEMCACHED_PROTOCOL_BINARY_H
+ (void)server;
+ (void)item;
+ return -1;
+#else
uint16_t keylen = item->keylen;
uint32_t bodylen = keylen;
@@ -490,23 +472,23 @@ static int binary_get(struct Server* server, struct Item* item)
if (response.message.header.response.extlen != 0) {
assert(response.message.header.response.extlen == 4);
uint32_t flags;
- struct iovec iovec[2];
- iovec[0].iov_base = (void*)&flags;
- iovec[0].iov_len = sizeof(flags);
- iovec[1].iov_base = item->data;
- iovec[1].iov_len = item->size;
+ struct iovec iov[2];
+ iov[0].iov_base = (void*)&flags;
+ iov[0].iov_len = sizeof(flags);
+ iov[1].iov_base = item->data;
+ iov[1].iov_len = item->size;
- ssize_t nread = readv(server->sock, iovec, 2);
+ nread = readv(server->sock, iovec, 2);
if (nread < bodylen) {
// partial read.. read the rest!
nread -= 4;
size_t left = item->size - nread;
- if (server_receive(server, item->data + nread, left, 0) != left) {
+ if (server_receive(server, (char*)(item->data) + nread, left, 0) != left) {
abort();
}
}
} else {
- size_t nread = server_receive(server, item->data, item->size, 0);
+ nread = server_receive(server, item->data, item->size, 0);
assert(nread == item->size);
}
@@ -527,14 +509,18 @@ static int binary_get(struct Server* server, struct Item* item)
return 0;
#endif
- return -1;
}
static int binary_store(struct Server* server,
enum StoreCommand cmd,
const struct Item *item)
{
-#if HAVE_PROTOCOL_BINARY
+#ifndef HAVE_MEMCACHED_PROTOCOL_BINARY_H
+ (void)server;
+ (void)cmd;
+ (void)item;
+ return -1;
+#else
protocol_binary_request_set request = { .bytes = {0} };
request.message.header.request.magic = PROTOCOL_BINARY_REQ;
@@ -593,13 +579,12 @@ static int binary_store(struct Server* server,
return -1;
}
- size_t nread = server_receive(server, buffer, len, 0);
+ nread = server_receive(server, buffer, len, 0);
free(buffer);
}
return (response.message.header.response.status == 0) ? 0 : -1;
#endif
- return -1;
}
/**
View
102 main.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* CDDL HEADER START
*
@@ -46,6 +47,7 @@
#include "libmemc.h"
#include "metrics.h"
+#include "boxmuller.h"
#ifndef MAXINT
/* I couldn't find MAXINT on my MacOSX box.. I should update this... */
@@ -199,8 +201,6 @@ struct connection {
void *handle;
};
-extern double box_muller(double m, double s);
-
/**
* Create a handle to a memcached library
*/
@@ -297,21 +297,21 @@ static void release_memcached_handle(void *handle) {
* Set a key / value pair on the memcached server
* @param handle Thandle to the memcached library to use
* @param key The items key
- * @param keylength The length of the key
+ * @param nkey The length of the key
* @param data The data to set
* @param The size of the data to set
* @return 0 on success -1 otherwise
*/
static inline int memcached_set_wrapper(struct connection *connection,
- const char *key,
- int keylength, const void *data, int size) {
+ const char *key, int nkey,
+ const void *data, int size) {
struct memcachelib* lib = (struct memcachelib*) connection->handle;
switch (lib->type) {
#ifdef HAVE_LIBMEMCACHED
case LIBMEMCACHED_BINARY: /* FALLTHROUGH */
case LIBMEMCACHED_TEXTUAL:
{
- int rc = memcached_set(lib->handle, key, keylength, data, size, 0, 0);
+ int rc = memcached_set(lib->handle, key, nkey, data, size, 0, 0);
if (rc != MEMCACHED_SUCCESS) {
return -1;
}
@@ -321,12 +321,13 @@ static inline int memcached_set_wrapper(struct connection *connection,
case LIBMEMC_BINARY:
case LIBMEMC_TEXTUAL:
{
- struct Item mitem = {0};
- mitem.key = key;
- mitem.keylen = keylength;
- /* Set will not modify data */
- mitem.data = (void*) data;
- mitem.size = size;
+ struct Item mitem = {
+ .key = key,
+ .keylen = nkey,
+ /* Set will not modify data */
+ .data = (void*)data,
+ .size = size
+ };
if (libmemc_set(lib->handle, &mitem) != 0) {
return -1;
}
@@ -343,14 +344,13 @@ static inline int memcached_set_wrapper(struct connection *connection,
* Get the value for a key from the memcached server
* @param connection the connection to use
* @param key The items key
- * @param keylength The length of the key
+ * @param nkey The length of the key
* @param The size of the data
* @return pointer to the data on success, -1 otherwise
* TODO: the return of -1 isn't really true
*/
static inline void *memcached_get_wrapper(struct connection* connection,
- const char *key,
- int keylength, size_t *size) {
+ const char *key, int nkey, size_t *size) {
struct memcachelib* lib = (struct memcachelib*) connection->handle;
void *ret = NULL;
switch (lib->type) {
@@ -360,7 +360,7 @@ static inline void *memcached_get_wrapper(struct connection* connection,
{
memcached_return rc;
uint32_t flags;
- ret = memcached_get(lib->handle, key, keylength, size, &flags, &rc);
+ ret = memcached_get(lib->handle, key, nkey, size, &flags, &rc);
if (rc != MEMCACHED_SUCCESS) {
return NULL;
}
@@ -370,9 +370,10 @@ static inline void *memcached_get_wrapper(struct connection* connection,
case LIBMEMC_BINARY:
case LIBMEMC_TEXTUAL:
{
- struct Item mitem = {0};
- mitem.key = key;
- mitem.keylen = keylength;
+ struct Item mitem = {
+ .key = key,
+ .keylen = nkey
+ };
if (libmemc_get(lib->handle, &mitem) != 0) {
return NULL;
@@ -392,7 +393,7 @@ static inline void *memcached_get_wrapper(struct connection* connection,
static struct connection* connectionpool;
-static int connection_pool_size = 1;
+static size_t connection_pool_size = 1;
static int thread_bind_connection = 0;
static int create_connection_pool(void) {
@@ -401,7 +402,7 @@ static int create_connection_pool(void) {
return -1;
}
- for (int ii = 0; ii < connection_pool_size; ++ii) {
+ for (size_t ii = 0; ii < connection_pool_size; ++ii) {
if (pthread_mutex_init(&connectionpool[ii].mutex, NULL) != 0) {
abort();
}
@@ -413,7 +414,7 @@ static int create_connection_pool(void) {
}
static void destroy_connection_pool(void) {
- for (int ii = 0; ii < connection_pool_size; ++ii) {
+ for (size_t ii = 0; ii < connection_pool_size; ++ii) {
pthread_mutex_destroy(&connectionpool[ii].mutex);
release_memcached_handle(connectionpool[ii].handle);
}
@@ -451,19 +452,19 @@ static void release_connection(struct connection *connection) {
* @param size the size of the buffer
* @return buffer
*/
-const char* hrtime2text(hrtime_t time, char *buffer, size_t size) {
+static const char* hrtime2text(hrtime_t t, char *buffer, size_t size) {
const char * const extensions[] = {"ns", "us", "ms", "s" }; //TODO: get a greek Mu in here correctly
int id = 0;
- while (time > 9999) {
+ while (t > 9999) {
++id;
- time /= 1000;
+ t /= 1000;
if (id > 3) {
break;
}
}
- snprintf(buffer, size, "%d %s", (int) time, extensions[id]);
+ snprintf(buffer, size, "%d %s", (int) t, extensions[id]);
buffer[size - 1] = '\0';
return buffer;
}
@@ -475,7 +476,7 @@ const char* hrtime2text(hrtime_t time, char *buffer, size_t size) {
* @param size the size of the buffer
* @return buffer
*/
-const char* timeval2text(struct timeval* val, char *buffer, size_t size) {
+static const char* timeval2text(struct timeval* val, char *buffer, size_t size) {
snprintf(buffer, size, "%2ld.%06lu", (long) val->tv_sec,
(long) val->tv_usec);
@@ -486,7 +487,7 @@ const char* timeval2text(struct timeval* val, char *buffer, size_t size) {
* Initialize the dataset to work on
* @return 0 if success, -1 if memory allocation fails
*/
-static int initialize_dataset() {
+static int initialize_dataset(void) {
uint64_t total = 0;
if (datablock.data != NULL) {
@@ -565,7 +566,7 @@ static int populate_dataset(struct report *rep) {
* the result
* @return arg
*/
-void *populate_thread_main(void* arg) {
+static void *populate_thread_main(void* arg) {
if (populate_dataset((struct report*) arg) == 0) {
return arg;
} else {
@@ -578,7 +579,7 @@ void *populate_thread_main(void* arg) {
* @param no_threads the number of theads to use
* @return 0 if success, -1 otherwise
*/
-int populate_data(int no_threads) {
+static int populate_data(int no_threads) {
int ret = 0;
if (no_threads > 1) {
pthread_t *threads = calloc(sizeof (pthread_t), no_threads);
@@ -628,7 +629,7 @@ int populate_data(int no_threads) {
}
-struct item get_setval(void) {
+static struct item get_setval(void) {
struct item ret = { .key = NULL, .keylen = 0, .size = 0 };
if (keyarray != 0) {
@@ -695,14 +696,14 @@ static int test(struct report *rep) {
rep->bestGet = rep->bestSet = 99999999;
rep->worstGet = rep->worstSet = 0;
- for (int ii = 0; ii < rep->total; ++ii) {
+ for (size_t ii = 0; ii < rep->total; ++ii) {
connection = get_connection();
struct item item = get_setval();
// Ensure that the item is paged in..
- for (int ii = 0; ii < item.keylen; ++ii) {
- if (item.key[ii] == '\0' || item.key[ii] == '\n') {
+ for (size_t jj = 0; jj < item.keylen; ++jj) {
+ if (item.key[jj] == '\0' || item.key[jj] == '\n') {
abort();
}
}
@@ -761,8 +762,8 @@ static int test(struct report *rep) {
free(data);
} else {
fprintf(stderr, "missing data for <");
- for (int ii = 0; ii < item.keylen; ++ii) {
- fprintf(stderr, "%c", item.key[ii]);
+ for (size_t jj = 0; jj < item.keylen; ++jj) {
+ fprintf(stderr, "%c", item.key[jj]);
}
fprintf(stderr, ">\n");
// record_error(TX_GET, delta);
@@ -781,7 +782,7 @@ static int test(struct report *rep) {
* the result
* @return arg
*/
-void *test_thread_main(void* arg) {
+static void *test_thread_main(void* arg) {
test((struct report*) arg);
return arg;
}
@@ -790,7 +791,7 @@ void *test_thread_main(void* arg) {
* Add a host into the list of memcached servers to use
* @param hostname the hostname:port to connect to
*/
-void add_host(const char *hostname) {
+static void add_host(const char *hostname) {
struct host *entry = malloc(sizeof (struct host));
if (entry == 0) {
fprintf(stderr, "Failed to allocate memory for <%s>. Host ignored\n",
@@ -810,17 +811,16 @@ void add_host(const char *hostname) {
}
}
-struct addrinfo *lookuphost(const char *hostname, in_port_t port) {
+static struct addrinfo *lookuphost(const char *hostname, in_port_t port) {
struct addrinfo *ai = 0;
- struct addrinfo hints = {0};
+ struct addrinfo hints = {
+ .ai_flags = AI_PASSIVE|AI_ADDRCONFIG,
+ .ai_family = AF_UNSPEC,
+ .ai_protocol = IPPROTO_TCP,
+ .ai_socktype = SOCK_STREAM };
char service[NI_MAXSERV];
int error;
- hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
- hints.ai_family = AF_UNSPEC;
- hints.ai_protocol = IPPROTO_TCP;
- hints.ai_socktype = SOCK_STREAM;
-
(void) snprintf(service, NI_MAXSERV, "%d", port);
if ((error = getaddrinfo(hostname, service, &hints, &ai)) != 0) {
if (error != EAI_SYSTEM) {
@@ -949,9 +949,7 @@ int main(int argc, char **argv) {
int loop = 0;
struct rusage rusage;
struct rusage server_start;
- struct timeval starttime = {0};
- int size;
-
+ struct timeval starttime = {.tv_sec = 0};
gettimeofday(&starttime, NULL);
while ((cmd = getopt(argc, argv, "QW:M:pL:P:Fm:t:h:i:s:c:VlSvy:xk:")) != EOF) {
@@ -1057,12 +1055,12 @@ int main(int argc, char **argv) {
exit(-1);
}
- if (connection_pool_size < no_threads) {
+ if (connection_pool_size < (size_t)no_threads) {
connection_pool_size = no_threads;
}
{
- int maxthreads = no_threads;
+ size_t maxthreads = no_threads;
struct rlimit rlim;
if (maxthreads < connection_pool_size) {
@@ -1143,7 +1141,7 @@ int main(int argc, char **argv) {
}
while (current < no_iterations) {
- struct report temp = {0};
+ struct report temp = { .offset = 0 };
char buff[40];
sleep(5);
/* print average */
@@ -1313,7 +1311,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Failed to get resource usage: %s\n",
strerror(errno));
} else {
- struct timeval endtime = {0};
+ struct timeval endtime = { .tv_sec = 0};
char buffer[128];
gettimeofday(&endtime, NULL);
View
12 metrics.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* CDDL HEADER START
*
@@ -99,7 +100,7 @@ static void insert(struct TxnResult** root, struct TxnResult* item) {
}
}
-int walk(struct TxnResult* node, int (*walk_function)(void *, struct TxnResult* node), void *cookie) {
+static int walk(struct TxnResult* node, int (*walk_function)(void *, struct TxnResult* node), void *cookie) {
int ret;
if (node->left) {
if ((ret = walk(node->left, walk_function, cookie)) != 0) {
@@ -119,6 +120,7 @@ int walk(struct TxnResult* node, int (*walk_function)(void *, struct TxnResult*
return 0;
}
+#if 0
static struct TxnResult *create_txn(struct TxnResult *item) {
static struct TxnResult *items;
static int no_left = 0;
@@ -139,6 +141,7 @@ static struct TxnResult *create_txn(struct TxnResult *item) {
return ret;
}
+#endif
struct walker_execution_time {
long current;
@@ -193,9 +196,9 @@ static hrtime_t calc_average(struct TxnResult* a) {
/**
* External interface
*/
-void record_tx(enum TxnType tx_type, hrtime_t time) {
+void record_tx(enum TxnType tx_type, hrtime_t t) {
struct TxnResult* new_txn = calloc(1, sizeof(struct TxnResult));
- new_txn->respTime = time;
+ new_txn->respTime = t;
new_txn->left = new_txn->right = new_txn->next = NULL;
pthread_mutex_lock(&lock);
insert(&txn_list_first, new_txn);
@@ -203,7 +206,8 @@ void record_tx(enum TxnType tx_type, hrtime_t time) {
txCntStdy[tx_type]++;
}
-void record_error(enum TxnType tx_type, hrtime_t time) {
+void record_error(enum TxnType tx_type, hrtime_t t) {
+ (void)t;
errCntStdy[tx_type]++;
}
Please sign in to comment.
Something went wrong with that request. Please try again.