X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fquery.c;fp=server%2Fquery.c;h=86696bb518a00ba1221d3c357cfcb27d6f6eff9c;hb=97d3625dcb84e6371d2464c93ae9bef8a3d4b466;hp=8499e37c62aede2281b0fba355c11934ab89994b;hpb=69483d953c93566731f72445a077dfcf60e01bf3;p=matches%2FMCTX3420.git diff --git a/server/query.c b/server/query.c index 8499e37..86696bb 100644 --- a/server/query.c +++ b/server/query.c @@ -25,21 +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, (s->read_offset)*sizeof(DataPoint), SEEK_SET); - 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