summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-04 19:01:57 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-04 19:01:57 +0800
commit9c6563c6e1d6e54655e59b828d10e9713655ba84 (patch)
tree863365730b8e53c45448bd2336bb3b45f56eac3a /mbbsd
parent9f9f9619a9fe96a172ec444373224625a3f09df6 (diff)
downloadpttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.tar
pttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.tar.gz
pttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.tar.bz2
pttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.tar.lz
pttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.tar.xz
pttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.tar.zst
pttbbs-9c6563c6e1d6e54655e59b828d10e9713655ba84.zip
read 8k once instead of 128bytes,
reduce system calls. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1157 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/bbs.c18
-rw-r--r--mbbsd/read.c83
2 files changed, 60 insertions, 41 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 50a5eee3..27c8ab25 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -659,16 +659,18 @@ do_generalboardreply(fileheader_t * fhdr)
int
getindex(char *fpath, char *fname, int size)
{
- int fd, now = 0;
- fileheader_t fhdr;
+#define READSIZE 64 // 8192 / sizeof(fileheader_t)
+ int fd, i, len, now = 1; /* now starts from 1 */
+ fileheader_t fhdrs[READSIZE];
if ((fd = open(fpath, O_RDONLY, 0)) != -1) {
- while ((read(fd, &fhdr, size) == size)) {
- now++;
- if (!strcmp(fhdr.filename, fname)) {
- close(fd);
- return now;
- }
+ while( (len = read(fd, fhdrs, sizeof(fhdrs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i, ++now )
+ if (!strcmp(fhdrs[i].filename, fname)) {
+ close(fd);
+ return now;
+ }
}
close(fd);
}
diff --git a/mbbsd/read.c b/mbbsd/read.c
index 1542ace5..cd20bd44 100644
--- a/mbbsd/read.c
+++ b/mbbsd/read.c
@@ -457,12 +457,13 @@ mail_forward(fileheader_t * fhdr, char *direct, int mode)
static int
select_read(keeploc_t * locmem, int sr_mode)
{
+#define READSIZE 64 // 8192 / sizeof(fileheader_t)
char *tag, *query = NULL, *temp;
- fileheader_t fh;
+ fileheader_t fhs[READSIZE];
char fpath[80], genbuf[MAXPATHLEN], buf3[5];
static char t_ans[TTLEN + 1] = "";
static char a_ans[TTLEN + 1] = "";
- int fd, fr, size = sizeof(fileheader_t);
+ int fd, fr, size = sizeof(fileheader_t), i, len;
struct stat st;
/* rocker.011018: make a reference number for process article */
int reference = 0;
@@ -500,51 +501,67 @@ select_read(keeploc_t * locmem, int sr_mode)
if (((fr = open(fpath, O_WRONLY | O_CREAT | O_TRUNC, 0600)) != -1)) {
switch (sr_mode) {
case RS_TITLE:
- while (read(fd, &fh, size) == size) {
- ++reference;
- tag = subject(fh.title);
- if (!strncmp(tag, query, 40)) {
- fh.money = reference | FHR_REFERENCE;
- write(fr, &fh, size);
+ while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i ){
+ ++reference;
+ tag = subject(fhs[i].title);
+ if (!strncmp(tag, query, 40)) {
+ fhs[i].money = reference | FHR_REFERENCE;
+ write(fr, &fhs[i], size);
+ }
}
}
break;
case RS_RELATED:
- while (read(fd, &fh, size) == size) {
- ++reference;
- tag = fh.title;
- if (strcasestr(tag, query)) {
- fh.money = reference | FHR_REFERENCE;
- write(fr, &fh, size);
+ while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i ){
+ ++reference;
+ tag = fhs[i].title;
+ if (strcasestr(tag, query)) {
+ fhs[i].money = reference | FHR_REFERENCE;
+ write(fr, &fhs[i], size);
+ }
}
}
break;
case RS_NEWPOST:
- while (read(fd, &fh, size) == size) {
- ++reference;
- tag = fh.title;
- temp = strstr(tag, query);
- if (temp == NULL || temp != tag) {
- fh.money = reference | FHR_REFERENCE;
- write(fr, &fh, size);
+ while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i ){
+ ++reference;
+ tag = fhs[i].title;
+ temp = strstr(tag, query);
+ if (temp == NULL || temp != tag) {
+ fhs[i].money = reference | FHR_REFERENCE;
+ write(fr, &fhs[i], size);
+ }
}
}
+ break;
case RS_AUTHOR:
- while (read(fd, &fh, size) == size) {
- ++reference;
- tag = fh.owner;
- if (strcasestr(tag, query)) {
- fh.money = reference | FHR_REFERENCE;
- write(fr, &fh, size);
+ while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i ){
+ ++reference;
+ tag = fhs[i].owner;
+ if (strcasestr(tag, query)) {
+ fhs[i].money = reference | FHR_REFERENCE;
+ write(fr, &fhs[i], size);
+ }
}
}
break;
- case RS_THREAD:
- while (read(fd, &fh, size) == size) {
- ++reference;
- if (fh.filemode & FILE_MARKED) {
- fh.money = reference | FHR_REFERENCE;
- write(fr, &fh, size);
+ case RS_THREAD:
+ while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i ){
+ ++reference;
+ if (fhs[i].filemode & FILE_MARKED) {
+ fhs[i].money = reference | FHR_REFERENCE;
+ write(fr, &fhs[i], size);
+ }
}
}
break;