1 /* Coordinator => Machine that initiates the transaction request call for commiting a transaction
2 * Participant => Machines that host the objects involved in a transaction commit */
4 #include <netinet/tcp.h>
8 #include "threadnotify.h"
13 #define BACKLOG 10 //max pending connections
14 #define RECEIVE_BUFFER_SIZE 2048
16 extern int classsize[];
17 extern int numHostsInSystem;
18 extern pthread_mutex_t notifymutex;
19 extern unsigned int myIpAddr;
21 objstr_t *mainobjstore;
22 pthread_mutex_t mainobjstore_mutex;
23 pthread_mutex_t lockObjHeader;
24 pthread_mutexattr_t mainobjstore_mutex_attr; /* Attribute for lock to make it a recursive lock */
26 sockPoolHashTable_t *transPResponseSocketPool;
28 /* This function initializes the main objects store and creates the
29 * global machine and location lookup table */
33 mainobjstore = objstrCreate(DEFAULT_OBJ_STORE_SIZE);
34 /* Initialize attribute for mutex */
35 pthread_mutexattr_init(&mainobjstore_mutex_attr);
36 pthread_mutexattr_settype(&mainobjstore_mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);
37 pthread_mutex_init(&mainobjstore_mutex, &mainobjstore_mutex_attr);
38 pthread_mutex_init(&lockObjHeader,NULL);
39 if (mhashCreate(HASH_SIZE, LOADFACTOR))
42 if (lhashCreate(HASH_SIZE, LOADFACTOR))
45 if (notifyhashCreate(N_HASH_SIZE, N_LOADFACTOR))
48 //Initialize socket pool
49 if((transPResponseSocketPool = createSockPool(transPResponseSocketPool, 2*numHostsInSystem+1)) == NULL) {
50 printf("Error in creating new socket pool at %s line %d\n", __FILE__, __LINE__);
56 /* This function starts the thread to listen on a socket
57 * for tranaction calls */
60 int listenfd, acceptfd;
61 struct sockaddr_in my_addr;
62 struct sockaddr_in client_addr;
63 socklen_t addrlength = sizeof(struct sockaddr);
64 pthread_t thread_dstm_accept;
68 listenfd = socket(AF_INET, SOCK_STREAM, 0);
75 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &setsockflag, sizeof (setsockflag)) < 0) {
80 if (setsockopt(listenfd, SOL_SOCKET, SO_NOSIGPIPE, &setsockflag, sizeof (setsockflag)) < 0) {
86 my_addr.sin_family = AF_INET;
87 my_addr.sin_port = htons(LISTEN_PORT);
88 my_addr.sin_addr.s_addr = INADDR_ANY;
89 memset(&(my_addr.sin_zero), '\0', 8);
91 if (bind(listenfd, (struct sockaddr *)&my_addr, addrlength) == -1)
97 if (listen(listenfd, BACKLOG) == -1)
103 printf("Listening on port %d, fd = %d\n", LISTEN_PORT, listenfd);
108 acceptfd = accept(listenfd, (struct sockaddr *)&client_addr, &addrlength);
110 perror("Error in accept: ");
111 printf("error %x", acceptfd); fflush(stdout);
113 setsockopt(acceptfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(flag));
115 retval=pthread_create(&thread_dstm_accept, NULL, dstmAccept, (void *)acceptfd);
117 pthread_detach(thread_dstm_accept);
120 /* This function accepts a new connection request, decodes the control message in the connection
121 * and accordingly calls other functions to process new requests */
122 void *dstmAccept(void *acceptfd) {
123 int val, retval, size, sum, sockid;
130 trans_commit_data_t transinfo;
131 unsigned short objType, *versionarry, version;
132 unsigned int *oidarry, numoid, mid, threadid;
134 /* Receive control messages from other machines */
135 if((retval = recv_data_errorcode((int)acceptfd, &control, sizeof(char))) <= 0) {
136 printf("%s() Error: Receiving control = %d at %s, %d\n", __func__, control, __FILE__, __LINE__);
143 /* Read oid requested and search if available */
144 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
145 if((srcObj = mhashSearch(oid)) == NULL) {
146 printf("Error: Object 0x%x is not found in Main Object Store %s, %d\n", oid, __FILE__, __LINE__);
149 h = (objheader_t *) srcObj;
151 size += sizeof(objheader_t);
152 sockid = (int) acceptfd;
155 ctrl = OBJECT_NOT_FOUND;
156 send_data(sockid, &ctrl, sizeof(char));
159 char msg[]={OBJECT_FOUND, 0, 0, 0, 0};
160 *((int *)&msg[1])=size;
161 send_data(sockid, &msg, sizeof(msg));
162 send_data(sockid, h, size);
164 if((retval = recv_data_errorcode((int)acceptfd, &control, sizeof(char))) <= 0) {
167 } while(control == READ_REQUEST);
170 case READ_MULT_REQUEST:
176 case MOVE_MULT_REQUEST:
180 /* Read transaction request */
181 transinfo.objlocked = NULL;
182 transinfo.objnotfound = NULL;
183 transinfo.modptr = NULL;
184 transinfo.numlocked = 0;
185 transinfo.numnotfound = 0;
186 if((val = readClientReq(&transinfo, (int)acceptfd)) != 0) {
187 printf("Error: In readClientReq() %s, %d\n", __FILE__, __LINE__);
193 if((val = prefetchReq((int)acceptfd)) != 0) {
194 printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__);
197 if((retval = recv_data_errorcode((int)acceptfd, &control, sizeof(char))) <= 0) {
200 } while (control == TRANS_PREFETCH);
202 case TRANS_PREFETCH_RESPONSE:
204 if((val = getPrefetchResponse((int) acceptfd)) != 0) {
205 printf("Error: In getPrefetchResponse() %s, %d\n", __FILE__, __LINE__);
208 if((retval = recv_data_errorcode((int)acceptfd, &control, sizeof(char))) <= 0) {
211 } while (control == TRANS_PREFETCH_RESPONSE);
213 case START_REMOTE_THREAD:
214 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
215 objType = getObjType(oid);
216 startDSMthread(oid, objType);
219 case THREAD_NOTIFY_REQUEST:
220 recv_data((int)acceptfd, &numoid, sizeof(unsigned int));
221 size = (sizeof(unsigned int) + sizeof(unsigned short)) * numoid + 2 * sizeof(unsigned int);
222 if((buffer = calloc(1,size)) == NULL) {
223 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
227 recv_data((int)acceptfd, buffer, size);
229 oidarry = calloc(numoid, sizeof(unsigned int));
230 memcpy(oidarry, buffer, sizeof(unsigned int) * numoid);
231 size = sizeof(unsigned int) * numoid;
232 versionarry = calloc(numoid, sizeof(unsigned short));
233 memcpy(versionarry, buffer+size, sizeof(unsigned short) * numoid);
234 size += sizeof(unsigned short) * numoid;
235 mid = *((unsigned int *)(buffer+size));
236 size += sizeof(unsigned int);
237 threadid = *((unsigned int *)(buffer+size));
238 processReqNotify(numoid, oidarry, versionarry, mid, threadid);
243 case THREAD_NOTIFY_RESPONSE:
244 size = sizeof(unsigned short) + 2 * sizeof(unsigned int);
245 if((buffer = calloc(1,size)) == NULL) {
246 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
250 recv_data((int)acceptfd, buffer, size);
252 oid = *((unsigned int *)buffer);
253 size = sizeof(unsigned int);
254 version = *((unsigned short *)(buffer+size));
255 size += sizeof(unsigned short);
256 threadid = *((unsigned int *)(buffer+size));
257 threadNotify(oid,version,threadid);
261 case CLOSE_CONNECTION:
262 goto closeconnection;
265 printf("Error: dstmAccept() Unknown opcode %d at %s, %d\n", control, __FILE__, __LINE__);
269 /* Close connection */
270 if (close((int)acceptfd) == -1)
275 /* This function reads the information available in a transaction request
276 * and makes a function call to process the request */
277 int readClientReq(trans_commit_data_t *transinfo, int acceptfd) {
280 unsigned int *oidmod, oid;
282 objheader_t *headaddr;
283 int sum, i, size, n, val;
287 /* Read fixed_data_t data structure */
288 size = sizeof(fixed) - 1;
289 ptr = (char *)&fixed;;
290 fixed.control = TRANS_REQUEST;
291 recv_data((int)acceptfd, ptr+1, size);
293 /* Read list of mids */
294 int mcount = fixed.mcount;
295 size = mcount * sizeof(unsigned int);
296 unsigned int listmid[mcount];
297 ptr = (char *) listmid;
298 recv_data((int)acceptfd, ptr, size);
300 /* Read oid and version tuples for those objects that are not modified in the transaction */
301 int numread = fixed.numread;
302 size = numread * (sizeof(unsigned int) + sizeof(unsigned short));
304 if(numread != 0) { //If pile contains more than one object to be read,
305 // keep reading all objects
306 recv_data((int)acceptfd, objread, size);
309 /* Read modified objects */
310 if(fixed.nummod != 0) {
311 if ((modptr = calloc(1, fixed.sum_bytes)) == NULL) {
312 printf("calloc error for modified objects %s, %d\n", __FILE__, __LINE__);
315 size = fixed.sum_bytes;
316 recv_data((int)acceptfd, modptr, size);
319 /* Create an array of oids for modified objects */
320 oidmod = (unsigned int *) calloc(fixed.nummod, sizeof(unsigned int));
323 printf("calloc error %s, %d\n", __FILE__, __LINE__);
326 ptr = (char *) modptr;
327 for(i = 0 ; i < fixed.nummod; i++) {
329 headaddr = (objheader_t *) ptr;
332 GETSIZE(tmpsize, headaddr);
333 ptr += sizeof(objheader_t) + tmpsize;
336 /*Process the information read */
337 if((val = processClientReq(&fixed, transinfo, listmid, objread, modptr, oidmod, acceptfd)) != 0) {
338 printf("Error: In processClientReq() %s, %d\n", __FILE__, __LINE__);
354 /* This function processes the Coordinator's transaction request using "handleTransReq"
355 * function and sends a reply to the co-ordinator.
356 * Following this it also receives a new control message from the co-ordinator and processes this message*/
357 int processClientReq(fixed_data_t *fixed, trans_commit_data_t *transinfo,
358 unsigned int *listmid, char *objread, void *modptr, unsigned int *oidmod, int acceptfd) {
359 char control, sendctrl, retval;
360 objheader_t *tmp_header;
364 /* Send reply to the Coordinator */
365 if((retval = handleTransReq(fixed, transinfo, listmid, objread, modptr,acceptfd)) == 0 ) {
366 printf("Error: In handleTransReq() %s, %d\n", __FILE__, __LINE__);
370 recv_data((int)acceptfd, &control, sizeof(char));
372 /* Process the new control message */
375 if (fixed->nummod > 0)
377 /* Unlock objects that was locked due to this transaction */
378 for(i = 0; i< transinfo->numlocked; i++) {
379 if((header = mhashSearch(transinfo->objlocked[i])) == NULL) {
380 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);// find the header address
383 UnLock(STATUSPTR(header));
386 /* Send ack to Coordinator */
387 sendctrl = TRANS_UNSUCESSFUL;
388 send_data((int)acceptfd, &sendctrl, sizeof(char));
392 /* Invoke the transCommit process() */
393 if((val = transCommitProcess(modptr, oidmod, transinfo->objlocked, fixed->nummod, transinfo->numlocked, (int)acceptfd)) != 0) {
394 printf("Error: In transCommitProcess() %s, %d\n", __FILE__, __LINE__);
396 if (transinfo->objlocked != NULL) {
397 free(transinfo->objlocked);
399 if (transinfo->objnotfound != NULL) {
400 free(transinfo->objnotfound);
406 case TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING:
409 printf("Error: No response to TRANS_AGREE OR DISAGREE protocol %s, %d\n", __FILE__, __LINE__);
410 //TODO Use fixed.trans_id TID since Client may have died
415 if (transinfo->objlocked != NULL) {
416 free(transinfo->objlocked);
418 if (transinfo->objnotfound != NULL) {
419 free(transinfo->objnotfound);
425 /* This function increments counters while running a voting decision on all objects involved
426 * in TRANS_REQUEST and If a TRANS_DISAGREE sends the response immediately back to the coordinator */
427 char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigned int *listmid, char *objread, void *modptr, int acceptfd) {
429 unsigned short version;
430 char control = 0, *ptr;
432 unsigned int *oidnotfound, *oidlocked;
434 objheader_t *headptr;
436 /* Counters and arrays to formulate decision on control message to be sent */
437 oidnotfound = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
438 oidlocked = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
439 int objnotfound = 0, objlocked = 0;
440 int v_nomatch = 0, v_matchlock = 0, v_matchnolock = 0;
442 /* modptr points to the beginning of the object store
443 * created at the Pariticipant.
444 * Object store holds the modified objects involved in the transaction request */
445 ptr = (char *) modptr;
447 /* Process each oid in the machine pile/ group per thread */
448 for (i = 0; i < fixed->numread + fixed->nummod; i++) {
449 if (i < fixed->numread) {//Objs only read and not modified
450 int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array
452 oid = *((unsigned int *)(objread + incr));
453 incr += sizeof(unsigned int);
454 version = *((unsigned short *)(objread + incr));
455 } else {//Objs modified
457 headptr = (objheader_t *) ptr;
459 version = headptr->version;
460 GETSIZE(tmpsize, headptr);
461 ptr += sizeof(objheader_t) + tmpsize;
464 /* Check if object is still present in the machine since the beginning of TRANS_REQUEST */
466 if ((mobj = mhashSearch(oid)) == NULL) {/* Obj not found */
467 /* Save the oids not found and number of oids not found for later use */
468 oidnotfound[objnotfound] = oid;
470 } else { /* If Obj found in machine (i.e. has not moved) */
471 /* Check if Obj is locked by any previous transaction */
472 if (test_and_set(STATUSPTR(mobj))) {
474 if (version == ((objheader_t *)mobj)->version) { /* If locked then match versions */
476 } else {/* If versions don't match ...HARD ABORT */
478 /* Send TRANS_DISAGREE to Coordinator */
479 control = TRANS_DISAGREE;
481 for(j = 0; j < objlocked; j++) {
482 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
483 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
486 UnLock(STATUSPTR(headptr));
490 send_data(acceptfd, &control, sizeof(char));
493 } else {/* If Obj is not locked then lock object */
494 /* Save all object oids that are locked on this machine during this transaction request call */
495 oidlocked[objlocked] = OID(((objheader_t *)mobj));
497 if (version == ((objheader_t *)mobj)->version) { /* Check if versions match */
499 } else { /* If versions don't match ...HARD ABORT */
501 control = TRANS_DISAGREE;
503 for(j = 0; j < objlocked; j++) {
504 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
505 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
508 UnLock(STATUSPTR(headptr));
513 /* Send TRANS_DISAGREE to Coordinator */
514 send_data(acceptfd, &control, sizeof(char));
521 /* Decide what control message to send to Coordinator */
522 if ((control = decideCtrlMessage(fixed, transinfo, &v_matchnolock, &v_matchlock, &v_nomatch, &objnotfound, &objlocked,
523 modptr, oidnotfound, oidlocked, acceptfd)) == 0) {
524 printf("Error: In decideCtrlMessage() %s, %d\n", __FILE__, __LINE__);
531 /* This function decides what control message such as TRANS_AGREE, TRANS_DISAGREE or TRANS_SOFT_ABORT
532 * to send to Coordinator based on the votes of oids involved in the transaction */
533 char decideCtrlMessage(fixed_data_t *fixed, trans_commit_data_t *transinfo, int *v_matchnolock, int *v_matchlock,
534 int *v_nomatch, int *objnotfound, int *objlocked, void *modptr,
535 unsigned int *oidnotfound, unsigned int *oidlocked, int acceptfd) {
539 /* Condition to send TRANS_AGREE */
540 if(*(v_matchnolock) == fixed->numread + fixed->nummod) {
541 control = TRANS_AGREE;
542 /* Send control message */
543 send_data(acceptfd, &control, sizeof(char));
545 /* Condition to send TRANS_SOFT_ABORT */
546 if((*(v_matchlock) > 0 && *(v_nomatch) == 0) || (*(objnotfound) > 0 && *(v_nomatch) == 0)) {
547 control = TRANS_SOFT_ABORT;
549 /* Send control message */
550 send_data(acceptfd, &control, sizeof(char));
552 /* Send number of oids not found and the missing oids if objects are missing in the machine */
553 if(*(objnotfound) != 0) {
555 msg[0] = *(objnotfound);
556 send_data(acceptfd, &msg, sizeof(int));
557 int size = sizeof(unsigned int)* *(objnotfound);
558 send_data(acceptfd, oidnotfound, size);
562 /* Fill out the trans_commit_data_t data structure. This is required for a trans commit process
563 * if Participant receives a TRANS_COMMIT */
564 transinfo->objlocked = oidlocked;
565 transinfo->objnotfound = oidnotfound;
566 transinfo->modptr = modptr;
567 transinfo->numlocked = *(objlocked);
568 transinfo->numnotfound = *(objnotfound);
573 /* This function processes all modified objects involved in a TRANS_COMMIT and updates pointer
574 * addresses in lookup table and also changes version number
575 * Sends an ACK back to Coordinator */
576 int transCommitProcess(void *modptr, unsigned int *oidmod, unsigned int *oidlocked, int nummod, int numlocked, int acceptfd) {
578 objheader_t *newheader;
579 int i = 0, offset = 0;
583 /* Process each modified object saved in the mainobject store */
584 for(i = 0; i < nummod; i++) {
585 if((header = (objheader_t *) mhashSearch(oidmod[i])) == NULL) {
586 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
589 GETSIZE(tmpsize,header);
590 memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
591 header->version += 1;
592 /* If threads are waiting on this object to be updated, notify them */
593 if(header->notifylist != NULL) {
594 notifyAll(&header->notifylist, OID(header), header->version);
596 offset += sizeof(objheader_t) + tmpsize;
602 /* Unlock locked objects */
603 for(i = 0; i < numlocked; i++) {
604 if((header = (objheader_t *) mhashSearch(oidlocked[i])) == NULL) {
605 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
608 UnLock(STATUSPTR(header));
610 //TODO Update location lookup table
612 /* Send ack to coordinator */
613 control = TRANS_SUCESSFUL;
614 send_data((int)acceptfd, &control, sizeof(char));
618 /* This function recevies the oid and offset tuples from the Coordinator's prefetch call.
619 * Looks for the objects to be prefetched in the main object store.
620 * If objects are not found then record those and if objects are found
621 * then use offset values to prefetch references to other objects */
623 int prefetchReq(int acceptfd) {
624 int i, size, objsize, numoffset = 0;
626 char *recvbuffer, control;
627 unsigned int oid, mid=-1;
633 recv_data((int)acceptfd, &numoffset, sizeof(int));
636 recv_data((int)acceptfd, &oidmid, 2*sizeof(unsigned int));
638 if (mid != oidmid.mid) {
640 freeSockWithLock(transPResponseSocketPool, mid, sd);
643 sd = getSockWithLock(transPResponseSocketPool, mid);
645 short offsetarry[numoffset];
646 recv_data((int) acceptfd, offsetarry, numoffset*sizeof(short));
648 /*Process each oid */
649 if ((header = mhashSearch(oid)) == NULL) {/* Obj not found */
650 /* Save the oids not found in buffer for later use */
651 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
652 char sendbuffer[size];
653 *((int *) sendbuffer) = size;
654 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
655 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
656 control = TRANS_PREFETCH_RESPONSE;
657 sendPrefetchResponse(sd, &control, sendbuffer, &size);
658 } else { /* Object Found */
660 GETSIZE(objsize, header);
661 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
662 char sendbuffer[size];
663 *((int *) (sendbuffer + incr)) = size;
665 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
666 incr += sizeof(char);
667 *((unsigned int *)(sendbuffer+incr)) = oid;
668 incr += sizeof(unsigned int);
669 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
671 control = TRANS_PREFETCH_RESPONSE;
672 sendPrefetchResponse(sd, &control, sendbuffer, &size);
674 /* Calculate the oid corresponding to the offset value */
675 for(i = 0 ; i< numoffset ; i++) {
676 /* Check for arrays */
677 if(TYPE(header) > NUMCLASSES) {
678 int elementsize = classsize[TYPE(header)];
679 struct ArrayObject *ao = (struct ArrayObject *) (((char *)header) + sizeof(objheader_t));
680 unsigned short length = ao->___length___;
681 /* Check if array out of bounds */
682 if(offsetarry[i]< 0 || offsetarry[i] >= length) {
685 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + sizeof(struct ArrayObject) + (elementsize*offsetarry[i])));
687 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + offsetarry[i]));
690 /* Don't continue if we hit a NULL pointer */
694 if((header = mhashSearch(oid)) == NULL) {
695 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
696 char sendbuffer[size];
697 *((int *) sendbuffer) = size;
698 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
699 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
701 control = TRANS_PREFETCH_RESPONSE;
702 sendPrefetchResponse(sd, &control, sendbuffer, &size);
704 } else {/* Obj Found */
706 GETSIZE(objsize, header);
707 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
708 char sendbuffer[size];
709 *((int *) (sendbuffer + incr)) = size;
711 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
712 incr += sizeof(char);
713 *((unsigned int *)(sendbuffer+incr)) = oid;
714 incr += sizeof(unsigned int);
715 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
717 control = TRANS_PREFETCH_RESPONSE;
718 sendPrefetchResponse(sd, &control, sendbuffer, &size);
725 freeSockWithLock(transPResponseSocketPool, mid, sd);
730 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size) {
731 send_data(sd, control, sizeof(char));
732 /* Send the buffer with its size */
733 int length = *(size);
734 send_data(sd, sendbuffer, length);
737 void processReqNotify(unsigned int numoid, unsigned int *oidarry, unsigned short *versionarry, unsigned int mid, unsigned int threadid) {
740 unsigned short newversion;
741 char msg[1+ 2 * sizeof(unsigned int) + sizeof(unsigned short)];
743 struct sockaddr_in remoteAddr;
749 oid = *(oidarry + i);
750 if((header = (objheader_t *) mhashSearch(oid)) == NULL) {
751 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
754 /* Check to see if versions are same */
756 if (test_and_set(STATUSPTR(header))==0) {
758 newversion = header->version;
759 if(newversion == *(versionarry + i)) {
760 //Add to the notify list
761 if((header->notifylist = insNode(header->notifylist, threadid, mid)) == NULL) {
762 printf("Error: Obj notify list points to NULL %s, %d\n", __FILE__, __LINE__);
765 UnLock(STATUSPTR(header));
767 UnLock(STATUSPTR(header));
768 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
769 perror("processReqNotify():socket()");
772 bzero(&remoteAddr, sizeof(remoteAddr));
773 remoteAddr.sin_family = AF_INET;
774 remoteAddr.sin_port = htons(LISTEN_PORT);
775 remoteAddr.sin_addr.s_addr = htonl(mid);
777 if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
778 printf("Error: processReqNotify():error %d connecting to %s:%d\n", errno,
779 inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
783 //Send Update notification
784 msg[0] = THREAD_NOTIFY_RESPONSE;
785 *((unsigned int *)&msg[1]) = oid;
786 size = sizeof(unsigned int);
787 *((unsigned short *)(&msg[1]+size)) = newversion;
788 size += sizeof(unsigned short);
789 *((unsigned int *)(&msg[1]+size)) = threadid;
790 size = 1+ 2*sizeof(unsigned int) + sizeof(unsigned short);
791 send_data(sd, msg, size);