Clean up for the master branch
This commit is contained in:
parent
cbe8c83195
commit
67edcc906f
2
Makefile
2
Makefile
|
@ -7,7 +7,7 @@ CFLAGS += -g -O2 -Wall -Wextra -Wshadow \
|
|||
LDFLAGS += `pkg-config --libs-only-L gumbo libcurl fuse uuid expat`
|
||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -lexpat
|
||||
COBJS = main.o network.o fuse_local.o link.o cache.o util.o sonic.o log.o\
|
||||
config.o ramcache.o
|
||||
config.o memcache.o
|
||||
|
||||
OS := $(shell uname)
|
||||
ifeq ($(OS),Darwin)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "link.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "ramcache.h"
|
||||
#include "memcache.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <gumbo.h>
|
||||
|
|
|
@ -13,7 +13,7 @@ typedef enum {
|
|||
link_lock_debug = 1 << 5,
|
||||
network_lock_debug = 1 << 6,
|
||||
cache_lock_debug = 1 << 7,
|
||||
ramcache_debug = 1 << 8,
|
||||
memcache_debug = 1 << 8,
|
||||
libcurl_debug = 1 << 9,
|
||||
} LogType;
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include "memcache.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
size_t write_memory_callback(void *recv_data, size_t size, size_t nmemb,
|
||||
void *userp)
|
||||
{
|
||||
size_t recv_size = size * nmemb;
|
||||
TransferStruct *ts = (TransferStruct *) userp;
|
||||
|
||||
ts->data = realloc(ts->data, ts->curr_size + recv_size + 1);
|
||||
if (!ts->data) {
|
||||
/*
|
||||
* out of memory!
|
||||
*/
|
||||
lprintf(fatal, "realloc failure!\n");
|
||||
}
|
||||
|
||||
memmove(&ts->data[ts->curr_size], recv_data, recv_size);
|
||||
ts->curr_size += recv_size;
|
||||
ts->data[ts->curr_size] = '\0';
|
||||
|
||||
return recv_size;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef memcache_H
|
||||
#define memcache_H
|
||||
#include "link.h"
|
||||
|
||||
/**
|
||||
* \brief specify the type of data transfer
|
||||
*/
|
||||
typedef enum {
|
||||
FILESTAT = 's',
|
||||
DATA = 'd'
|
||||
} TransferType;
|
||||
|
||||
/**
|
||||
* \brief For storing transfer data and metadata
|
||||
*/
|
||||
struct TransferStruct {
|
||||
/** \brief The array to store the data */
|
||||
char *data;
|
||||
/** \brief The current size of the array */
|
||||
size_t curr_size;
|
||||
/** \brief The type of transfer being done */
|
||||
TransferType type;
|
||||
/** \brief Whether transfer is in progress */
|
||||
volatile int transferring;
|
||||
/** \brief The link associated with the transfer */
|
||||
Link *link;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Callback function for file transfer
|
||||
*/
|
||||
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||
void *userp);
|
||||
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
#include "network.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "ramcache.h"
|
||||
#include "memcache.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
#include "ramcache.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
size_t write_memory_callback(void *recv_data, size_t size, size_t nmemb,
|
||||
void *userp)
|
||||
{
|
||||
size_t recv_size = size * nmemb;
|
||||
TransferStruct *ts = (TransferStruct *) userp;
|
||||
// lprintf(ramcache_debug, "bg_transfer: %d\n", ts->bg_transfer);
|
||||
// if (ts->bg_transfer) {
|
||||
// lprintf(ramcache_debug, "ramcache: thread %x: locking;\n",
|
||||
// pthread_self());
|
||||
// }
|
||||
// PTHREAD_MUTEX_LOCK(&ts->lock);
|
||||
|
||||
ts->data = realloc(ts->data, ts->curr_size + recv_size + 1);
|
||||
if (!ts->data) {
|
||||
/*
|
||||
* out of memory!
|
||||
*/
|
||||
lprintf(fatal, "realloc failure!\n");
|
||||
}
|
||||
|
||||
memmove(&ts->data[ts->curr_size], recv_data, recv_size);
|
||||
ts->curr_size += recv_size;
|
||||
ts->data[ts->curr_size] = '\0';
|
||||
// if (ts->bg_transfer) {
|
||||
// lprintf(ramcache_debug, "ramcache: thread %x: unlocking;\n",
|
||||
// pthread_self());
|
||||
// }
|
||||
// PTHREAD_MUTEX_UNLOCK(&ts->lock);
|
||||
return recv_size;
|
||||
}
|
||||
|
||||
TransferStruct *TransferStruct_bg_transfer_new()
|
||||
{
|
||||
TransferStruct *ts = CALLOC(1, sizeof(TransferStruct));
|
||||
if (pthread_mutexattr_init(&ts->lock_attr)) {
|
||||
lprintf(fatal, "lock_attr initialisation failed!\n");
|
||||
}
|
||||
|
||||
if (pthread_mutexattr_setpshared(&ts->lock_attr,
|
||||
PTHREAD_PROCESS_SHARED)) {
|
||||
lprintf(fatal, "could not set lock_attr!\n");
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&ts->lock, &ts->lock_attr)) {
|
||||
lprintf(fatal, "lock initialisation failed!\n");
|
||||
}
|
||||
|
||||
ts->bg_transfer = 1;
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
void TransferStruct_bg_transfer_free(TransferStruct *ts)
|
||||
{
|
||||
if (ts->bg_transfer) {
|
||||
if (pthread_mutex_destroy(&ts->lock)) {
|
||||
lprintf(fatal, "could not destroy lock!\n");
|
||||
}
|
||||
|
||||
if (pthread_mutexattr_destroy(&ts->lock_attr)) {
|
||||
lprintf(fatal, "could not destroy lock_attr!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* free(NULL) does nothing */
|
||||
free(ts->data);
|
||||
FREE(ts);
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
#ifndef RAMCACHE_H
|
||||
#define RAMCACHE_H
|
||||
#include "link.h"
|
||||
|
||||
/**
|
||||
* \brief specify the type of data transfer
|
||||
*/
|
||||
typedef enum {
|
||||
FILESTAT = 's',
|
||||
DATA = 'd'
|
||||
} TransferType;
|
||||
|
||||
/**
|
||||
* \brief For storing transfer data and metadata
|
||||
*/
|
||||
struct TransferStruct {
|
||||
/** \brief The array to store the data */
|
||||
char *data;
|
||||
/** \brief The current size of the array */
|
||||
size_t curr_size;
|
||||
/** \brief The type of transfer being done */
|
||||
TransferType type;
|
||||
/** \brief Whether transfer is in progress */
|
||||
volatile int transferring;
|
||||
/** \brief The link associated with the transfer */
|
||||
Link *link;
|
||||
/** \brief The minium requested size */
|
||||
size_t min_req_size;
|
||||
/** \brief mutex for background transfer */
|
||||
pthread_mutex_t lock;
|
||||
/** \brief attribute associated with the mutex */
|
||||
pthread_mutexattr_t lock_attr;
|
||||
/** \brief Whether this TransferStruct was used for background transfer */
|
||||
int bg_transfer;
|
||||
/** \brief The cache file used for background transfer */
|
||||
Cache *cf;
|
||||
/** \brief The ID of the segment being downloaded */
|
||||
off_t seg_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Callback function for file transfer
|
||||
*/
|
||||
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||
void *userp);
|
||||
|
||||
/**
|
||||
* \brief Create a TransferStruct for background transfer
|
||||
*/
|
||||
TransferStruct *TransferStruct_bg_transfer_new();
|
||||
|
||||
/**
|
||||
* \brief Free a TransferStruct used for background transfer
|
||||
*/
|
||||
void TransferStruct_free(TransferStruct *ts);
|
||||
|
||||
#endif
|
|
@ -3,7 +3,7 @@
|
|||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "link.h"
|
||||
#include "ramcache.h"
|
||||
#include "memcache.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <expat.h>
|
||||
|
|
Loading…
Reference in New Issue