started writing the ramcache
This commit is contained in:
parent
939e287c87
commit
5d539c30b1
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`
|
LDFLAGS += `pkg-config --libs-only-L gumbo libcurl fuse uuid expat`
|
||||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -lexpat
|
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\
|
COBJS = main.o network.o fuse_local.o link.o cache.o util.o sonic.o log.o\
|
||||||
config.o
|
config.o ramcache.o
|
||||||
|
|
||||||
OS := $(shell uname)
|
OS := $(shell uname)
|
||||||
ifeq ($(OS),Darwin)
|
ifeq ($(OS),Darwin)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "link.h"
|
#include "link.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "ramcache.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <gumbo.h>
|
#include <gumbo.h>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "ramcache.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
|
@ -315,26 +316,6 @@ void transfer_nonblocking(CURL *curl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int HTTP_temp_failure(HTTPResponseCode http_resp)
|
int HTTP_temp_failure(HTTPResponseCode http_resp)
|
||||||
{
|
{
|
||||||
switch (http_resp) {
|
switch (http_resp) {
|
||||||
|
|
|
@ -12,34 +12,6 @@ typedef struct TransferStruct TransferStruct;
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.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 Whether we have sent off the minimally requested data*/
|
|
||||||
int min_data_sent;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** \brief HTTP response codes */
|
/** \brief HTTP response codes */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HTTP_OK = 200,
|
HTTP_OK = 200,
|
||||||
|
@ -65,11 +37,6 @@ void transfer_blocking(CURL *curl);
|
||||||
/** \brief non blocking file transfer */
|
/** \brief non blocking file transfer */
|
||||||
void transfer_nonblocking(CURL *curl);
|
void transfer_nonblocking(CURL *curl);
|
||||||
|
|
||||||
/** \brief callback function for file transfer */
|
|
||||||
size_t
|
|
||||||
write_memory_callback(void *contents, size_t size, size_t nmemb,
|
|
||||||
void *userp);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief check if a HTTP response code corresponds to a temporary failure
|
* \brief check if a HTTP response code corresponds to a temporary failure
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include "ramcache.h"
|
||||||
|
|
||||||
|
#include "log.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,37 @@
|
||||||
|
#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 Whether we have sent off the minimally requested data*/
|
||||||
|
int min_data_sent;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \brief callback function for file transfer */
|
||||||
|
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||||
|
void *userp);
|
||||||
|
|
||||||
|
#endif
|
|
@ -3,7 +3,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "link.h"
|
#include "link.h"
|
||||||
|
#include "ramcache.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
|
|
Loading…
Reference in New Issue