diff --git a/client.c b/client.c index e8c10c4..e29f193 100644 --- a/client.c +++ b/client.c @@ -27,8 +27,8 @@ static struct sockaddr_in their_addr; static pthread_t thread; static uint32_t file_size; static int recv_bin = 0; -static char pwd[64] = "testpwd"; -static char sps[64] = "testsps"; +static char pwd[64] = "fumiama"; +static char sps[64] = "minamoto"; void getMessage(void *p) { int c = 0, offset = 0; diff --git a/server.c b/server.c index 294cbbf..bf0f5c0 100644 --- a/server.c +++ b/server.c @@ -241,9 +241,9 @@ static int s1_get(THREADTIMER *timer) { static int s2_set(THREADTIMER *timer) { uint8_t digest[16]; + timer->lock_type = DICT_LOCK_EX; FILE *fp = open_dict(DICT_LOCK_EX, timer->index); if(fp) { - timer->lock_type = DICT_LOCK_EX; md5((uint8_t*)timer->dat, strlen(timer->dat)+1, digest); uint8_t* dp = digest; int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ; @@ -350,10 +350,10 @@ static void del(FILE *fp, char* key, int len, char ret[4]) { static int s4_del(THREADTIMER *timer) { uint8_t digest[16]; char ret[4]; + timer->lock_type = DICT_LOCK_EX; FILE *fp = open_dict(DICT_LOCK_EX, timer->index); //timer->status = 0; if(fp) { - timer->lock_type = DICT_LOCK_EX; md5((uint8_t*)timer->dat, strlen(timer->dat)+1, digest); uint8_t* dp = digest; int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ; @@ -367,6 +367,7 @@ static int s4_del(THREADTIMER *timer) { del(fp, timer->dat, timer->numbytes+1, ret); return close_and_send(timer, ret, 4); } + timer->lock_type = DICT_LOCK_UN; return close_and_send(timer, "null", 4); } @@ -392,7 +393,9 @@ static void accept_timer(void *p) { sleep(MAXWAITSEC / 4); time_t waitsec = time(NULL) - timer->touch; printf("Wait sec: %u, max: %u\n", (unsigned int)waitsec, MAXWAITSEC); - if(waitsec > MAXWAITSEC) break; + if(timer->lock_type == DICT_LOCK_EX) { + if(waitsec > MAXWAITSEC*THREADCNT) break; + } else if(waitsec > MAXWAITSEC) break; } pthread_t thread = accept_threads[index]; if(thread) { diff --git a/server.h b/server.h index d661f54..a901034 100644 --- a/server.h +++ b/server.h @@ -4,7 +4,7 @@ #include #define THREADCNT 16 -#define MAXWAITSEC 10 +#define MAXWAITSEC 4 // DICTPOOLBIT must be lower than 4*8 = 32 #define DICTPOOLBIT 16