Skip to content

Commit

Permalink
cstyle repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Apr 5, 2012
1 parent d95637c commit d571968
Show file tree
Hide file tree
Showing 24 changed files with 266 additions and 261 deletions.
30 changes: 15 additions & 15 deletions buffered_socket/buffered_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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)) {
Expand Down
20 changes: 10 additions & 10 deletions buffered_socket/buffered_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

enum BufferedSocketStates {
BS_INIT,
BS_CONNECTING,
BS_CONNECTED,
BS_CONNECTING,
BS_CONNECTED,
BS_DISCONNECTED
};

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions buffered_socket/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions domain_socket/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions domain_socket/domain_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions domain_socket/domain_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
48 changes: 24 additions & 24 deletions host_pool/host_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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++;
Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions host_pool/host_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit d571968

Please sign in to comment.