summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-04 17:59:40 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-04 17:59:40 +0800
commit983a7b8ef01b03cc7596751f431277ed7540c713 (patch)
tree9330d2b190001e4f884a8cf8fd58db84094ac39e /mbbsd
parenteb86d8ff553917f392c556ef3a4b846910b1a17a (diff)
downloadpttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.tar
pttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.tar.gz
pttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.tar.bz2
pttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.tar.lz
pttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.tar.xz
pttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.tar.zst
pttbbs-983a7b8ef01b03cc7596751f431277ed7540c713.zip
merge from outtacache branch
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1689 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/cal.c7
-rw-r--r--mbbsd/stuff.c69
-rw-r--r--mbbsd/talk.c25
3 files changed, 97 insertions, 4 deletions
diff --git a/mbbsd/cal.c b/mbbsd/cal.c
index 462818de..43c0d2f5 100644
--- a/mbbsd/cal.c
+++ b/mbbsd/cal.c
@@ -431,9 +431,14 @@ p_sysinfo(void)
prints("記憶體用量: sbrk: %d KB, idrss: %d KB, isrss: %d KB\n",
((int)sbrk(0) - 0x8048000) / 1024,
(int)ru.ru_idrss, (int)ru.ru_isrss);
+ prints("特別參數:"
#ifdef CRITICAL_MEMORY
- prints("目前在 CRITICAL_MEMORY 模式下\n");
+ " CRITICAL_MEMORY"
#endif
+#ifdef OUTTACACHE
+ " OUTTACACHE"
+#endif
+ );
}
pressanykey();
return 0;
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c
index 767fdca1..008f18f9 100644
--- a/mbbsd/stuff.c
+++ b/mbbsd/stuff.c
@@ -694,3 +694,72 @@ int qsort_intcompar(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
+
+#ifdef OUTTACACHE
+#include <err.h>
+int tobind(int port)
+{
+ int sockfd, val;
+ struct sockaddr_in servaddr;
+
+ if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
+ err(1, NULL);
+ setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
+ (char *)&val, sizeof(val));
+ bzero(&servaddr, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ servaddr.sin_port = htons(port);
+ if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 )
+ err(1, NULL);
+ if( listen(sockfd, 5) < 0 )
+ err(1, NULL);
+
+ return sockfd;
+}
+
+int toconnect(char *host, int port)
+{
+ int sock;
+ struct sockaddr_in serv_name;
+ if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
+ perror("socket");
+ return -1;
+ }
+
+ serv_name.sin_family = AF_INET;
+ serv_name.sin_addr.s_addr = inet_addr(host);
+ serv_name.sin_port = htons(port);
+ if( connect(sock, (struct sockaddr*)&serv_name, sizeof(serv_name)) < 0 ){
+ close(sock);
+ return -1;
+ }
+ return sock;
+}
+
+int toread(int fd, void *buf, int len)
+{
+ int l;
+ for( l = 0 ; len > 0 ; )
+ if( (l = read(fd, buf, len)) <= 0 )
+ return -1;
+ else{
+ buf += l;
+ len -= l;
+ }
+ return l;
+}
+
+int towrite(int fd, void *buf, int len)
+{
+ int l;
+ for( l = 0 ; len > 0 ; )
+ if( (l = write(fd, buf, len)) <= 0 )
+ return -1;
+ else{
+ buf += l;
+ len -= l;
+ }
+ return l;
+}
+#endif
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index 8052ae5a..23a5a305 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -210,12 +210,31 @@ reverse_friend_stat(int stat)
return stat1;
}
-int
-login_friend_online(void)
+void login_friend_online(void)
{
userinfo_t *uentp;
int i, stat, stat1;
int offset = (int)(currutmp - &SHM->uinfo[0]);
+#ifdef OUTTACACHE
+ int sfd;
+ if( (sfd = toconnect(OUTTACACHEHOST, OUTTACACHEPORT)) > 0 ){
+ if( towrite(sfd, &offset, sizeof(offset)) > 0 &&
+ towrite(sfd, &currutmp->uid, sizeof(currutmp->uid)) > 0 &&
+ towrite(sfd, currutmp->friend, sizeof(currutmp->friend)) > 0 &&
+ towrite(sfd, currutmp->reject, sizeof(currutmp->reject)) > 0 ){
+ ocfs_t fs;
+ while( toread(sfd, &fs, sizeof(fs)) > 0 )
+ if( SHM->uinfo[fs.index].uid == fs.uid ){
+ currutmp->friend_online[currutmp->friendtotal++]
+ = fs.friendstat;
+ SHM->uinfo[fs.index].friend_online[ SHM->uinfo[fs.index].friendtotal++ ] = fs.rfriendstat;
+ }
+ close(sfd);
+ return;
+ }
+ close(sfd);
+ }
+#endif
for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) {
uentp = (SHM->sorted[SHM->currsorted][0][i]);
if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) {
@@ -230,7 +249,7 @@ login_friend_online(void)
}
}
}
- return 0;
+ return;
}
int