--- libaitrpc/src/srv.c 2010/06/28 15:18:43 1.1.1.1.2.13 +++ libaitrpc/src/srv.c 2010/07/08 12:29:38 1.1.1.1.2.20 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.1.1.1.2.13 2010/06/28 15:18:43 misho Exp $ +* $Id: srv.c,v 1.1.1.1.2.20 2010/07/08 12:29:38 misho Exp $ * *************************************************************************/ #include "global.h" @@ -93,7 +93,7 @@ rpc_srv_dispatchCall(void *arg) ret = -6; } else if ((ret = rpc_srv_execCall(f, rpc, v)) == -1) - ret = -6; + ret = -9; else argc = rpc_srv_getValsCall(f, &vals); @@ -179,7 +179,7 @@ rpc_srv_dispatchVars(void *arg) rpc_cli_t *c = arg; rpc_srv_t *s; rpc_blob_t *b; - int cx, ret; + int ret; fd_set fds; u_char buf[sizeof(struct tagBLOBHdr)]; struct tagBLOBHdr *blob; @@ -190,7 +190,6 @@ rpc_srv_dispatchVars(void *arg) } else s = c->cli_parent; - cx = -1; do { // check for disable service at this moment? if (s->srv_blob.state == disable) { @@ -203,8 +202,8 @@ rpc_srv_dispatchVars(void *arg) ret = select(c->cli_sock + 1, &fds, NULL, NULL, NULL); if (ret == -1) { ret = -2; - } else - cx++; + } + memset(buf, 0, sizeof buf); if ((ret = recv(c->cli_sock, buf, sizeof buf, 0)) == -1) { LOGERR; @@ -222,9 +221,8 @@ rpc_srv_dispatchVars(void *arg) } else blob = (struct tagBLOBHdr*) buf; // check BLOB packet session info - if (memcmp(&blob->hdr_session, &s->srv_session, sizeof blob->hdr_session) || - blob->hdr_seq != cx) { - rpc_SetErr(EINVAL, "Error:: get invalid BLOB session in seq=%d...\n", blob->hdr_seq); + if (memcmp(&blob->hdr_session, &s->srv_session, sizeof blob->hdr_session)) { + rpc_SetErr(EINVAL, "Error:: get invalid BLOB session ...\n"); ret = -5; goto makeReply; } @@ -236,7 +234,8 @@ rpc_srv_dispatchVars(void *arg) blob->hdr_var); ret = -6; break; - } + } else + blob->hdr_len = b->blob_len; if (rpc_srv_blobMap(s, b) != -1) { ret = rpc_srv_sendBLOB(c, b); @@ -268,7 +267,7 @@ rpc_srv_dispatchVars(void *arg) makeReply: // Replay to client! blob->hdr_cmd = ret < 0 ? error : ok; - blob->hdr_seq = ret; + blob->hdr_ret = ret; if ((ret = send(c->cli_sock, buf, sizeof buf, 0)) == -1) { LOGERR; ret = -8; @@ -407,10 +406,12 @@ rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) pthread_mutex_lock(&srv->srv_blob.mtx); while ((f = srv->srv_blob.blobs)) { srv->srv_blob.blobs = f->blob_next; + rpc_srv_blobFree(srv, f); free(f); } pthread_mutex_unlock(&srv->srv_blob.mtx); + while (pthread_mutex_trylock(&srv->srv_blob.mtx) == EBUSY); pthread_mutex_destroy(&srv->srv_blob.mtx); } @@ -625,6 +626,7 @@ rpc_srv_endServer(rpc_srv_t * __restrict srv) } pthread_mutex_unlock(&srv->srv_mtx); + while (pthread_mutex_trylock(&srv->srv_mtx) == EBUSY); pthread_mutex_destroy(&srv->srv_mtx); free(srv);