X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fquery.c;h=86696bb518a00ba1221d3c357cfcb27d6f6eff9c;hb=97d3625dcb84e6371d2464c93ae9bef8a3d4b466;hp=7a9ab161019d6d7c0882fda74bb2a8f39a44cf62;hpb=259624013535f3c93315868efb5f6f611ba88470;p=matches%2FMCTX3420.git diff --git a/server/query.c b/server/query.c index 7a9ab16..86696bb 100644 --- a/server/query.c +++ b/server/query.c @@ -6,7 +6,7 @@ - +#include "query.h" #include "sensor.h" #include "log.h" @@ -25,22 +25,10 @@ void QuerySensor(int id) //TODO: This code will form the SensorHandler FastCGI f //CRITICAL SECTION (Don't access file while sensor thread is writing to it!) pthread_mutex_lock(&(s->mutex)); - FILE * file = fopen(s->filename, "rb"); - if (file == NULL) - { - Log(LOGWARN, "Couldn't open file \"%s\" mode rb - %s", s->filename, strerror(errno)); - } - else - { - fseek(file, 0, SEEK_SET); - rewind(file); - amount_read = fread(&buffer, sizeof(DataPoint), QUERY_BUFSIZ, file); - s->read_offset += amount_read; - Log(LOGDEBUG, "Read %d data points; offset now at %d", amount_read, s->read_offset); - - fclose(file); - } - + fseek(s->file, -QUERY_BUFSIZ*sizeof(DataPoint), SEEK_END); + amount_read = fread(&buffer, sizeof(DataPoint), QUERY_BUFSIZ, s->file); + Log(LOGDEBUG, "Read %d data points", amount_read); + pthread_mutex_unlock(&(s->mutex)); //End critical section