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;
20 objstr_t *mainobjstore;
21 pthread_mutex_t mainobjstore_mutex;
22 pthread_mutex_t lockObjHeader;
23 pthread_mutexattr_t mainobjstore_mutex_attr; /* Attribute for lock to make it a recursive lock */
25 sockPoolHashTable_t *transPResponseSocketPool;
27 /* This function initializes the main objects store and creates the
28 * global machine and location lookup table */
32 mainobjstore = objstrCreate(DEFAULT_OBJ_STORE_SIZE);
33 /* Initialize attribute for mutex */
34 pthread_mutexattr_init(&mainobjstore_mutex_attr);
35 pthread_mutexattr_settype(&mainobjstore_mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);
36 pthread_mutex_init(&mainobjstore_mutex, &mainobjstore_mutex_attr);
37 pthread_mutex_init(&lockObjHeader,NULL);
38 if (mhashCreate(HASH_SIZE, LOADFACTOR))
41 if (lhashCreate(HASH_SIZE, LOADFACTOR))
44 if (notifyhashCreate(N_HASH_SIZE, N_LOADFACTOR))
47 //Initialize socket pool
48 if((transPResponseSocketPool = createSockPool(transPResponseSocketPool, 2*numHostsInSystem+1)) == NULL) {
49 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);
109 setsockopt(acceptfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(flag));
111 retval=pthread_create(&thread_dstm_accept, NULL, dstmAccept, (void *)acceptfd);
113 pthread_detach(thread_dstm_accept);
116 /* This function accepts a new connection request, decodes the control message in the connection
117 * and accordingly calls other functions to process new requests */
118 void *dstmAccept(void *acceptfd) {
119 int val, retval, size, sum, sockid;
126 trans_commit_data_t transinfo;
127 unsigned short objType, *versionarry, version;
128 unsigned int *oidarry, numoid, mid, threadid;
130 /* Receive control messages from other machines */
132 int ret=recv_data_errorcode((int)acceptfd, &control, sizeof(char));
136 printf("DEBUG -> RECV Error!.. retrying\n");
141 /* Read oid requested and search if available */
142 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
143 if((srcObj = mhashSearch(oid)) == NULL) {
144 printf("Error: Object 0x%x is not found in Main Object Store %s, %d\n", oid, __FILE__, __LINE__);
147 h = (objheader_t *) srcObj;
149 size += sizeof(objheader_t);
150 sockid = (int) acceptfd;
153 ctrl = OBJECT_NOT_FOUND;
154 send_data(sockid, &ctrl, sizeof(char));
157 char msg[]={OBJECT_FOUND, 0, 0, 0, 0};
158 *((int *)&msg[1])=size;
159 send_data(sockid, &msg, sizeof(msg));
160 send_data(sockid, h, size);
164 case READ_MULT_REQUEST:
170 case MOVE_MULT_REQUEST:
174 /* Read transaction request */
175 transinfo.objlocked = NULL;
176 transinfo.objnotfound = NULL;
177 transinfo.modptr = NULL;
178 transinfo.numlocked = 0;
179 transinfo.numnotfound = 0;
180 if((val = readClientReq(&transinfo, (int)acceptfd)) != 0) {
181 printf("Error: In readClientReq() %s, %d\n", __FILE__, __LINE__);
186 if((val = prefetchReq((int)acceptfd)) != 0) {
187 printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__);
191 case TRANS_PREFETCH_RESPONSE:
192 if((val = getPrefetchResponse((int) acceptfd)) != 0) {
193 printf("Error: In getPrefetchResponse() %s, %d\n", __FILE__, __LINE__);
197 case START_REMOTE_THREAD:
198 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
199 objType = getObjType(oid);
200 startDSMthread(oid, objType);
203 case THREAD_NOTIFY_REQUEST:
204 recv_data((int)acceptfd, &numoid, sizeof(unsigned int));
205 size = (sizeof(unsigned int) + sizeof(unsigned short)) * numoid + 2 * sizeof(unsigned int);
206 if((buffer = calloc(1,size)) == NULL) {
207 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
211 recv_data((int)acceptfd, buffer, size);
213 oidarry = calloc(numoid, sizeof(unsigned int));
214 memcpy(oidarry, buffer, sizeof(unsigned int) * numoid);
215 size = sizeof(unsigned int) * numoid;
216 versionarry = calloc(numoid, sizeof(unsigned short));
217 memcpy(versionarry, buffer+size, sizeof(unsigned short) * numoid);
218 size += sizeof(unsigned short) * numoid;
219 mid = *((unsigned int *)(buffer+size));
220 size += sizeof(unsigned int);
221 threadid = *((unsigned int *)(buffer+size));
222 processReqNotify(numoid, oidarry, versionarry, mid, threadid);
227 case THREAD_NOTIFY_RESPONSE:
228 size = sizeof(unsigned short) + 2 * sizeof(unsigned int);
229 if((buffer = calloc(1,size)) == NULL) {
230 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
234 recv_data((int)acceptfd, buffer, size);
236 oid = *((unsigned int *)buffer);
237 size = sizeof(unsigned int);
238 version = *((unsigned short *)(buffer+size));
239 size += sizeof(unsigned short);
240 threadid = *((unsigned int *)(buffer+size));
241 threadNotify(oid,version,threadid);
245 case CLOSE_CONNECTION:
246 goto closeconnection;
249 printf("Error: dstmAccept() Unknown opcode %d at %s, %d\n", control, __FILE__, __LINE__);
254 /* Close connection */
255 if (close((int)acceptfd) == -1)
260 /* This function reads the information available in a transaction request
261 * and makes a function call to process the request */
262 int readClientReq(trans_commit_data_t *transinfo, int acceptfd) {
265 unsigned int *oidmod, oid;
267 objheader_t *headaddr;
268 int sum, i, size, n, val;
272 /* Read fixed_data_t data structure */
273 size = sizeof(fixed) - 1;
274 ptr = (char *)&fixed;;
275 fixed.control = TRANS_REQUEST;
276 recv_data((int)acceptfd, ptr+1, size);
278 /* Read list of mids */
279 int mcount = fixed.mcount;
280 size = mcount * sizeof(unsigned int);
281 unsigned int listmid[mcount];
282 ptr = (char *) listmid;
283 recv_data((int)acceptfd, ptr, size);
285 /* Read oid and version tuples for those objects that are not modified in the transaction */
286 int numread = fixed.numread;
287 size = numread * (sizeof(unsigned int) + sizeof(unsigned short));
289 if(numread != 0) { //If pile contains more than one object to be read,
290 // keep reading all objects
291 recv_data((int)acceptfd, objread, size);
294 /* Read modified objects */
295 if(fixed.nummod != 0) {
296 if ((modptr = calloc(1, fixed.sum_bytes)) == NULL) {
297 printf("calloc error for modified objects %s, %d\n", __FILE__, __LINE__);
300 size = fixed.sum_bytes;
301 recv_data((int)acceptfd, modptr, size);
304 /* Create an array of oids for modified objects */
305 oidmod = (unsigned int *) calloc(fixed.nummod, sizeof(unsigned int));
308 printf("calloc error %s, %d\n", __FILE__, __LINE__);
311 ptr = (char *) modptr;
312 for(i = 0 ; i < fixed.nummod; i++) {
314 headaddr = (objheader_t *) ptr;
317 GETSIZE(tmpsize, headaddr);
318 ptr += sizeof(objheader_t) + tmpsize;
321 /*Process the information read */
322 if((val = processClientReq(&fixed, transinfo, listmid, objread, modptr, oidmod, acceptfd)) != 0) {
323 printf("Error: In processClientReq() %s, %d\n", __FILE__, __LINE__);
339 /* This function processes the Coordinator's transaction request using "handleTransReq"
340 * function and sends a reply to the co-ordinator.
341 * Following this it also receives a new control message from the co-ordinator and processes this message*/
342 int processClientReq(fixed_data_t *fixed, trans_commit_data_t *transinfo,
343 unsigned int *listmid, char *objread, void *modptr, unsigned int *oidmod, int acceptfd) {
344 char control, sendctrl, retval;
345 objheader_t *tmp_header;
349 /* Send reply to the Coordinator */
350 if((retval = handleTransReq(fixed, transinfo, listmid, objread, modptr,acceptfd)) == 0 ) {
351 printf("Error: In handleTransReq() %s, %d\n", __FILE__, __LINE__);
355 recv_data((int)acceptfd, &control, sizeof(char));
357 /* Process the new control message */
360 if (fixed->nummod > 0)
362 /* Unlock objects that was locked due to this transaction */
363 for(i = 0; i< transinfo->numlocked; i++) {
364 if((header = mhashSearch(transinfo->objlocked[i])) == NULL) {
365 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);// find the header address
368 STATUS(((objheader_t *)header)) &= ~(LOCK);
371 /* Send ack to Coordinator */
372 sendctrl = TRANS_UNSUCESSFUL;
373 send_data((int)acceptfd, &sendctrl, sizeof(char));
377 /* Invoke the transCommit process() */
378 if((val = transCommitProcess(modptr, oidmod, transinfo->objlocked, fixed->nummod, transinfo->numlocked, (int)acceptfd)) != 0) {
379 printf("Error: In transCommitProcess() %s, %d\n", __FILE__, __LINE__);
381 if (transinfo->objlocked != NULL) {
382 free(transinfo->objlocked);
384 if (transinfo->objnotfound != NULL) {
385 free(transinfo->objnotfound);
391 case TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING:
394 printf("Error: No response to TRANS_AGREE OR DISAGREE protocol %s, %d\n", __FILE__, __LINE__);
395 //TODO Use fixed.trans_id TID since Client may have died
400 if (transinfo->objlocked != NULL) {
401 free(transinfo->objlocked);
403 if (transinfo->objnotfound != NULL) {
404 free(transinfo->objnotfound);
410 /* This function increments counters while running a voting decision on all objects involved
411 * in TRANS_REQUEST and If a TRANS_DISAGREE sends the response immediately back to the coordinator */
412 char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigned int *listmid, char *objread, void *modptr, int acceptfd) {
414 unsigned short version;
415 char control = 0, *ptr;
417 unsigned int *oidnotfound, *oidlocked;
419 objheader_t *headptr;
421 /* Counters and arrays to formulate decision on control message to be sent */
422 oidnotfound = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
423 oidlocked = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
424 int objnotfound = 0, objlocked = 0;
425 int v_nomatch = 0, v_matchlock = 0, v_matchnolock = 0;
427 /* modptr points to the beginning of the object store
428 * created at the Pariticipant.
429 * Object store holds the modified objects involved in the transaction request */
430 ptr = (char *) modptr;
432 /* Process each oid in the machine pile/ group per thread */
433 for (i = 0; i < fixed->numread + fixed->nummod; i++) {
434 if (i < fixed->numread) {//Objs only read and not modified
435 int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array
437 oid = *((unsigned int *)(objread + incr));
438 incr += sizeof(unsigned int);
439 version = *((unsigned short *)(objread + incr));
440 } else {//Objs modified
442 headptr = (objheader_t *) ptr;
444 version = headptr->version;
445 GETSIZE(tmpsize, headptr);
446 ptr += sizeof(objheader_t) + tmpsize;
449 /* Check if object is still present in the machine since the beginning of TRANS_REQUEST */
451 if ((mobj = mhashSearch(oid)) == NULL) {/* Obj not found */
452 /* Save the oids not found and number of oids not found for later use */
453 oidnotfound[objnotfound] = oid;
455 } else { /* If Obj found in machine (i.e. has not moved) */
456 /* Check if Obj is locked by any previous transaction */
457 pthread_mutex_lock(&lockObjHeader);
458 if ((STATUS(((objheader_t *)mobj)) & LOCK) == LOCK) {
459 pthread_mutex_unlock(&lockObjHeader);
460 if (version == ((objheader_t *)mobj)->version) { /* If locked then match versions */
462 } else {/* If versions don't match ...HARD ABORT */
464 /* Send TRANS_DISAGREE to Coordinator */
465 control = TRANS_DISAGREE;
467 for(j = 0; j < objlocked; j++) {
468 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
469 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
472 STATUS(headptr) &= ~(LOCK);
476 send_data(acceptfd, &control, sizeof(char));
479 } else {/* If Obj is not locked then lock object */
480 STATUS(((objheader_t *)mobj)) |= LOCK;
481 pthread_mutex_unlock(&lockObjHeader);
482 /* Save all object oids that are locked on this machine during this transaction request call */
483 oidlocked[objlocked] = OID(((objheader_t *)mobj));
485 if (version == ((objheader_t *)mobj)->version) { /* Check if versions match */
487 } else { /* If versions don't match ...HARD ABORT */
489 control = TRANS_DISAGREE;
491 for(j = 0; j < objlocked; j++) {
492 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
493 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
496 STATUS(headptr) &= ~(LOCK);
501 /* Send TRANS_DISAGREE to Coordinator */
502 send_data(acceptfd, &control, sizeof(char));
509 /* Decide what control message to send to Coordinator */
510 if ((control = decideCtrlMessage(fixed, transinfo, &v_matchnolock, &v_matchlock, &v_nomatch, &objnotfound, &objlocked,
511 modptr, oidnotfound, oidlocked, acceptfd)) == 0) {
512 printf("Error: In decideCtrlMessage() %s, %d\n", __FILE__, __LINE__);
519 /* This function decides what control message such as TRANS_AGREE, TRANS_DISAGREE or TRANS_SOFT_ABORT
520 * to send to Coordinator based on the votes of oids involved in the transaction */
521 char decideCtrlMessage(fixed_data_t *fixed, trans_commit_data_t *transinfo, int *v_matchnolock, int *v_matchlock,
522 int *v_nomatch, int *objnotfound, int *objlocked, void *modptr,
523 unsigned int *oidnotfound, unsigned int *oidlocked, int acceptfd) {
527 /* Condition to send TRANS_AGREE */
528 if(*(v_matchnolock) == fixed->numread + fixed->nummod) {
529 control = TRANS_AGREE;
530 /* Send control message */
531 send_data(acceptfd, &control, sizeof(char));
533 /* Condition to send TRANS_SOFT_ABORT */
534 if((*(v_matchlock) > 0 && *(v_nomatch) == 0) || (*(objnotfound) > 0 && *(v_nomatch) == 0)) {
535 control = TRANS_SOFT_ABORT;
537 /* Send control message */
538 send_data(acceptfd, &control, sizeof(char));
540 /* Send number of oids not found and the missing oids if objects are missing in the machine */
541 if(*(objnotfound) != 0) {
543 msg[0] = *(objnotfound);
544 send_data(acceptfd, &msg, sizeof(int));
545 int size = sizeof(unsigned int)* *(objnotfound);
546 send_data(acceptfd, oidnotfound, size);
550 /* Fill out the trans_commit_data_t data structure. This is required for a trans commit process
551 * if Participant receives a TRANS_COMMIT */
552 transinfo->objlocked = oidlocked;
553 transinfo->objnotfound = oidnotfound;
554 transinfo->modptr = modptr;
555 transinfo->numlocked = *(objlocked);
556 transinfo->numnotfound = *(objnotfound);
561 /* This function processes all modified objects involved in a TRANS_COMMIT and updates pointer
562 * addresses in lookup table and also changes version number
563 * Sends an ACK back to Coordinator */
564 int transCommitProcess(void *modptr, unsigned int *oidmod, unsigned int *oidlocked, int nummod, int numlocked, int acceptfd) {
566 objheader_t *newheader;
567 int i = 0, offset = 0;
571 /* Process each modified object saved in the mainobject store */
572 for(i = 0; i < nummod; i++) {
573 if((header = (objheader_t *) mhashSearch(oidmod[i])) == NULL) {
574 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
577 GETSIZE(tmpsize,header);
578 memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
579 header->version += 1;
580 /* If threads are waiting on this object to be updated, notify them */
581 pthread_mutex_lock(¬ifymutex);
582 if(header->notifylist != NULL) {
583 notifyAll(&header->notifylist, OID(header), header->version);
585 pthread_mutex_unlock(¬ifymutex);
586 offset += sizeof(objheader_t) + tmpsize;
592 /* Unlock locked objects */
593 for(i = 0; i < numlocked; i++) {
594 if((header = (objheader_t *) mhashSearch(oidlocked[i])) == NULL) {
595 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
598 STATUS(header) &= ~(LOCK);
600 //TODO Update location lookup table
602 /* Send ack to coordinator */
603 control = TRANS_SUCESSFUL;
604 send_data((int)acceptfd, &control, sizeof(char));
608 /* This function recevies the oid and offset tuples from the Coordinator's prefetch call.
609 * Looks for the objects to be prefetched in the main object store.
610 * If objects are not found then record those and if objects are found
611 * then use offset values to prefetch references to other objects */
613 int prefetchReq(int acceptfd) {
614 int i, size, objsize, numoffset = 0;
616 char *recvbuffer, control;
617 unsigned int oid, mid=-1;
623 recv_data((int)acceptfd, &numoffset, sizeof(int));
626 recv_data((int)acceptfd, &oidmid, 2*sizeof(unsigned int));
628 if (mid != oidmid.mid) {
630 freeSockWithLock(transPResponseSocketPool, mid, sd);
633 sd = getSockWithLock(transPResponseSocketPool, mid);
635 short offsetarry[numoffset];
636 recv_data((int) acceptfd, offsetarry, numoffset*sizeof(short));
638 /*Process each oid */
639 if ((header = mhashSearch(oid)) == NULL) {/* Obj not found */
640 /* Save the oids not found in buffer for later use */
641 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
642 char sendbuffer[size];
643 *((int *) sendbuffer) = size;
644 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
645 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
646 control = TRANS_PREFETCH_RESPONSE;
647 sendPrefetchResponse(sd, &control, sendbuffer, &size);
648 } else { /* Object Found */
650 GETSIZE(objsize, header);
651 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
652 char sendbuffer[size];
653 *((int *) (sendbuffer + incr)) = size;
655 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
656 incr += sizeof(char);
657 *((unsigned int *)(sendbuffer+incr)) = oid;
658 incr += sizeof(unsigned int);
659 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
661 control = TRANS_PREFETCH_RESPONSE;
662 sendPrefetchResponse(sd, &control, sendbuffer, &size);
664 /* Calculate the oid corresponding to the offset value */
665 for(i = 0 ; i< numoffset ; i++) {
666 /* Check for arrays */
667 if(TYPE(header) > NUMCLASSES) {
668 int elementsize = classsize[TYPE(header)];
669 struct ArrayObject *ao = (struct ArrayObject *) (((char *)header) + sizeof(objheader_t));
670 unsigned short length = ao->___length___;
671 /* Check if array out of bounds */
672 if(offsetarry[i]< 0 || offsetarry[i] >= length) {
675 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + sizeof(struct ArrayObject) + (elementsize*offsetarry[i])));
677 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + offsetarry[i]));
680 /* Don't continue if we hit a NULL pointer */
684 if((header = mhashSearch(oid)) == NULL) {
685 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
686 char sendbuffer[size];
687 *((int *) sendbuffer) = size;
688 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
689 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
691 control = TRANS_PREFETCH_RESPONSE;
692 sendPrefetchResponse(sd, &control, sendbuffer, &size);
694 } else {/* Obj Found */
696 GETSIZE(objsize, header);
697 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
698 char sendbuffer[size];
699 *((int *) (sendbuffer + incr)) = size;
701 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
702 incr += sizeof(char);
703 *((unsigned int *)(sendbuffer+incr)) = oid;
704 incr += sizeof(unsigned int);
705 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
707 control = TRANS_PREFETCH_RESPONSE;
708 sendPrefetchResponse(sd, &control, sendbuffer, &size);
715 freeSockWithLock(transPResponseSocketPool, mid, sd);
720 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size) {
721 send_data(sd, control, sizeof(char));
722 /* Send the buffer with its size */
723 int length = *(size);
724 send_data(sd, sendbuffer, length);
727 void processReqNotify(unsigned int numoid, unsigned int *oidarry, unsigned short *versionarry, unsigned int mid, unsigned int threadid) {
730 unsigned short newversion;
731 char msg[1+ 2 * sizeof(unsigned int) + sizeof(unsigned short)];
733 struct sockaddr_in remoteAddr;
739 oid = *(oidarry + i);
740 if((header = (objheader_t *) mhashSearch(oid)) == NULL) {
741 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
744 /* Check to see if versions are same */
746 if ((STATUS(header) & LOCK) != LOCK) {
747 pthread_mutex_lock(¬ifymutex);
748 STATUS(header) |= LOCK;
749 newversion = header->version;
750 if(newversion == *(versionarry + i)) {
751 //Add to the notify list
752 if((header->notifylist = insNode(header->notifylist, threadid, mid)) == NULL) {
753 printf("Error: Obj notify list points to NULL %s, %d\n", __FILE__, __LINE__);
754 pthread_mutex_unlock(¬ifymutex);
757 STATUS(header) &= ~(LOCK);
758 pthread_mutex_unlock(¬ifymutex);
760 STATUS(header) &= ~(LOCK);
761 pthread_mutex_unlock(¬ifymutex);
762 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
763 perror("processReqNotify():socket()");
766 bzero(&remoteAddr, sizeof(remoteAddr));
767 remoteAddr.sin_family = AF_INET;
768 remoteAddr.sin_port = htons(LISTEN_PORT);
769 remoteAddr.sin_addr.s_addr = htonl(mid);
771 if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
772 printf("Error: processReqNotify():error %d connecting to %s:%d\n", errno,
773 inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
777 //Send Update notification
778 msg[0] = THREAD_NOTIFY_RESPONSE;
779 *((unsigned int *)&msg[1]) = oid;
780 size = sizeof(unsigned int);
781 *((unsigned short *)(&msg[1]+size)) = newversion;
782 size += sizeof(unsigned short);
783 *((unsigned int *)(&msg[1]+size)) = threadid;
784 size = 1+ 2*sizeof(unsigned int) + sizeof(unsigned short);
785 send_data(sd, msg, size);