Browse Source
try to use memory mapped io for asset access, but this one leaks like a rotten barge
release0.1.5
try to use memory mapped io for asset access, but this one leaks like a rotten barge
release0.1.5
25 changed files with 333 additions and 209 deletions
-
2assets/html/main.html
-
1configure.ac
-
9include/asset.h
-
3include/http/message.h
-
2include/http/worker.h
-
8src/Makefile.am
-
6src/asset/Makefile.am
-
19src/asset/asset.c
-
88src/asset/pool.c
-
4src/cbuf/write.c
-
2src/hash/delete.c
-
4src/http/Makefile.am
-
16src/http/message.c
-
65src/http/response/500.c
-
61src/http/response/asset.c
-
46src/http/worker.c
-
32src/http/worker/get_asset.c
-
42src/http/worker/get_mime_type.c
-
33src/http/worker/process.c
-
22src/http/writer/write.c
-
6src/server/read.c
-
1src/server/run.c
-
5src/server/server.c
-
47src/server/write.c
-
2src/taskrambler.c
@ -0,0 +1,6 @@ |
|||||
|
ACLOCAL_AMFLAGS = -I m4 |
||||
|
|
||||
|
noinst_LIBRARIES = libasset.a |
||||
|
|
||||
|
libasset_a_SOURCES = asset.c pool.c |
||||
|
libasset_a_CFLAGS = $(CFLAGS) -Wall -I ../../include/ |
||||
@ -0,0 +1,88 @@ |
|||||
|
/** |
||||
|
* \file |
||||
|
* |
||||
|
* \author Georg Hopp |
||||
|
* |
||||
|
* \copyright |
||||
|
* Copyright © 2012 Georg Hopp |
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
// for size_t |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
// for strlen |
||||
|
|
||||
|
#include "class.h" |
||||
|
#include "asset.h" |
||||
|
#include "hash.h" |
||||
|
|
||||
|
Hash asset_pool = NULL; |
||||
|
|
||||
|
static |
||||
|
inline |
||||
|
void |
||||
|
freeAsset(const void * _node) |
||||
|
{ |
||||
|
Asset node = (Asset)_node; |
||||
|
|
||||
|
delete(node); |
||||
|
} |
||||
|
|
||||
|
Asset |
||||
|
assetPoolGet(const char * path, size_t npath) |
||||
|
{ |
||||
|
Asset asset = NULL; |
||||
|
|
||||
|
if (NULL == asset_pool) { |
||||
|
asset_pool = new(Hash); |
||||
|
} else { |
||||
|
asset = hashGet(asset_pool, path, npath); |
||||
|
} |
||||
|
|
||||
|
if (NULL == asset) { |
||||
|
asset = new(Asset, path, npath); |
||||
|
|
||||
|
hashAdd(asset_pool, |
||||
|
new(HashValue, path, npath, asset, sizeof(Asset))); |
||||
|
} else { |
||||
|
asset->ref_count++; |
||||
|
} |
||||
|
|
||||
|
return asset; |
||||
|
} |
||||
|
|
||||
|
size_t |
||||
|
assetPoolRelease(Asset asset) |
||||
|
{ |
||||
|
if (asset->ref_count <= 1) { |
||||
|
hashDelete(asset_pool, asset->fname, asset->nfname); |
||||
|
delete(asset); |
||||
|
|
||||
|
return 0; |
||||
|
} else { |
||||
|
asset->ref_count--; |
||||
|
|
||||
|
return asset->ref_count; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
assetPoolCleanup(void) |
||||
|
{ |
||||
|
hashEach(asset_pool, freeAsset); |
||||
|
} |
||||
|
|
||||
|
// vim: set ts=4 sw=4: |
||||
@ -0,0 +1,65 @@ |
|||||
|
/** |
||||
|
* \file |
||||
|
* |
||||
|
* \author Georg Hopp |
||||
|
* |
||||
|
* \copyright |
||||
|
* Copyright © 2012 Georg Hopp |
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#include "class.h" |
||||
|
|
||||
|
#include "http/response.h" |
||||
|
#include "http/message.h" |
||||
|
#include "http/header.h" |
||||
|
|
||||
|
#include "utils/memory.h" |
||||
|
#include "hash.h" |
||||
|
|
||||
|
#define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \ |
||||
|
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \ |
||||
|
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \ |
||||
|
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n" \ |
||||
|
"<head><title>500 - Internal Server Error</title></head>" \ |
||||
|
"<body><h1>500 - Internal Server Error</h1></body>" \ |
||||
|
"</html>" |
||||
|
|
||||
|
|
||||
|
HttpResponse |
||||
|
httpResponse500() |
||||
|
{ |
||||
|
HttpResponse response; |
||||
|
HttpMessage message; |
||||
|
|
||||
|
response = new(HttpResponse, "HTTP/1.1", 500, "Internal Server Error"); |
||||
|
message = (HttpMessage)response; |
||||
|
|
||||
|
hashAdd(message->header, |
||||
|
new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); |
||||
|
|
||||
|
message->nbody = sizeof(RESP_DATA) - 1; |
||||
|
message->body = memMalloc(sizeof(RESP_DATA)); |
||||
|
memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)); |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
// vim: set ts=4 sw=4: |
||||
@ -1,42 +0,0 @@ |
|||||
/** |
|
||||
* \file |
|
||||
* |
|
||||
* \author Georg Hopp |
|
||||
* |
|
||||
* \copyright |
|
||||
* Copyright © 2012 Georg Hopp |
|
||||
* |
|
||||
* This program is free software: you can redistribute it and/or modify |
|
||||
* it under the terms of the GNU General Public License as published by |
|
||||
* the Free Software Foundation, either version 3 of the License, or |
|
||||
* (at your option) any later version. |
|
||||
* |
|
||||
* This program is distributed in the hope that it will be useful, |
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
* GNU General Public License for more details. |
|
||||
* |
|
||||
* You should have received a copy of the GNU General Public License |
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
*/ |
|
||||
|
|
||||
#include <sys/types.h> |
|
||||
|
|
||||
#include "http/worker.h" |
|
||||
|
|
||||
#include "utils/memory.h" |
|
||||
#include "hash.h" |
|
||||
|
|
||||
char * |
|
||||
httpWorkerGetMimeType( |
|
||||
HttpWorker this, |
|
||||
const char * extension) |
|
||||
{ |
|
||||
HashValue mime_type; |
|
||||
|
|
||||
mime_type = hashGet(this->mime_types, extension, strlen(extension)); |
|
||||
|
|
||||
return (char *)mime_type->value; |
|
||||
} |
|
||||
|
|
||||
// vim: set ts=4 sw=4: |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue