Update simplestore to use a standard port number.
[bluesky.git] / simplestore / server.c
index 0e2ed4b..07448f1 100644 (file)
@@ -29,6 +29,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#define SIMPLESTORE_PORT 9541
+
 /* Maximum number of connections the server will queue waiting for us to call
  * accept(). */
 #define TCP_BACKLOG 32
@@ -193,7 +195,7 @@ void cmd_put(int fd, char *path, char *buf,
         continue;
     }
 
-    printf("Got %zd bytes for object '%s'\n", buf_used, path);
+    /* printf("Got %zd bytes for object '%s'\n", buf_used, path); */
 
     char *response = "-1\n";
     int file = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0600);
@@ -322,6 +324,17 @@ int server_init()
         exit(1);
     }
 
+    int val = 1;
+    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
+
+    server_addr.sin_family = AF_INET;
+    server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+    server_addr.sin_port = htons(SIMPLESTORE_PORT);
+    if (bind(fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
+        perror("bind");
+        exit(1);
+    }
+
     if (listen(fd, TCP_BACKLOG) < 0) {
         perror("listen");
         exit(1);