summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author(no author) <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-04 16:13:43 +0800
committer(no author) <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-04 16:13:43 +0800
commit279a022993b124a6d6838e32519c96e909a2e816 (patch)
treebda64726c450f5f180b1e62e6a6b5b97a8e99909
parent7ec7b19a9fc01ce195c2d8eb4e18643d2242bb57 (diff)
downloadpttbbs-279a022993b124a6d6838e32519c96e909a2e816.tar
pttbbs-279a022993b124a6d6838e32519c96e909a2e816.tar.gz
pttbbs-279a022993b124a6d6838e32519c96e909a2e816.tar.bz2
pttbbs-279a022993b124a6d6838e32519c96e909a2e816.tar.lz
pttbbs-279a022993b124a6d6838e32519c96e909a2e816.tar.xz
pttbbs-279a022993b124a6d6838e32519c96e909a2e816.tar.zst
pttbbs-279a022993b124a6d6838e32519c96e909a2e816.zip
add get_record_keep().
we don't need to open/close the same file every time in title search mode. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1155 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/include/proto.h1
-rw-r--r--pttbbs/mbbsd/read.c16
-rw-r--r--pttbbs/mbbsd/record.c18
3 files changed, 31 insertions, 4 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h
index 84db664c..073e9520 100644
--- a/pttbbs/include/proto.h
+++ b/pttbbs/include/proto.h
@@ -366,6 +366,7 @@ void UnTagger (int locus);
int substitute_record(char *fpath, void *rptr, int size, int id);
int lock_substitute_record(char *fpath, void *rptr, int size, int id, int);
int get_record(char *fpath, void *rptr, int size, int id);
+int get_record_keep(char *fpath, void *rptr, int size, int id, int *fd);
void prints(char *fmt, ...) GCC_CHECK_FORMAT(1,2);
int append_record(char *fpath, fileheader_t *record, int size);
int stampfile(char *fpath, fileheader_t *fh);
diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c
index 009b6912..1542ace5 100644
--- a/pttbbs/mbbsd/read.c
+++ b/pttbbs/mbbsd/read.c
@@ -289,6 +289,7 @@ thread(keeploc_t * locmem, int stype)
register int now, pos, match, near = 0;
fileheader_t fh;
int circulate_flag = 1; /* circulate at end or begin */
+ int fd = -1;
match = hit_thread = 0;
now = pos = locmem->crs_ln;
@@ -357,10 +358,15 @@ thread(keeploc_t * locmem, int stype)
do {
if (!circulate_flag || stype & RS_RELATED) {
if (stype & RS_FORWARD) {
- if (++now > last_line)
+ if (++now > last_line){
+ if( fd != -1 )
+ close(fd);
return DONOTHING;
+ }
} else {
- if (--now <= 0 || now < pos - 300) {
+ if (--now <= 0 || now < pos - 200) {
+ if( fd )
+ close(fd);
if ((stype & RS_FIRST) && (near)) {
hit_thread = 1;
return cursor_pos(locmem, near, 10);
@@ -376,7 +382,7 @@ thread(keeploc_t * locmem, int stype)
now = last_line;
}
- get_record(currdirect, &fh, sizeof(fileheader_t), now);
+ get_record_keep(currdirect, &fh, sizeof(fileheader_t), now, &fd);
if (fh.owner[0] == '-')
continue;
@@ -384,6 +390,8 @@ thread(keeploc_t * locmem, int stype)
if (stype & RS_THREAD) {
if (strncasecmp(fh.title, str_reply, 3)) {
hit_thread = 1;
+ if( fd )
+ close(fd);
return cursor_pos(locmem, now, 10);
}
continue;
@@ -411,6 +419,8 @@ thread(keeploc_t * locmem, int stype)
}
} while (now != pos);
+ if( fd != -1 )
+ close(fd);
return match;
}
diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c
index 55f78787..491af517 100644
--- a/pttbbs/mbbsd/record.c
+++ b/pttbbs/mbbsd/record.c
@@ -56,11 +56,27 @@ get_sum_records(char *fpath, int size)
}
int
+get_record_keep(char *fpath, void *rptr, int size, int id, int *fd)
+{
+ /* 和 get_record() 一樣. 不過藉由 *fd, 可使同一個檔案不要一直重複開關 */
+ if (id >= 1 &&
+ (*fd > 0 ||
+ ((*fd = open(fpath, O_RDONLY, 0)) > 0))){
+ if (lseek(*fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) {
+ if (read(*fd, rptr, size) == size) {
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+int
get_record(char *fpath, void *rptr, int size, int id)
{
int fd = -1;
- if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) {
+ if (id >= 1 && (fd = open(fpath, O_RDONLY, 0)) != -1) {
if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) {
if (read(fd, rptr, size) == size) {
close(fd);