2014年08月09日 pobox-1.2.6 enhance patch [長年日記]
_ pobox-1.2.6 enhance patch
Orginal pbserver can answer max 40 words in one query. This patch makes pbserver to be able to answer max 256 words.
And This patch also makes pbserver to be able to save learndic when accept signal(INT, TERM).
*** server/pbserver.html.ORG 2015-12-28 14:47:50.942454872 +0900 --- server/pbserver.html 2015-12-28 14:48:35.676895615 +0900 *************** *** 45,53 **** --- 45,57 ---- #else #include <strings.h> #endif + #include <signal.h> + #include <sys/signal.h> #include "server.h" #include "poboxlib.h" + void sigtrap(int); + #ifdef USE_PROFILER #include <sys/time.h> struct timeval ts,te; *************** *** 67,73 **** #define POBOXSERVERPORT 1178 ! #define MAXCANDS 100 #define MAXWORDLEN 100 unsigned char *cands[MAXCANDS],*candspat[MAXCANDS]; --- 71,77 ---- #define POBOXSERVERPORT 1178 ! #define MAXCANDS 256 #define MAXWORDLEN 100 unsigned char *cands[MAXCANDS],*candspat[MAXCANDS]; *************** *** 121,126 **** --- 125,133 ---- #else main(int argc, char **argv) { + signal(SIGINT, sigtrap); + signal(SIGTERM, sigtrap); + if(argc > 1) poboxdebug = 1; #endif if(pobox_init() < 0) exit(0); *************** *** 137,143 **** process(int sock) { ! unsigned char buf[1000],combuf[BUFSIZE]; unsigned char w[100],p[100]; int i,n; --- 144,150 ---- process(int sock) { ! unsigned char buf[65536],combuf[BUFSIZE]; unsigned char w[100],p[100]; int i,n; *************** *** 178,187 **** else { strcpy(buf,"1\t"); for(i=0;i< n;i++){ ! strcat(buf,cands[i]); ! strcat(buf,"\t"); } - strcat(buf,"\n"); } if(send(sock, buf, strlen(buf), 0) < 0) return -1; return 0; --- 185,199 ---- else { strcpy(buf,"1\t"); for(i=0;i< n;i++){ ! strncat(buf,cands[i],sizeof(buf) - strlen(buf) - 1); ! strncat(buf,"\t",sizeof(buf) - strlen(buf) - 1); ! } ! if ((sizeof(buf) - strlen(buf)) < 2){ ! buf[sizeof(buf) - 2] = '\n'; ! buf[sizeof(buf) - 1] = '\0'; ! }else{ ! strncat(buf,"\n",sizeof(buf) - strlen(buf) - 1); } } if(send(sock, buf, strlen(buf), 0) < 0) return -1; return 0; *************** *** 234,239 **** --- 246,257 ---- return -1; } } + + void sigtrap(int signum) + { + pobox_save(&learndic); + exit(1); + } </pre> *** server/poboxlib.html.ORG 2015-12-28 14:48:00.738332407 +0900 --- server/poboxlib.html 2015-12-28 14:48:28.735982388 +0900 *************** *** 574,580 **** // ///////////////////////////////////////////////////////////////// ! #define MAXCANDS 40 static UCHAR *cands[MAXCANDS]; static UCHAR *candspat[MAXCANDS]; static int ncands = 0; --- 574,580 ---- // ///////////////////////////////////////////////////////////////// ! #define MAXCANDS 256 static UCHAR *cands[MAXCANDS]; static UCHAR *candspat[MAXCANDS]; static int ncands = 0;