Commit 8903b938 authored by Per Cederqvist's avatar Per Cederqvist

patch refactor-cached_get_text-part-2.patch

parent 560a74da
introduce-generation_position refactor-cached_get_text
From: Per Cederqvist <ceder@lysator.liu.se> From: Per Cederqvist <ceder@lysator.liu.se>
Subject: patch refactor-cached_get_text.patch Subject: patch refactor-cached_get_text-part-2.patch
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
#include "local-to-global.h" #include "local-to-global.h"
#include "unused.h" #include "unused.h"
#include "eintr.h" #include "eintr.h"
#include "text-store.h"
/* /*
* All functions that can fail sets kom_errno to a suitable value * All functions that can fail sets kom_errno to a suitable value
...@@ -324,41 +325,20 @@ cached_conf_exists(Conf_no conf_no) ...@@ -324,41 +325,20 @@ cached_conf_exists(Conf_no conf_no)
extern String extern String
cached_get_text( Text_no text ) cached_get_text( Text_no text )
{ {
String the_string; String the_string = EMPTY_STRING;
Text_stat *t_stat; Text_stat *t_stat;
TRACE2("cached_get_text %lu\n", text); TRACE2("cached_get_text %lu\n", text);
if ( (t_stat = cached_get_text_stat (text)) == NULL ) if ( (t_stat = cached_get_text_stat (text)) == NULL )
return EMPTY_STRING; return EMPTY_STRING;
else if (t_stat->text_store.generation == 0) else if (text_store_load_text(text, t_stat, &the_string, text_file) != OK)
{ return EMPTY_STRING;
the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars;
if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
{
kom_log("Failed to seek to %ld in text mass file: %s.\n",
t_stat->text_store.file_pos, strerror(errno));
return EMPTY_STRING;
}
if ( fread(the_string.string, sizeof(char), the_string.len, text_file) return the_string;
!= (size_t)the_string.len )
{
kom_log("WARNING: cached_get_text: premature end on text %lu\n",
text);
return EMPTY_STRING;
}
return the_string;
}
else
{
#warning Generation > 0 not yet handled
restart_kom("Only generation 0 is handled.\n");
}
} }
extern Text_stat * /* NULL on error */ extern Text_stat * /* NULL on error */
cached_get_text_stat( Text_no text ) cached_get_text_stat( Text_no text )
{ {
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
#include "stats.h" #include "stats.h"
#include "services.h" #include "services.h"
#include "manipulate.h" #include "manipulate.h"
#include "text-store.h"
/* /*
* Possible improvements: * Possible improvements:
...@@ -1045,7 +1046,7 @@ cached_conf_exists(Conf_no conf_no) ...@@ -1045,7 +1046,7 @@ cached_conf_exists(Conf_no conf_no)
extern String extern String
cached_get_text( Text_no text ) cached_get_text( Text_no text )
{ {
String the_string; String the_string = EMPTY_STRING;
Text_stat *t_stat; Text_stat *t_stat;
LOGACC(lt_text_mass, text); LOGACC(lt_text_mass, text);
...@@ -1053,32 +1054,10 @@ cached_get_text( Text_no text ) ...@@ -1053,32 +1054,10 @@ cached_get_text( Text_no text )
if ( (t_stat = cached_get_text_stat (text)) == NULL ) if ( (t_stat = cached_get_text_stat (text)) == NULL )
return EMPTY_STRING; return EMPTY_STRING;
else if (t_stat->text_store.generation == 0) else if (text_store_load_text(text, t_stat, &the_string, text_file) != OK)
{ return EMPTY_STRING;
the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars;
if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
{
kom_log("Failed to seek to %ld in text mass file: %s.\n",
t_stat->text_store.file_pos, strerror(errno));
return EMPTY_STRING;
}
if ( fread(the_string.string, sizeof(char), the_string.len, text_file) return the_string;
!= (size_t)the_string.len )
{
kom_log("WARNING: cached_get_text: premature end on text %lu\n",
text);
return EMPTY_STRING;
}
return the_string;
}
else
{
#warning Generation > 0 not yet handled
restart_kom("Only generation 0 is handled.\n");
}
} }
......
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "log.h"
#include "server/smalloc.h"
#include "kom-types.h"
#include "lyskomd.h"
#include "text-store.h" #include "text-store.h"
extern Success
text_store_load_text(Text_no tno,
const Text_stat *t_stat,
String *res,
FILE *text_file)
{
if (t_stat->text_store.generation == 0)
{
if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
{
kom_log("Failed to seek to %ld in text mass file: %s.\n",
t_stat->text_store.file_pos, strerror(errno));
return FAILURE;
}
res->string = tmp_alloc(t_stat->no_of_chars);
res->len = t_stat->no_of_chars;
if ( fread(res->string, sizeof(char), res->len, text_file)
!= (size_t)res->len )
{
kom_log("WARNING: cached_get_text: premature end on text %lu\n",
tno);
return FAILURE;
}
return OK;
}
else
{
#warning Generation > 0 not yet handled
restart_kom("Only generation 0 is handled.\n");
}
}
/* still empty */ extern Success
text_store_load_text(Text_no text,
const Text_stat *t_stat,
String *res,
FILE *text_file);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment