From 6eac320f0270a36f06b9c1f0fe51e37ba9ed3fc3 Mon Sep 17 00:00:00 2001 From: ptt Date: Wed, 21 Dec 2005 17:03:41 +0000 Subject: save IO from check mail git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3257 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/mail.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'mbbsd/mail.c') diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 67ef0ec8..3bf0dd47 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1868,7 +1868,7 @@ load_mailalert(const char *userid) struct stat st; char maildir[MAXPATHLEN]; int fd; - register int numfiles; + register int num; fileheader_t my_mail; sethomedir(maildir, userid); @@ -1876,14 +1876,15 @@ load_mailalert(const char *userid) return 0; if (stat(maildir, &st) < 0) return 0; - numfiles = st.st_size / sizeof(fileheader_t); - if (numfiles <= 0) + num = st.st_size / sizeof(fileheader_t); + if (num <= 0) return 0; + if (num > 50) num = 50; //check only 50 mails /* 看看有沒有信件還沒讀過?從檔尾回頭檢查,效率較高 */ if ((fd = open(maildir, O_RDONLY)) > 0) { lseek(fd, st.st_size - sizeof(fileheader_t), SEEK_SET); - while (numfiles--) { + while (num--) { read(fd, &my_mail, sizeof(fileheader_t)); if (!(my_mail.filemode & FILE_READ)) { close(fd); -- cgit v1.2.3