Permalink
Browse files

Make port configurable via args

  • Loading branch information...
1 parent 0365848 commit e65c81af69de9d02d7e4faf06dfbdeab488fa972 @txus committed Sep 20, 2012
Showing with 16 additions and 2 deletions.
  1. +1 −1 README.md
  2. +15 −1 bin/shitdb.c
View
@@ -5,7 +5,7 @@ Shitty key-value store in C inspired by Redis.
## Usage
$ make
- $ bin/shitdb
+ $ bin/shitdb [port]
Example session:
View
@@ -1,12 +1,26 @@
#include <shitdb/db.h>
#include <shitdb/server.h>
+
#define DEFAULT_PORT 4999
+static int
+resolve_port(int argc, char **argv)
+{
+ int port = 0;
+ if(argc == 2 && (port = atoi(argv[1]))) {
+ return port;
+ } else {
+ return DEFAULT_PORT;
+ }
+}
+
int main(int argc, char **argv)
{
DB *db = DB_create();
- Server_start(db, DEFAULT_PORT);
+ int port = resolve_port(argc, argv);
+
+ Server_start(db, port);
return 0;
}

0 comments on commit e65c81a

Please sign in to comment.