Joseph Redmon
2015-01-31 0f1a31648c5292fa49b35eac90a2ee676d6c13e6
src/server.c
@@ -6,6 +6,7 @@
#include <netinet/in.h> /* needed for sockaddr_in */
#include <netdb.h>
#include <pthread.h>
#include <time.h>
#include "mini_blas.h"
#include "utils.h"
@@ -14,7 +15,7 @@
#include "connected_layer.h"
#include "convolutional_layer.h"
#define SERVER_PORT 9876
#define SERVER_PORT 9423
#define STR(x) #x
int socket_setup(int server)
@@ -45,7 +46,7 @@
typedef struct{
    int fd;
    int *counter;
    int counter;
    network net;
} connection_info;
@@ -83,7 +84,12 @@
{
    connection_info info = *(connection_info *) pointer;
    free(pointer);
    printf("New Connection\n");
    //printf("New Connection\n");
    if(info.counter%100==0){
        char buff[256];
        sprintf(buff, "unikitty/net_%d.part", info.counter);
        save_network(info.net, buff);
    }
    int fd = info.fd;
    network net = info.net;
    int i;
@@ -118,28 +124,32 @@
            write_all(fd, (char *)layer.weights, layer.outputs*layer.inputs*sizeof(float));
        }
    }
    printf("Received updates\n");
    //printf("Received updates\n");
    close(fd);
}
void server_update(network net)
{
    int fd = socket_setup(1);
    int counter = 0;
    listen(fd, 10);
    int counter = 18000;
    listen(fd, 64);
    struct sockaddr_in client;     /* remote address */
    socklen_t client_size = sizeof(client);   /* length of addresses */
    time_t t=0;
    while(1){
        connection_info *info = calloc(1, sizeof(connection_info));
        info->net = net;
        info->counter = &counter;
        info->counter = counter;
        pthread_t worker;
        int connection = accept(fd, (struct sockaddr *) &client, &client_size);
        if(!t) t=time(0);
        info->fd = connection;
        pthread_create(&worker, NULL, (void *) &handle_connection, info);
        ++counter;
        if(counter%1000==0) save_network(net, "cfg/nist.part");
        printf("%d\n", counter);
        //if(counter == 1024) break;
    }
    close(fd);
}
void client_update(network net, char *address)
@@ -197,7 +207,9 @@
            int num = layer.n*layer.c*layer.size*layer.size;
            read_all(fd, (char*) layer.filters, num*sizeof(float));
#ifdef GPU
            push_convolutional_layer(layer);
            #endif
        }
        if(net.types[i] == CONNECTED){
            connected_layer layer = *(connected_layer *) net.layers[i];
@@ -205,7 +217,9 @@
            read_all(fd, (char *)layer.biases, layer.outputs*sizeof(float));
            read_all(fd, (char *)layer.weights, layer.outputs*layer.inputs*sizeof(float));
#ifdef GPU
            push_connected_layer(layer);
            #endif
        }
    }
    //printf("Updated\n");