Permalink
Browse files

Merge pull request #40 from mreiferson/cstyle

cstyle repo
  • Loading branch information...
2 parents d95637c + d571968 commit 4f4f54af7d14f3df19e16c03906c884decfcfb81 @ploxiln ploxiln committed Apr 5, 2012
@@ -19,13 +19,13 @@ static void buffered_socket_writecb(struct bufferevent *bev, void *arg);
static void buffered_socket_errorcb(struct bufferevent *bev, short what, void *arg);
static void buffered_socket_connectcb(int fd, short what, void *arg);
-struct BufferedSocket *new_buffered_socket(const char *address, int port,
- void (*connect_callback)(struct BufferedSocket *buffsock, void *arg),
- void (*close_callback)(struct BufferedSocket *buffsock, void *arg),
- void (*read_callback)(struct BufferedSocket *buffsock, struct evbuffer *evb, void *arg),
- void (*write_callback)(struct BufferedSocket *buffsock, void *arg),
- void (*error_callback)(struct BufferedSocket *buffsock, void *arg),
- void *cbarg)
+struct BufferedSocket *new_buffered_socket(const char *address, int port,
+ void (*connect_callback)(struct BufferedSocket *buffsock, void *arg),
+ void (*close_callback)(struct BufferedSocket *buffsock, void *arg),
+ void (*read_callback)(struct BufferedSocket *buffsock, struct evbuffer *evb, void *arg),
+ void (*write_callback)(struct BufferedSocket *buffsock, void *arg),
+ void (*error_callback)(struct BufferedSocket *buffsock, void *arg),
+ void *cbarg)
{
struct BufferedSocket *buffsock;
@@ -119,7 +119,7 @@ static void buffered_socket_connectcb(int fd, short what, void *arg)
return;
}
- if (getsockopt(buffsock->fd, SOL_SOCKET, SO_ERROR, (void*)&error, &errsz) == -1) {
+ if (getsockopt(buffsock->fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errsz) == -1) {
_DEBUG("%s: getsockopt failed for \"%s:%d\" on %d\n",
__FUNCTION__, buffsock->address, buffsock->port, buffsock->fd);
buffered_socket_close(buffsock);
@@ -133,13 +133,13 @@ static void buffered_socket_connectcb(int fd, short what, void *arg)
return;
}
- _DEBUG("%s: connected to \"%s:%d\" on %d\n",
+ _DEBUG("%s: connected to \"%s:%d\" on %d\n",
__FUNCTION__, buffsock->address, buffsock->port, buffsock->fd);
-
+
buffsock->state = BS_CONNECTED;
- buffsock->bev = bufferevent_new(buffsock->fd,
- buffered_socket_readcb, buffered_socket_writecb, buffered_socket_errorcb,
- (void *)buffsock);
+ buffsock->bev = bufferevent_new(buffsock->fd,
+ buffered_socket_readcb, buffered_socket_writecb, buffered_socket_errorcb,
+ (void *)buffsock);
bufferevent_enable(buffsock->bev, EV_READ);
if (buffsock->connect_callback) {
@@ -149,9 +149,9 @@ static void buffered_socket_connectcb(int fd, short what, void *arg)
void buffered_socket_close(struct BufferedSocket *buffsock)
{
- _DEBUG("%s: closing \"%s:%d\" on %d\n",
+ _DEBUG("%s: closing \"%s:%d\" on %d\n",
__FUNCTION__, buffsock->address, buffsock->port, buffsock->fd);
-
+
buffsock->state = BS_DISCONNECTED;
if (event_initialized(&buffsock->conn_ev)) {
@@ -5,8 +5,8 @@
enum BufferedSocketStates {
BS_INIT,
- BS_CONNECTING,
- BS_CONNECTED,
+ BS_CONNECTING,
+ BS_CONNECTED,
BS_DISCONNECTED
};
@@ -20,18 +20,18 @@ struct BufferedSocket {
void (*connect_callback)(struct BufferedSocket *buffsock, void *arg);
void (*close_callback)(struct BufferedSocket *buffsock, void *arg);
void (*read_callback)(struct BufferedSocket *buffsock, struct evbuffer *evb, void *arg);
- void (*write_callback)(struct BufferedSocket *buffsock, void *arg);
+ void (*write_callback)(struct BufferedSocket *buffsock, void *arg);
void (*error_callback)(struct BufferedSocket *buffsock, void *arg);
void *cbarg;
};
-struct BufferedSocket *new_buffered_socket(const char *address, int port,
- void (*connect_callback)(struct BufferedSocket *buffsock, void *arg),
- void (*close_callback)(struct BufferedSocket *buffsock, void *arg),
- void (*read_callback)(struct BufferedSocket *buffsock, struct evbuffer *evb, void *arg),
- void (*write_callback)(struct BufferedSocket *buffsock, void *arg),
- void (*error_callback)(struct BufferedSocket *buffsock, void *arg),
- void *cbarg);
+struct BufferedSocket *new_buffered_socket(const char *address, int port,
+ void (*connect_callback)(struct BufferedSocket *buffsock, void *arg),
+ void (*close_callback)(struct BufferedSocket *buffsock, void *arg),
+ void (*read_callback)(struct BufferedSocket *buffsock, struct evbuffer *evb, void *arg),
+ void (*write_callback)(struct BufferedSocket *buffsock, void *arg),
+ void (*error_callback)(struct BufferedSocket *buffsock, void *arg),
+ void *cbarg);
void free_buffered_socket(struct BufferedSocket *socket);
int buffered_socket_connect(struct BufferedSocket *buffsock);
void buffered_socket_close(struct BufferedSocket *socket);
@@ -76,8 +76,8 @@ int main(int argc, char **argv)
event_init();
buffsock = new_buffered_socket("127.0.0.1", 5150,
- connect_cb, close_cb, read_cb, write_cb, error_cb, "hello world\n");
-
+ connect_cb, close_cb, read_cb, write_cb, error_cb, "hello world\n");
+
signal(SIGINT, termination_handler);
signal(SIGQUIT, termination_handler);
signal(SIGTERM, termination_handler);
@@ -59,9 +59,9 @@ int main(int argc, char **argv)
{
event_init();
- if (!(uds = new_domain_socket("/tmp/domain_socket_test",
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH,
- uds_on_read, uds_on_write, uds_on_error, 64))) {
+ if (!(uds = new_domain_socket("/tmp/domain_socket_test",
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH,
+ uds_on_read, uds_on_write, uds_on_error, 64))) {
fprintf(stdout, "ERROR: new_domain_socket() failed\n");
exit(1);
}
@@ -17,15 +17,15 @@
#endif
static struct DSClient *new_domain_socket_client(struct DomainSocket *uds,
- int client_fd, struct sockaddr *sa, socklen_t salen);
+ int client_fd, struct sockaddr *sa, socklen_t salen);
static void free_domain_socket_client(struct DSClient *client);
static void accept_socket(int fd, short what, void *arg);
-struct DomainSocket *new_domain_socket(const char *path, int access_mask,
- void (*read_callback)(struct DSClient *client),
- void (*write_callback)(struct DSClient *client),
- void (*error_callback)(struct DSClient *client),
- int listen_backlog)
+struct DomainSocket *new_domain_socket(const char *path, int access_mask,
+ void (*read_callback)(struct DSClient *client),
+ void (*write_callback)(struct DSClient *client),
+ void (*error_callback)(struct DSClient *client),
+ int listen_backlog)
{
struct linger ling = {0, 0};
struct sockaddr_un addr;
@@ -50,7 +50,7 @@ struct DomainSocket *new_domain_socket(const char *path, int access_mask,
}
// clean up a previous socket file if we left it around
- if (lstat(path, &tstat) == 0) {
+ if (lstat(path, &tstat) == 0) {
if (S_ISSOCK(tstat.st_mode)) {
unlink(path);
}
@@ -110,7 +110,7 @@ void free_domain_socket(struct DomainSocket *uds)
close(uds->fd);
}
- if (lstat(uds->path, &tstat) == 0) {
+ if (lstat(uds->path, &tstat) == 0) {
if (S_ISSOCK(tstat.st_mode)) {
unlink(uds->path);
}
@@ -198,7 +198,7 @@ void domain_socket_client_write(struct DSClient *client, void *data, size_t len)
}
static struct DSClient *new_domain_socket_client(struct DomainSocket *uds,
- int client_fd, struct sockaddr *sa, socklen_t salen)
+ int client_fd, struct sockaddr *sa, socklen_t salen)
{
struct DSClient *client;
@@ -18,11 +18,11 @@ struct DSClient {
struct DomainSocket *uds;
};
-struct DomainSocket *new_domain_socket(const char *path, int access_mask,
- void (*read_callback)(struct DSClient *client),
- void (*write_callback)(struct DSClient *client),
- void (*error_callback)(struct DSClient *client),
- int listen_backlog);
+struct DomainSocket *new_domain_socket(const char *path, int access_mask,
+ void (*read_callback)(struct DSClient *client),
+ void (*write_callback)(struct DSClient *client),
+ void (*error_callback)(struct DSClient *client),
+ int listen_backlog);
void free_domain_socket(struct DomainSocket *uds);
void domain_socket_client_write(struct DSClient *client, void *data, size_t len);
View
@@ -19,8 +19,8 @@
* max_retry_interval - the maximum seconds to wait between retries
* reset_on_all_failed - reset all hosts to alive when all are marked as failed.
*/
-struct HostPool *new_host_pool(int retry_failed_hosts, int retry_interval,
- int max_retry_interval, int reset_on_all_failed)
+struct HostPool *new_host_pool(int retry_failed_hosts, int retry_interval,
+ int max_retry_interval, int reset_on_all_failed)
{
struct HostPool *host_pool;
@@ -51,8 +51,8 @@ void free_host_pool(struct HostPool *host_pool)
}
}
-struct HostPoolEndpoint *new_host_pool_endpoint(struct HostPool *host_pool,
- char *address, int port, char *path)
+struct HostPoolEndpoint *new_host_pool_endpoint(struct HostPool *host_pool,
+ char *address, int port, char *path)
{
struct HostPoolEndpoint *host_pool_endpoint;
@@ -100,8 +100,8 @@ void host_pool_from_json(struct HostPool *host_pool, json_object *host_pool_endp
}
}
-struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
- enum HostPoolEndpointSelectionMode mode, int64_t state)
+struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
+ enum HostPoolEndpointSelectionMode mode, int64_t state)
{
struct HostPoolEndpoint *endpoint;
int c;
@@ -117,8 +117,8 @@ struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
return endpoint;
}
- if ((host_pool->retry_failed_hosts == -1) ||
- (endpoint->retry_count <= host_pool->retry_failed_hosts)) {
+ if ((host_pool->retry_failed_hosts == -1) ||
+ (endpoint->retry_count <= host_pool->retry_failed_hosts)) {
time(&now);
if (endpoint->next_retry < now) {
endpoint->retry_count++;
@@ -140,8 +140,8 @@ struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
//
// this ensures we always try each endpoint in the host pool
//
- // however, if we were asked to find a random endpoint, randomize once
- // more so that the endpoint following the failed endpoint won't get a
+ // however, if we were asked to find a random endpoint, randomize once
+ // more so that the endpoint following the failed endpoint won't get a
// disproportionate number of additional requests
if (mode == HOST_POOL_RANDOM) {
host_pool_next_endpoint(host_pool, mode, state);
@@ -157,8 +157,8 @@ struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
return NULL;
}
-struct HostPoolEndpoint *host_pool_next_endpoint(struct HostPool *host_pool,
- enum HostPoolEndpointSelectionMode mode, int64_t state)
+struct HostPoolEndpoint *host_pool_next_endpoint(struct HostPool *host_pool,
+ enum HostPoolEndpointSelectionMode mode, int64_t state)
{
int index;
@@ -171,17 +171,17 @@ struct HostPoolEndpoint *host_pool_next_endpoint(struct HostPool *host_pool,
break;
case HOST_POOL_ROUND_ROBIN:
// round-robin through the endpoints for each request
- host_pool->current_endpoint = host_pool->current_endpoint ?
- (host_pool->current_endpoint->hh.next ? host_pool->current_endpoint->hh.next :
- host_pool->endpoints) : host_pool->endpoints;
+ host_pool->current_endpoint = host_pool->current_endpoint ?
+ (host_pool->current_endpoint->hh.next ? host_pool->current_endpoint->hh.next :
+ host_pool->endpoints) : host_pool->endpoints;
break;
case HOST_POOL_SINGLE:
// choose the same endpoint for all requests for this message
if (state != host_pool->checkpoint) {
host_pool->checkpoint = state;
- host_pool->current_endpoint = host_pool->current_endpoint ?
- (host_pool->current_endpoint->hh.next ? host_pool->current_endpoint->hh.next :
- host_pool->endpoints) : host_pool->endpoints;
+ host_pool->current_endpoint = host_pool->current_endpoint ?
+ (host_pool->current_endpoint->hh.next ? host_pool->current_endpoint->hh.next :
+ host_pool->endpoints) : host_pool->endpoints;
}
break;
}
@@ -198,9 +198,9 @@ void host_pool_mark_success(struct HostPool *host_pool, int id)
HASH_FIND_INT(host_pool->endpoints, &id, endpoint);
assert(endpoint != NULL);
- _DEBUG("HOST_POOL: marking endpoint #%d (%s:%d%s) as SUCCESS\n",
- endpoint->id, endpoint->address, endpoint->port, endpoint->path);
-
+ _DEBUG("HOST_POOL: marking endpoint #%d (%s:%d%s) as SUCCESS\n",
+ endpoint->id, endpoint->address, endpoint->port, endpoint->path);
+
endpoint->alive = 1;
}
@@ -212,9 +212,9 @@ void host_pool_mark_failed(struct HostPool *host_pool, int id)
HASH_FIND_INT(host_pool->endpoints, &id, endpoint);
assert(endpoint != NULL);
- _DEBUG("HOST_POOL: marking endpoint #%d (%s:%d%s) as FAILED\n",
- endpoint->id, endpoint->address, endpoint->port, endpoint->path);
-
+ _DEBUG("HOST_POOL: marking endpoint #%d (%s:%d%s) as FAILED\n",
+ endpoint->id, endpoint->address, endpoint->port, endpoint->path);
+
if (endpoint->alive) {
endpoint->alive = 0;
endpoint->retry_count = 0;
View
@@ -33,17 +33,17 @@ enum HostPoolEndpointSelectionMode {
HOST_POOL_SINGLE
};
-struct HostPool *new_host_pool(int retry_failed_hosts, int retry_interval,
- int max_retry_interval, int reset_on_all_failed);
+struct HostPool *new_host_pool(int retry_failed_hosts, int retry_interval,
+ int max_retry_interval, int reset_on_all_failed);
void free_host_pool(struct HostPool *host_pool);
-struct HostPoolEndpoint *new_host_pool_endpoint(struct HostPool *host_pool,
- char *address, int port, char *path);
+struct HostPoolEndpoint *new_host_pool_endpoint(struct HostPool *host_pool,
+ char *address, int port, char *path);
void free_host_pool_endpoint(struct HostPoolEndpoint *host_pool_endpoint);
void host_pool_from_json(struct HostPool *host_pool, json_object *host_pool_endpoint_list);
-struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
- enum HostPoolEndpointSelectionMode mode, int64_t state);
-struct HostPoolEndpoint *host_pool_next_endpoint(struct HostPool *host_pool,
- enum HostPoolEndpointSelectionMode mode, int64_t state);
+struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
+ enum HostPoolEndpointSelectionMode mode, int64_t state);
+struct HostPoolEndpoint *host_pool_next_endpoint(struct HostPool *host_pool,
+ enum HostPoolEndpointSelectionMode mode, int64_t state);
void host_pool_mark_success(struct HostPool *host_pool, int id);
void host_pool_mark_failed(struct HostPool *host_pool, int id);
void host_pool_reset(struct HostPool *host_pool);
Oops, something went wrong.

0 comments on commit 4f4f54a

Please sign in to comment.