Joseph Redmon
2014-12-08 cb1f33c6ae840e8dc0f43518daf76e6ed01034f0
src/server.c
@@ -9,6 +9,7 @@
#include "mini_blas.h"
#include "utils.h"
#include "parser.h"
#include "server.h"
#include "connected_layer.h"
#include "convolutional_layer.h"
@@ -50,20 +51,22 @@
void read_all(int fd, char *buffer, size_t bytes)
{
    //printf("Want %d\n", bytes);
    size_t n = 0;
    while(n < bytes){
        int next = read(fd, buffer + n, bytes-n);
        if(next < 0) error("read failed");
        if(next <= 0) error("read failed");
        n += next;
    }
}
void write_all(int fd, char *buffer, size_t bytes)
{
    //printf("Writ %d\n", bytes);
    size_t n = 0;
    while(n < bytes){
        int next = write(fd, buffer + n, bytes-n);
        if(next < 0) error("write failed");
        if(next <= 0) error("write failed");
        n += next;
    }
}
@@ -78,11 +81,11 @@
void handle_connection(void *pointer)
{
    printf("New Connection\n");
    connection_info info = *(connection_info *) pointer;
    free(pointer);
    printf("New Connection\n");
    int fd = info.fd;
    network net = info.net;
    ++*(info.counter);
    int i;
    for(i = 0; i < net.n; ++i){
        if(net.types[i] == CONVOLUTIONAL){
@@ -126,14 +129,16 @@
    listen(fd, 10);
    struct sockaddr_in client;     /* remote address */
    socklen_t client_size = sizeof(client);   /* length of addresses */
    connection_info info;
    info.net = net;
    info.counter = &counter;
    while(1){
        connection_info *info = calloc(1, sizeof(connection_info));
        info->net = net;
        info->counter = &counter;
        pthread_t worker;
        int connection = accept(fd, (struct sockaddr *) &client, &client_size);
        info.fd = connection;
        pthread_create(&worker, NULL, (void *) &handle_connection, &info);
        info->fd = connection;
        pthread_create(&worker, NULL, (void *) &handle_connection, info);
        ++counter;
        if(counter%1000==0) save_network(net, "cfg/nist.part");
    }
}
@@ -164,6 +169,7 @@
    /* send a message to the server */
    int i;
    //printf("Sending\n");
    for(i = 0; i < net.n; ++i){
        if(net.types[i] == CONVOLUTIONAL){
            convolutional_layer layer = *(convolutional_layer *) net.layers[i];
@@ -181,6 +187,7 @@
            memset(layer.weight_updates, 0, layer.inputs*layer.outputs*sizeof(float));
        }
    }
    //printf("Sent\n");
    for(i = 0; i < net.n; ++i){
        if(net.types[i] == CONVOLUTIONAL){
@@ -201,5 +208,6 @@
            push_connected_layer(layer);
        }
    }
    //printf("Updated\n");
    close(fd);
}