Skip to content

Commit

Permalink
Better compiler flags make for better code
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Jan 6, 2012
1 parent 254e158 commit 03828af
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .gitignore
@@ -1,2 +1 @@
server
client
bungelo
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
bungelo:
gcc bungeloClient.c bungeloServer.c bungelo.c -o bungelo -lzmq -lhiredis -ljson -ltofu
gcc -Wall -pedantic -Werror -O3 bungeloClient.c bungeloServer.c bungelo.c -o bungelo -lzmq -lhiredis -ljson -ltofu

clean:
rm bungelo
Binary file removed bungelo
Binary file not shown.
9 changes: 7 additions & 2 deletions bungelo.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bungeloClient.h"
#include "bungeloServer.h"

Expand All @@ -9,22 +10,26 @@ static void printUsage(void) {

int main(int argc, char **argv)
{
char *mode;

if(argc != 2) {
printUsage();
return 1;
}

char *mode = argv[1];
mode = argv[1];

if(strcmp(mode, "--client") == 0) {
printf("Starting bungelo client...\n");
startBungeloClient();
} else if(strcmp(mode, "--server") == 0) {
} else if(strcmp(mode, "--server") == 0) {
printf("Starting bungelo server...\n");
startBungeloServer();
} else {
printf("Unknown option %s\n", mode);
printUsage();
return 2;
}

return 0;
}
25 changes: 15 additions & 10 deletions bungeloClient.c
Expand Up @@ -6,13 +6,15 @@
#include "hiredis/hiredis.h"

static char * zrecv(void *socket) {
int size;
char *string;
zmq_msg_t message;
zmq_msg_init(&message);

if(zmq_recv(socket, &message, 0)) return(NULL);

int size = zmq_msg_size(&message);
char *string = malloc(size + 1);
size = zmq_msg_size(&message);
string = malloc(size + 1);
memcpy(string, zmq_msg_data(&message), size);
zmq_msg_close(&message);
string[size] = 0;
Expand All @@ -28,20 +30,23 @@ static int persist(redisContext *c, const char *key, const char *value) {

int startBungeloClient(void)
{
void *context = zmq_init(1);
void *receiver = zmq_socket(context, ZMQ_PULL);
redisContext *c;
void *context;
void *receiver;
char *string;
const char *id, *message;
struct json_object *obj;

context = zmq_init(1);
receiver = zmq_socket(context, ZMQ_PULL);
zmq_connect(receiver, "tcp://localhost:5555");

redisContext *c = redisConnect("127.0.0.1", 6379);
c = redisConnect("127.0.0.1", 6379);

if(c->err) {
printf("Error: %s\n", c->errstr);
return 1;
}

const char *id, *message;
char *string;
struct json_object *obj;

while(1) {
string = zrecv(receiver);
obj = json_tokener_parse(string);
Expand Down
2 changes: 1 addition & 1 deletion bungeloClient.h
@@ -1,6 +1,6 @@
#ifndef __BUNGLEO_CLIENT_H__
#define __BUNGLEO_CLIENT_H__

extern int startBungleoClient(void);
extern int startBungeloClient(void);

#endif
2 changes: 1 addition & 1 deletion bungeloServer.h
@@ -1,6 +1,6 @@
#ifndef __BUNGLEO_SERVER_H__
#define __BUNGLEO_SERVER_H__

extern int startBungleoServer(void);
extern int startBungeloServer(void);

#endif

0 comments on commit 03828af

Please sign in to comment.