[core] remove stream.[ch]
- remove stream.[ch] (was used only by configfile.c) - read config files into memory; no big gain from mmap (config files are typically small files)personal/stbuehler/tests-path
parent
86ede08134
commit
8c7dbf1a21
|
@ -746,7 +746,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
|||
set(COMMON_SRC
|
||||
base64.c buffer.c burl.c log.c
|
||||
http_header.c http_kv.c keyvalue.c chunk.c
|
||||
http_chunk.c stream.c fdevent.c gw_backend.c
|
||||
http_chunk.c fdevent.c gw_backend.c
|
||||
stat_cache.c plugin.c http_etag.c array.c
|
||||
data_string.c data_array.c
|
||||
data_integer.c
|
||||
|
|
|
@ -71,7 +71,7 @@ CLEANFILES = versionstamp.h versionstamp.h.tmp lemon$(BUILD_EXEEXT)
|
|||
|
||||
common_src=base64.c buffer.c burl.c log.c \
|
||||
http_header.c http_kv.c keyvalue.c chunk.c \
|
||||
http_chunk.c stream.c fdevent.c gw_backend.c \
|
||||
http_chunk.c fdevent.c gw_backend.c \
|
||||
stat_cache.c plugin.c http_etag.c array.c \
|
||||
data_string.c data_array.c \
|
||||
data_integer.c \
|
||||
|
@ -468,7 +468,6 @@ hdr = base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
|
|||
algo_md.h algo_md5.h algo_sha1.h algo_splaytree.h algo_xxhash.h \
|
||||
http_auth.h http_cgi.h http_date.h \
|
||||
http_header.h http_range.h http_vhostdb.h \
|
||||
stream.h \
|
||||
fdevent.h gw_backend.h connections.h base.h base_decls.h stat_cache.h \
|
||||
plugin.h plugin_config.h \
|
||||
http_etag.h array.h vector.h \
|
||||
|
|
|
@ -57,7 +57,7 @@ def GatherLibs(env, *libs):
|
|||
|
||||
common_src = Split("base64.c buffer.c burl.c log.c \
|
||||
http_header.c http_kv.c keyvalue.c chunk.c \
|
||||
http_chunk.c stream.c fdevent.c gw_backend.c \
|
||||
http_chunk.c fdevent.c gw_backend.c \
|
||||
stat_cache.c plugin.c http_etag.c array.c \
|
||||
data_string.c data_array.c \
|
||||
data_integer.c \
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
#include "http_etag.h"
|
||||
#include "keyvalue.h"
|
||||
#include "log.h"
|
||||
#include "stream.h"
|
||||
|
||||
#include "configparser.h"
|
||||
#include "configfile.h"
|
||||
#include "plugin.h"
|
||||
#include "safe_memclear.h"
|
||||
#include "stat_cache.h"
|
||||
#include "sys-crypto.h"
|
||||
|
||||
|
@ -1978,17 +1978,21 @@ static int config_parse(server *srv, config_t *context, const char *source, cons
|
|||
}
|
||||
|
||||
static int config_parse_file_stream(server *srv, config_t *context, const char *fn) {
|
||||
stream s;
|
||||
off_t dlen = 32*1024*1024;/*(arbitrary limit: 32 MB file; expect < 1 MB)*/
|
||||
char *data = fdevent_load_file(fn, &dlen, NULL, malloc, free);
|
||||
if (NULL == data) {
|
||||
log_perror(srv->errh, __FILE__, __LINE__,
|
||||
"opening configfile %s failed", fn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != stream_open(&s, fn)) {
|
||||
log_perror(srv->errh, __FILE__, __LINE__,
|
||||
"opening configfile %s failed", fn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = config_parse(srv, context, fn, s.start, (size_t)s.size);
|
||||
stream_close(&s);
|
||||
return ret;
|
||||
int rc = 0;
|
||||
if (dlen) {
|
||||
rc = config_parse(srv, context, fn, data, (size_t)dlen);
|
||||
safe_memclear(data, (size_t)dlen);
|
||||
}
|
||||
free(data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int config_parse_file(server *srv, config_t *context, const char *fn) {
|
||||
|
|
|
@ -744,7 +744,6 @@ common_src = [
|
|||
'safe_memclear.c',
|
||||
'sock_addr.c',
|
||||
'stat_cache.c',
|
||||
'stream.c',
|
||||
'vector.c',
|
||||
]
|
||||
if target_machine.system() == 'windows'
|
||||
|
|
151
src/stream.c
151
src/stream.c
|
@ -1,151 +0,0 @@
|
|||
#include "first.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sys-mmap.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <MemoryAPI.h>
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/* don't want to block when open()ing a fifo */
|
||||
#if defined(O_NONBLOCK)
|
||||
# define FIFO_NONBLOCK O_NONBLOCK
|
||||
#else
|
||||
# define FIFO_NONBLOCK 0
|
||||
#endif
|
||||
|
||||
int stream_open(stream *f, const char *fn) {
|
||||
|
||||
#if !defined(__WIN32)
|
||||
|
||||
struct stat st;
|
||||
int fd;
|
||||
|
||||
f->start = NULL;
|
||||
f->size = 0;
|
||||
f->mapped = 0;
|
||||
|
||||
if (-1 == (fd = open(fn, O_RDONLY | O_BINARY | FIFO_NONBLOCK))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (-1 == fstat(fd, &st)) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == st.st_size) {
|
||||
/* empty file doesn't need a mapping */
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f->start = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
|
||||
if (MAP_FAILED == f->start) {
|
||||
f->start = malloc((size_t)st.st_size);
|
||||
if (NULL == f->start
|
||||
|| st.st_size != read(fd, f->start, (size_t)st.st_size)) {
|
||||
free(f->start);
|
||||
f->start = NULL;
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
f->mapped = 1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
f->size = st.st_size;
|
||||
return 0;
|
||||
|
||||
#elif defined __WIN32
|
||||
|
||||
HANDLE fh, mh;
|
||||
void *p;
|
||||
int64_t fsize;
|
||||
|
||||
f->start = NULL;
|
||||
f->size = 0;
|
||||
|
||||
fh = CreateFile(fn,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_READONLY,
|
||||
NULL);
|
||||
|
||||
if (!fh) return -1;
|
||||
|
||||
if (!GetFileSizeEx(fh, (PLARGE_INTEGER)&fsize)) {
|
||||
CloseHandle(fh);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == fsize) {
|
||||
CloseHandle(fh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mh = CreateFileMapping( fh,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
(sizeof(off_t) > 4) ? fsize >> 32 : 0,
|
||||
fsize & 0xffffffff,
|
||||
NULL);
|
||||
|
||||
if (!mh) {
|
||||
CloseHandle(fh);
|
||||
return -1;
|
||||
}
|
||||
|
||||
p = MapViewOfFile(mh,
|
||||
FILE_MAP_READ,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
CloseHandle(mh);
|
||||
CloseHandle(fh);
|
||||
|
||||
f->start = p;
|
||||
f->size = (off_t)fsize;
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int stream_close(stream *f) {
|
||||
#ifdef HAVE_MMAP
|
||||
if (f->start) {
|
||||
if (f->mapped) {
|
||||
f->mapped = 0;
|
||||
munmap(f->start, f->size);
|
||||
} else {
|
||||
free(f->start);
|
||||
}
|
||||
}
|
||||
#elif defined(__WIN32)
|
||||
if (f->start) UnmapViewOfFile(f->start);
|
||||
#endif
|
||||
|
||||
f->start = NULL;
|
||||
f->size = 0;
|
||||
|
||||
return 0;
|
||||
}
|
14
src/stream.h
14
src/stream.h
|
@ -1,14 +0,0 @@
|
|||
#ifndef _STREAM_H_
|
||||
#define _STREAM_H_
|
||||
#include "first.h"
|
||||
|
||||
typedef struct {
|
||||
char *start;
|
||||
off_t size;
|
||||
int mapped;
|
||||
} stream;
|
||||
|
||||
int stream_open(stream *f, const char *fn);
|
||||
int stream_close(stream *f);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue