Permalink
Browse files

Better compiler flags make for better code

  • Loading branch information...
1 parent 254e158 commit 03828af7a9d08f69d4867ca33d847554d17a729b @abedra committed Jan 6, 2012
Showing with 26 additions and 17 deletions.
  1. +1 −2 .gitignore
  2. +1 −1 Makefile
  3. BIN bungelo
  4. +7 −2 bungelo.c
  5. +15 −10 bungeloClient.c
  6. +1 −1 bungeloClient.h
  7. +1 −1 bungeloServer.h
View
@@ -1,2 +1 @@
-server
-client
+bungelo
View
@@ -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
View
BIN bungelo
Binary file not shown.
View
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "bungeloClient.h"
#include "bungeloServer.h"
@@ -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;
}
View
@@ -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;
@@ -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);
View
@@ -1,6 +1,6 @@
#ifndef __BUNGLEO_CLIENT_H__
#define __BUNGLEO_CLIENT_H__
-extern int startBungleoClient(void);
+extern int startBungeloClient(void);
#endif
View
@@ -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.