summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/board.c47
-rw-r--r--mbbsd/cache.c105
2 files changed, 111 insertions, 41 deletions
diff --git a/mbbsd/board.c b/mbbsd/board.c
index 2f2dff2b..346de070 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -1,4 +1,4 @@
-/* $Id: board.c,v 1.50 2002/08/07 10:00:13 in2 Exp $ */
+/* $Id: board.c,v 1.51 2002/08/19 14:47:40 in2 Exp $ */
#include "bbs.h"
#define BRC_STRLEN 15 /* Length of board name */
#define BRC_MAXSIZE 24576
@@ -226,10 +226,6 @@ static boardstat_t *nbrd = NULL;
#define STR_BBSRC ".bbsrc"
#define STR_FAV ".fav"
-#ifdef OUTTA_CACHE
-int zaplength, favlength;
-#endif
-
void
init_brdbuf()
{
@@ -239,11 +235,18 @@ init_brdbuf()
/* MAXBOARDS ==> 至多看得見 32 個新板 */
n = numboards + 32;
size = n * sizeof(int);
+#ifdef OUTTA_CACHE
+ zapbuf = (int *)outta_malloc(size, 'z');
+ favbuf = (int *)outta_malloc(size + sizeof(int), 'f');
+#else
zapbuf = (int *)malloc(size);
favbuf = (int *)malloc(size + sizeof(int));
+#endif
+#if 0
favbuf[0] = 0x5c4d3e; /* for check memory */
++favbuf;
+#endif
memset(favbuf, 0, size);
@@ -265,8 +268,8 @@ init_brdbuf()
brc_expire_time = login_start_time - 365 * 86400;
#ifdef OUTTA_CACHE
- outta_swapout((void **)&favbuf, (favlength = size + 4), 'f');
- outta_swapout((void **)&zapbuf, (zaplength = size), 'z');
+ outta_swapout((void **)&favbuf);
+ outta_swapout((void **)&zapbuf);
#endif
}
@@ -280,8 +283,8 @@ save_brdbuf()
return;
reentrant = 1;
#ifdef OUTTA_CACHE
- outta_swapin((void **)&favbuf, favlength, 'f');
- outta_swapin((void **)&zapbuf, zaplength, 'z');
+ outta_swapin((void **)&favbuf, 'f');
+ outta_swapin((void **)&zapbuf, 'z');
#endif
if (!zapbuf)
return;
@@ -291,12 +294,14 @@ save_brdbuf()
write(fd, zapbuf, size);
close(fd);
}
+#if 0
if (favbuf[-1] != 0x5c4d3e) {
FILE *fp = fopen(BBSHOME "/log/memorybad", "a");
fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]);
fclose(fp);
return;
}
+#endif
setuserfile(fname, STR_FAV);
if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) {
size = numboards * sizeof(int);
@@ -463,7 +468,7 @@ load_boards(char *key)
brdnum = 0;
if (class_bid <= 0) {
nbrdlength = numboards * sizeof(boardstat_t);
- nbrd = (boardstat_t *) malloc(nbrdlength);
+ nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b');
for (i = 0; i < numboards; i++) {
if ((bptr = SHM->bsorted[type][i]) == NULL)
continue;
@@ -482,7 +487,7 @@ load_boards(char *key)
}
} else {
nbrdlength = bptr->childcount * sizeof(boardstat_t);
- nbrd = (boardstat_t *) malloc(nbrdlength);
+ nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b');
for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0;
bptr = bptr->next[type]) {
n = (int)(bptr - bcache);
@@ -729,9 +734,9 @@ choose_board(int newflag)
static char depth = 0;
++depth;
if( favbuf == NULL )
- outta_swapin((void **)&favbuf, favlength, 'f');
+ outta_swapin((void **)&favbuf, 'f');
if( zapbuf == NULL )
- outta_swapin((void **)&zapbuf, zaplength, 'z');
+ outta_swapin((void **)&zapbuf, 'z');
#endif
setutmpmode(newflag ? READNEW : READBRD);
brdnum = 0;
@@ -1042,15 +1047,15 @@ choose_board(int newflag)
if (!(ptr->myattr & BRD_ZAP))
zapbuf[ptr->bid - 1] = now;
#ifdef OUTTA_CACHE
- outta_swapout((void **)&favbuf, favlength, 'f');
- outta_swapout((void **)&zapbuf, zaplength, 'z');
- outta_swapout((void **)&nbrd, nbrdlength, 'b');
+ outta_swapout((void **)&favbuf);
+ outta_swapout((void **)&zapbuf);
+ outta_swapout((void **)&nbrd);
#endif
Read();
#ifdef OUTTA_CACHE
- outta_swapin((void **)&favbuf, favlength, 'f');
- outta_swapin((void **)&zapbuf, zaplength, 'z');
- outta_swapin((void **)&nbrd, nbrdlength, 'b');
+ outta_swapin((void **)&favbuf, 'f');
+ outta_swapin((void **)&zapbuf, 'z');
+ outta_swapin((void **)&nbrd, 'b');
ptr = &nbrd[num];
#endif
check_newpost(ptr);
@@ -1101,8 +1106,8 @@ choose_board(int newflag)
free(nbrd);
#ifdef OUTTA_CACHE
if( --depth == 0 ){
- outta_swapout((void **)&favbuf, favlength, 'f');
- outta_swapout((void **)&zapbuf, zaplength, 'z');
+ outta_swapout((void **)&favbuf);
+ outta_swapout((void **)&zapbuf);
}
#endif
}
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 27202de7..c824b4f6 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -1,4 +1,4 @@
-/* $Id: cache.c,v 1.47 2002/08/07 09:32:38 in2 Exp $ */
+/* $Id: cache.c,v 1.48 2002/08/19 14:47:41 in2 Exp $ */
#include "bbs.h"
#ifndef __FreeBSD__
@@ -1131,35 +1131,100 @@ mdcacheopen(char *fpath)
#endif
#ifdef OUTTA_CACHE
-void outta_swapout(void **ptr, int length, char cacheid)
+#include <err.h>
+static ssize_t Read(int fd, void *BUF, size_t nbytes)
{
- char fn[64];
+ char *buf = (char *)BUF;
+ ssize_t thisgot, totalgot = nbytes;
+ while( nbytes > 0 ){
+ if( (thisgot = read(fd, buf, nbytes)) <= 0 )
+ err(1, "read from socket: ");
+ nbytes -= thisgot;
+ buf += thisgot;
+ }
+ return totalgot;
+}
+
+static ssize_t Write(int fd, void *BUF, size_t nbytes)
+{
+ char *buf = (char *)BUF;
+ ssize_t thisgot, totalgot = nbytes;
+ while( nbytes > 0 ){
+ if( (thisgot = write(fd, buf, nbytes)) <= 0 )
+ err(1, "read from socket: ");
+ nbytes -= thisgot;
+ buf += thisgot;
+ }
+ return totalgot;
+}
+
+int connectserver(char *host, int port)
+{
+ struct sockaddr_in servaddr;
int fd;
+
+ if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
+ err(1, "socket");
+ bzero(&servaddr, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ inet_pton(AF_INET, host, &servaddr.sin_addr);
+ servaddr.sin_port = htons(port);
+ if( connect(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 )
+ err(1, "connect");
+ return fd;
+}
+
+void *outta_malloc(size_t size, char id)
+{
+ OCbuf_t *ptr = (OCbuf_t *)malloc(OC_HEADERLEN + size);
#ifdef DEBUG
- vmsg("swap out (%c) %d bytes", cacheid, length);
+ vmsg("outta_malloc(%d, %c)", size, id);
#endif
- sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid);
- if( (fd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 )
- abort_bbs(0);
- write(fd, *ptr, length);
+ ptr->key.pid = getpid();
+ ptr->key.cacheid = id;
+ ptr->length = size;
+ return ptr->buf;
+}
+
+void outta_swapout(void **inptr)
+{
+ OCbuf_t *ptr = (OCbuf_t *)(*inptr - OC_HEADERLEN);
+ int fd, len;
+ fd = connectserver("10.2.1.2", 1477);
+ len = ptr->length + OC_HEADERLEN;
+#ifdef DEBUG
+ vmsg("outta_swapout(%d)", len);
+#endif
+ Write(fd, &len, sizeof(len));
+ Write(fd, ptr, len);
close(fd);
- free(*ptr);
- *ptr = NULL;
+ free(ptr);
+ *inptr = NULL;
}
-void outta_swapin(void **ptr, int length, char cacheid)
+void *outta_swapin(void **inptr, char cacheid)
{
- char fn[64];
- int fd;
+ char buf[OC_HEADERLEN];
+ OCbuf_t *ptr = (OCbuf_t *)buf;
+ int fd, len;
+
+ fd = connectserver("10.2.1.2", 1477);
+ ptr->key.pid = getpid() + OC_pidadd;
+ ptr->key.cacheid = cacheid;
+ ptr->length = 0;
+ len = OC_HEADERLEN;
+ Write(fd, &len, sizeof(len));
+ Write(fd, ptr, OC_HEADERLEN);
+
+ Read(fd, &len, sizeof(len));
#ifdef DEBUG
- vmsg("swap in (%c) %d bytes", cacheid, length);
+ vmsg("outta_swapin(%d)", len);
#endif
- sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid);
- if( (fd = open(fn, O_RDONLY)) < 0 )
- abort_bbs(0);
- *ptr = (void *)malloc(length);
- read(fd, *ptr, length);
+ ptr = (OCbuf_t *)malloc(len);
+ Read(fd, ptr, len);
close(fd);
- unlink(fn);
+
+ return (*inptr = ptr->buf);
}
+
#endif