diff --git a/core/cache.c b/core/cache.c index df361be1..e3d186b0 100644 --- a/core/cache.c +++ b/core/cache.c @@ -21,6 +21,21 @@ static void cache_sync_hook(char *k, uint16_t kl, char *v, uint16_t vl, void *da } } +static void uwsgi_cache_load_files() { + + struct uwsgi_string_list *usl = uwsgi.load_file_in_cache; + while(usl) { + size_t len = 0; + char *value = uwsgi_open_and_read(usl->value, &len, 0, NULL); + if (value) { + if (!uwsgi_cache_set(usl->value, usl->len, value, len, 0, 0)) { + uwsgi_log("[cache] stored %s\n", usl->value); + } + } + usl = usl->next; + } +} + void uwsgi_init_cache() { uwsgi.cache_hashtable = (uint64_t *) mmap(NULL, sizeof(uint64_t) * UMAX16, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); @@ -96,6 +111,8 @@ void uwsgi_init_cache() { uwsgi_log("*** Cache subsystem initialized: %lluMB (key: %llu bytes, keys: %llu bytes, data: %llu bytes) preallocated ***\n", (unsigned long long) ((uwsgi.cache_blocksize * uwsgi.cache_max_items) + (sizeof(struct uwsgi_cache_item) * uwsgi.cache_max_items)) / (1024 * 1024), (unsigned long long) sizeof(struct uwsgi_cache_item), (unsigned long long) (sizeof(struct uwsgi_cache_item) * uwsgi.cache_max_items), (unsigned long long) (uwsgi.cache_blocksize * uwsgi.cache_max_items)); + uwsgi_cache_load_files(); + struct uwsgi_string_list *usl = uwsgi.cache_udp_node; while(usl) { char *port = strchr(usl->value, ':'); diff --git a/core/ini.c b/core/ini.c index d00aab35..5fc9fcd0 100644 --- a/core/ini.c +++ b/core/ini.c @@ -78,7 +78,7 @@ char *ini_get_line(char *ini, off_t size) { void uwsgi_ini_config(char *file, char *magic_table[]) { - int len = 0; + size_t len = 0; char *ini; char *ini_line; diff --git a/core/io.c b/core/io.c index d0de65ab..ea82a382 100644 --- a/core/io.c +++ b/core/io.c @@ -251,7 +251,7 @@ int uwsgi_waitfd_event(int fd, int timeout, int event) { return ret; } -char *uwsgi_read_fd(int fd, int *size, int add_zero) { +char *uwsgi_read_fd(int fd, size_t *size, int add_zero) { char stack_buf[4096]; ssize_t len; @@ -315,7 +315,7 @@ end: } -char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[]) { +char *uwsgi_open_and_read(char *url, size_t *size, int add_zero, char *magic_table[]) { int fd; struct stat sb; diff --git a/core/sqlite3.c b/core/sqlite3.c index 5733c844..ea7a99b0 100644 --- a/core/sqlite3.c +++ b/core/sqlite3.c @@ -8,7 +8,7 @@ extern struct uwsgi_server uwsgi; static int uwsgi_sqlite3_config_callback(void *magic_table, int field_count, char **fields, char **col) { // make a copy of the string if (field_count >= 2) { - int value_len = strlen(fields[1]) + 1; + size_t value_len = strlen(fields[1]) + 1; char *value = magic_sub(fields[1], value_len, &value_len, (char **) magic_table); add_exported_option(uwsgi_strncopy(fields[0], strlen(fields[0])), value, 0); } diff --git a/core/subscription.c b/core/subscription.c index 9709bae5..c6e909f8 100644 --- a/core/subscription.c +++ b/core/subscription.c @@ -607,8 +607,8 @@ struct uwsgi_subscribe_slot **uwsgi_subscription_init_ht() { void uwsgi_subscribe(char *subscription, uint8_t cmd) { - int subfile_size; - int i; + size_t subfile_size; + size_t i; char *key = NULL; int keysize = 0; char *modifier1 = NULL; diff --git a/core/utils.c b/core/utils.c index b33566cc..7921742d 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1993,9 +1993,9 @@ int uwsgi_file_exists(char *filename) { return !access(filename, R_OK); } -char *magic_sub(char *buffer, int len, int *size, char *magic_table[]) { +char *magic_sub(char *buffer, size_t len, size_t *size, char *magic_table[]) { - int i; + size_t i; size_t magic_len = 0; char *magic_buf = uwsgi_malloc(len); char *magic_ptr = magic_buf; @@ -2841,7 +2841,7 @@ char *uwsgi_get_line(char *ptr, char *watermark, int *size) { void uwsgi_build_mime_dict(char *filename) { - int size = 0; + size_t size = 0; char *buf = uwsgi_open_and_read(filename, &size, 1, NULL); char *watermark = buf + size; diff --git a/core/uwsgi.c b/core/uwsgi.c index b8859bce..1f687a2c 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -189,6 +189,9 @@ static struct uwsgi_option uwsgi_base_options[] = { {"cache-udp-node", required_argument, 0, "send cache update/deletion to the specified cache udp server", uwsgi_opt_add_string_list, &uwsgi.cache_udp_node, UWSGI_OPT_MASTER}, {"cache-sync", required_argument, 0, "copy the whole content of another uWSGI cache server on server startup", uwsgi_opt_set_str, &uwsgi.cache_sync, 0}, + {"load-file-in-cache", required_argument, 0, "load a static file in the cache", uwsgi_opt_add_string_list, &uwsgi.load_file_in_cache, UWSGI_OPT_MASTER}, + + {"queue", required_argument, 0, "enable shared queue", uwsgi_opt_set_int, &uwsgi.queue_size, 0}, {"queue-blocksize", required_argument, 0, "set queue blocksize", uwsgi_opt_set_int, &uwsgi.queue_store_sync, 0}, {"queue-store", required_argument, 0, "enable persistent queue to disk", uwsgi_opt_set_str, &uwsgi.queue_store, UWSGI_OPT_MASTER}, @@ -1345,7 +1348,7 @@ static void vacuum(void) { void signal_pidfile(int sig, char *filename) { - int size = 0; + size_t size = 0; char *buffer = uwsgi_open_and_read(filename, &size, 1, NULL); @@ -4029,12 +4032,12 @@ void uwsgi_opt_connect_and_read(char *opt, char *address, void *foobar) { void uwsgi_opt_extract(char *opt, char *address, void *foobar) { - int len = 0; + size_t len = 0; char *buf; buf = uwsgi_open_and_read(address, &len, 0, NULL); if (len > 0) { - if (write(1, buf, len) != len) { + if (write(1, buf, len) != (ssize_t) len) { uwsgi_error("write()"); exit(1); }; diff --git a/core/xmlconf.c b/core/xmlconf.c index 4313689f..75bc87c6 100644 --- a/core/xmlconf.c +++ b/core/xmlconf.c @@ -20,7 +20,7 @@ void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, char *magic char *xml_id; char *xml_content; - int xml_size = 0; + size_t xml_size = 0; if (uwsgi_check_scheme(filename)) { colon = uwsgi_get_last_char(filename, '/'); diff --git a/core/yaml.c b/core/yaml.c index a43fb300..14179256 100644 --- a/core/yaml.c +++ b/core/yaml.c @@ -96,7 +96,7 @@ char *yaml_get_line(char *yaml, off_t size) { void uwsgi_yaml_config(char *file, char *magic_table[]) { - int len = 0; + size_t len = 0; char *yaml; int in_uwsgi_section = 0; diff --git a/plugins/corerouter/cr_map.c b/plugins/corerouter/cr_map.c index 1987f037..06443cf9 100644 --- a/plugins/corerouter/cr_map.c +++ b/plugins/corerouter/cr_map.c @@ -19,7 +19,7 @@ int uwsgi_cr_map_use_cache(struct uwsgi_corerouter *ucr, struct corerouter_peer } int uwsgi_cr_map_use_pattern(struct uwsgi_corerouter *ucr, struct corerouter_peer *peer) { - int tmp_socket_name_len = 0; + size_t tmp_socket_name_len = 0; ucr->magic_table['s'] = uwsgi_concat2n(peer->key, peer->key_len, "", 0); peer->tmp_socket_name = magic_sub(ucr->pattern, ucr->pattern_len, &tmp_socket_name_len, ucr->magic_table); free(ucr->magic_table['s']); diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 1d907894..9f37bd0f 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -455,7 +455,7 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { fclose(pyfile); } else { - int pycontent_size = 0; + size_t pycontent_size = 0; char *pycontent = uwsgi_open_and_read(filename, &pycontent_size, 1, NULL); if (pycontent) { diff --git a/plugins/python/symimporter.c b/plugins/python/symimporter.c index a91d6fcd..391199d8 100644 --- a/plugins/python/symimporter.c +++ b/plugins/python/symimporter.c @@ -436,7 +436,7 @@ zipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds) char *name; char *prefix = NULL; - int len = 0; + size_t len = 0; if (!PyArg_ParseTuple(args, "s", &name)) return -1; diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 33ad79aa..aba8a956 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1399,7 +1399,7 @@ PyObject *py_uwsgi_farm_get_msg(PyObject * self, PyObject * args) { PyObject *py_uwsgi_extract(PyObject * self, PyObject * args) { char *name; - int len; + size_t len; char *buf; if (!PyArg_ParseTuple(args, "s:extract", &name)) { diff --git a/uwsgi.h b/uwsgi.h index 667495de..d0220dd0 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1941,6 +1941,7 @@ struct uwsgi_server { size_t lock_size; size_t rwlock_size; + struct uwsgi_string_list *load_file_in_cache; int check_cache; uint32_t cache_max_items; @@ -2626,7 +2627,7 @@ void gateway_respawn(int); void uwsgi_gateway_go_cheap(char *, int, int *); -char *uwsgi_open_and_read(char *, int *, int, char *[]); +char *uwsgi_open_and_read(char *, size_t *, int, char *[]); char *uwsgi_get_last_char(char *, char); struct uwsgi_twobytes { @@ -2659,7 +2660,7 @@ void uwsgi_detach_daemons(); void emperor_loop(void); char *uwsgi_num2str(int); -char *magic_sub(char *, int, int *, char *[]); +char *magic_sub(char *, size_t, size_t *, char *[]); void init_magic_table(char *[]); char *uwsgi_simple_message_string(char *, uint8_t, uint8_t, char *, uint16_t, char *, uint16_t *, int); @@ -3300,7 +3301,7 @@ int uwsgi_fcntl_is_locked(int); void uwsgi_emulate_cow_for_apps(int); -char *uwsgi_read_fd(int, int *, int); +char *uwsgi_read_fd(int, size_t *, int); void uwsgi_setup_post_buffering(void);