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 */
7 #include "threadnotify.h"
12 #define BACKLOG 10 //max pending connections
13 #define RECEIVE_BUFFER_SIZE 2048
15 extern int classsize[];
16 extern int numHostsInSystem;
17 extern pthread_mutex_t notifymutex;
19 objstr_t *mainobjstore;
20 pthread_mutex_t mainobjstore_mutex;
21 pthread_mutex_t lockObjHeader;
22 pthread_mutexattr_t mainobjstore_mutex_attr; /* Attribute for lock to make it a recursive lock */
24 sockPoolHashTable_t *transPResponseSocketPool;
26 /* This function initializes the main objects store and creates the
27 * global machine and location lookup table */
31 mainobjstore = objstrCreate(DEFAULT_OBJ_STORE_SIZE);
32 /* Initialize attribute for mutex */
33 pthread_mutexattr_init(&mainobjstore_mutex_attr);
34 pthread_mutexattr_settype(&mainobjstore_mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);
35 pthread_mutex_init(&mainobjstore_mutex, &mainobjstore_mutex_attr);
36 pthread_mutex_init(&lockObjHeader,NULL);
37 if (mhashCreate(HASH_SIZE, LOADFACTOR))
40 if (lhashCreate(HASH_SIZE, LOADFACTOR))
43 if (notifyhashCreate(N_HASH_SIZE, N_LOADFACTOR))
46 //Initialize socket pool
47 if((transPResponseSocketPool = createSockPool(transPResponseSocketPool, 2*numHostsInSystem+1)) == NULL) {
48 printf("Error in creating new socket pool at %s line %d\n", __FILE__, __LINE__);
55 /* This function starts the thread to listen on a socket
56 * for tranaction calls */
59 int listenfd, acceptfd;
60 struct sockaddr_in my_addr;
61 struct sockaddr_in client_addr;
62 socklen_t addrlength = sizeof(struct sockaddr);
63 pthread_t thread_dstm_accept;
67 listenfd = socket(AF_INET, SOCK_STREAM, 0);
74 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &setsockflag, sizeof (setsockflag)) < 0) {
79 if (setsockopt(listenfd, SOL_SOCKET, SO_NOSIGPIPE, &setsockflag, sizeof (setsockflag)) < 0) {
85 my_addr.sin_family = AF_INET;
86 my_addr.sin_port = htons(LISTEN_PORT);
87 my_addr.sin_addr.s_addr = INADDR_ANY;
88 memset(&(my_addr.sin_zero), '\0', 8);
90 if (bind(listenfd, (struct sockaddr *)&my_addr, addrlength) == -1)
96 if (listen(listenfd, BACKLOG) == -1)
102 printf("Listening on port %d, fd = %d\n", LISTEN_PORT, listenfd);
106 acceptfd = accept(listenfd, (struct sockaddr *)&client_addr, &addrlength);
108 retval=pthread_create(&thread_dstm_accept, NULL, dstmAccept, (void *)acceptfd);
110 pthread_detach(thread_dstm_accept);
113 /* This function accepts a new connection request, decodes the control message in the connection
114 * and accordingly calls other functions to process new requests */
115 void *dstmAccept(void *acceptfd) {
116 int val, retval, size, sum, sockid;
123 trans_commit_data_t transinfo;
124 unsigned short objType, *versionarry, version;
125 unsigned int *oidarry, numoid, mid, threadid;
127 /* Receive control messages from other machines */
129 int ret=recv_data_errorcode((int)acceptfd, &control, sizeof(char));
131 printf("DEBUG -> RECV Error!.. retrying\n");
136 /* Read oid requested and search if available */
137 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
138 if((srcObj = mhashSearch(oid)) == NULL) {
139 printf("Error: Object 0x%x is not found in Main Object Store %s, %d\n", oid, __FILE__, __LINE__);
142 h = (objheader_t *) srcObj;
144 size += sizeof(objheader_t);
145 sockid = (int) acceptfd;
148 ctrl = OBJECT_NOT_FOUND;
149 send_data(sockid, &ctrl, sizeof(char));
152 char msg[]={OBJECT_FOUND, 0, 0, 0, 0};
153 *((int *)&msg[1])=size;
154 send_data(sockid, &msg, sizeof(msg));
155 send_data(sockid, h, size);
159 case READ_MULT_REQUEST:
165 case MOVE_MULT_REQUEST:
169 /* Read transaction request */
170 transinfo.objlocked = NULL;
171 transinfo.objnotfound = NULL;
172 transinfo.modptr = NULL;
173 transinfo.numlocked = 0;
174 transinfo.numnotfound = 0;
175 if((val = readClientReq(&transinfo, (int)acceptfd)) != 0) {
176 printf("Error: In readClientReq() %s, %d\n", __FILE__, __LINE__);
181 if((val = prefetchReq((int)acceptfd)) != 0) {
182 printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__);
186 case TRANS_PREFETCH_RESPONSE:
187 if((val = getPrefetchResponse((int) acceptfd)) != 0) {
188 printf("Error: In getPrefetchResponse() %s, %d\n", __FILE__, __LINE__);
192 case START_REMOTE_THREAD:
193 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
194 objType = getObjType(oid);
195 startDSMthread(oid, objType);
198 case THREAD_NOTIFY_REQUEST:
199 recv_data((int)acceptfd, &numoid, sizeof(unsigned int));
200 size = (sizeof(unsigned int) + sizeof(unsigned short)) * numoid + 2 * sizeof(unsigned int);
201 if((buffer = calloc(1,size)) == NULL) {
202 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
206 recv_data((int)acceptfd, buffer, size);
208 oidarry = calloc(numoid, sizeof(unsigned int));
209 memcpy(oidarry, buffer, sizeof(unsigned int) * numoid);
210 size = sizeof(unsigned int) * numoid;
211 versionarry = calloc(numoid, sizeof(unsigned short));
212 memcpy(versionarry, buffer+size, sizeof(unsigned short) * numoid);
213 size += sizeof(unsigned short) * numoid;
214 mid = *((unsigned int *)(buffer+size));
215 size += sizeof(unsigned int);
216 threadid = *((unsigned int *)(buffer+size));
217 processReqNotify(numoid, oidarry, versionarry, mid, threadid);
222 case THREAD_NOTIFY_RESPONSE:
223 size = sizeof(unsigned short) + 2 * sizeof(unsigned int);
224 if((buffer = calloc(1,size)) == NULL) {
225 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
229 recv_data((int)acceptfd, buffer, size);
231 oid = *((unsigned int *)buffer);
232 size = sizeof(unsigned int);
233 version = *((unsigned short *)(buffer+size));
234 size += sizeof(unsigned short);
235 threadid = *((unsigned int *)(buffer+size));
236 threadNotify(oid,version,threadid);
240 case CLOSE_CONNECTION:
241 goto closeconnection;
244 printf("Error: dstmAccept() Unknown opcode %d at %s, %d\n", control, __FILE__, __LINE__);
249 /* Close connection */
250 if (close((int)acceptfd) == -1)
255 /* This function reads the information available in a transaction request
256 * and makes a function call to process the request */
257 int readClientReq(trans_commit_data_t *transinfo, int acceptfd) {
260 unsigned int *oidmod, oid;
262 objheader_t *headaddr;
263 int sum, i, size, n, val;
267 /* Read fixed_data_t data structure */
268 size = sizeof(fixed) - 1;
269 ptr = (char *)&fixed;;
270 fixed.control = TRANS_REQUEST;
271 recv_data((int)acceptfd, ptr+1, size);
273 /* Read list of mids */
274 int mcount = fixed.mcount;
275 size = mcount * sizeof(unsigned int);
276 unsigned int listmid[mcount];
277 ptr = (char *) listmid;
278 recv_data((int)acceptfd, ptr, size);
280 /* Read oid and version tuples for those objects that are not modified in the transaction */
281 int numread = fixed.numread;
282 size = numread * (sizeof(unsigned int) + sizeof(unsigned short));
284 if(numread != 0) { //If pile contains more than one object to be read,
285 // keep reading all objects
286 recv_data((int)acceptfd, objread, size);
289 /* Read modified objects */
290 if(fixed.nummod != 0) {
291 if ((modptr = calloc(1, fixed.sum_bytes)) == NULL) {
292 printf("calloc error for modified objects %s, %d\n", __FILE__, __LINE__);
295 size = fixed.sum_bytes;
296 recv_data((int)acceptfd, modptr, size);
299 /* Create an array of oids for modified objects */
300 oidmod = (unsigned int *) calloc(fixed.nummod, sizeof(unsigned int));
303 printf("calloc error %s, %d\n", __FILE__, __LINE__);
306 ptr = (char *) modptr;
307 for(i = 0 ; i < fixed.nummod; i++) {
309 headaddr = (objheader_t *) ptr;
312 GETSIZE(tmpsize, headaddr);
313 ptr += sizeof(objheader_t) + tmpsize;
316 /*Process the information read */
317 if((val = processClientReq(&fixed, transinfo, listmid, objread, modptr, oidmod, acceptfd)) != 0) {
318 printf("Error: In processClientReq() %s, %d\n", __FILE__, __LINE__);
334 /* This function processes the Coordinator's transaction request using "handleTransReq"
335 * function and sends a reply to the co-ordinator.
336 * Following this it also receives a new control message from the co-ordinator and processes this message*/
337 int processClientReq(fixed_data_t *fixed, trans_commit_data_t *transinfo,
338 unsigned int *listmid, char *objread, void *modptr, unsigned int *oidmod, int acceptfd) {
339 char control, sendctrl, retval;
340 objheader_t *tmp_header;
344 /* Send reply to the Coordinator */
345 if((retval = handleTransReq(fixed, transinfo, listmid, objread, modptr,acceptfd)) == 0 ) {
346 printf("Error: In handleTransReq() %s, %d\n", __FILE__, __LINE__);
350 recv_data((int)acceptfd, &control, sizeof(char));
352 /* Process the new control message */
355 if (fixed->nummod > 0)
357 /* Unlock objects that was locked due to this transaction */
358 for(i = 0; i< transinfo->numlocked; i++) {
359 if((header = mhashSearch(transinfo->objlocked[i])) == NULL) {
360 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);// find the header address
363 STATUS(((objheader_t *)header)) &= ~(LOCK);
366 /* Send ack to Coordinator */
367 sendctrl = TRANS_UNSUCESSFUL;
368 send_data((int)acceptfd, &sendctrl, sizeof(char));
372 /* Invoke the transCommit process() */
373 if((val = transCommitProcess(modptr, oidmod, transinfo->objlocked, fixed->nummod, transinfo->numlocked, (int)acceptfd)) != 0) {
374 printf("Error: In transCommitProcess() %s, %d\n", __FILE__, __LINE__);
376 if (transinfo->objlocked != NULL) {
377 free(transinfo->objlocked);
379 if (transinfo->objnotfound != NULL) {
380 free(transinfo->objnotfound);
386 case TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING:
389 printf("Error: No response to TRANS_AGREE OR DISAGREE protocol %s, %d\n", __FILE__, __LINE__);
390 //TODO Use fixed.trans_id TID since Client may have died
395 if (transinfo->objlocked != NULL) {
396 free(transinfo->objlocked);
398 if (transinfo->objnotfound != NULL) {
399 free(transinfo->objnotfound);
405 /* This function increments counters while running a voting decision on all objects involved
406 * in TRANS_REQUEST and If a TRANS_DISAGREE sends the response immediately back to the coordinator */
407 char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigned int *listmid, char *objread, void *modptr, int acceptfd) {
409 unsigned short version;
410 char control = 0, *ptr;
412 unsigned int *oidnotfound, *oidlocked;
414 objheader_t *headptr;
416 /* Counters and arrays to formulate decision on control message to be sent */
417 oidnotfound = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
418 oidlocked = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
419 int objnotfound = 0, objlocked = 0;
420 int v_nomatch = 0, v_matchlock = 0, v_matchnolock = 0;
422 /* modptr points to the beginning of the object store
423 * created at the Pariticipant.
424 * Object store holds the modified objects involved in the transaction request */
425 ptr = (char *) modptr;
427 /* Process each oid in the machine pile/ group per thread */
428 for (i = 0; i < fixed->numread + fixed->nummod; i++) {
429 if (i < fixed->numread) {//Objs only read and not modified
430 int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array
432 oid = *((unsigned int *)(objread + incr));
433 incr += sizeof(unsigned int);
434 version = *((unsigned short *)(objread + incr));
435 } else {//Objs modified
437 headptr = (objheader_t *) ptr;
439 version = headptr->version;
440 GETSIZE(tmpsize, headptr);
441 ptr += sizeof(objheader_t) + tmpsize;
444 /* Check if object is still present in the machine since the beginning of TRANS_REQUEST */
446 if ((mobj = mhashSearch(oid)) == NULL) {/* Obj not found */
447 /* Save the oids not found and number of oids not found for later use */
448 oidnotfound[objnotfound] = oid;
450 } else { /* If Obj found in machine (i.e. has not moved) */
451 /* Check if Obj is locked by any previous transaction */
452 pthread_mutex_lock(&lockObjHeader);
453 if ((STATUS(((objheader_t *)mobj)) & LOCK) == LOCK) {
454 pthread_mutex_unlock(&lockObjHeader);
455 if (version == ((objheader_t *)mobj)->version) { /* If locked then match versions */
457 } else {/* If versions don't match ...HARD ABORT */
459 /* Send TRANS_DISAGREE to Coordinator */
460 control = TRANS_DISAGREE;
462 for(j = 0; j < objlocked; j++) {
463 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
464 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
467 STATUS(headptr) &= ~(LOCK);
471 send_data(acceptfd, &control, sizeof(char));
474 } else {/* If Obj is not locked then lock object */
475 STATUS(((objheader_t *)mobj)) |= LOCK;
476 pthread_mutex_unlock(&lockObjHeader);
477 /* Save all object oids that are locked on this machine during this transaction request call */
478 oidlocked[objlocked] = OID(((objheader_t *)mobj));
480 if (version == ((objheader_t *)mobj)->version) { /* Check if versions match */
482 } else { /* If versions don't match ...HARD ABORT */
484 control = TRANS_DISAGREE;
486 for(j = 0; j < objlocked; j++) {
487 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
488 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
491 STATUS(headptr) &= ~(LOCK);
496 /* Send TRANS_DISAGREE to Coordinator */
497 send_data(acceptfd, &control, sizeof(char));
504 /* Decide what control message to send to Coordinator */
505 if ((control = decideCtrlMessage(fixed, transinfo, &v_matchnolock, &v_matchlock, &v_nomatch, &objnotfound, &objlocked,
506 modptr, oidnotfound, oidlocked, acceptfd)) == 0) {
507 printf("Error: In decideCtrlMessage() %s, %d\n", __FILE__, __LINE__);
514 /* This function decides what control message such as TRANS_AGREE, TRANS_DISAGREE or TRANS_SOFT_ABORT
515 * to send to Coordinator based on the votes of oids involved in the transaction */
516 char decideCtrlMessage(fixed_data_t *fixed, trans_commit_data_t *transinfo, int *v_matchnolock, int *v_matchlock,
517 int *v_nomatch, int *objnotfound, int *objlocked, void *modptr,
518 unsigned int *oidnotfound, unsigned int *oidlocked, int acceptfd) {
522 /* Condition to send TRANS_AGREE */
523 if(*(v_matchnolock) == fixed->numread + fixed->nummod) {
524 control = TRANS_AGREE;
525 /* Send control message */
526 send_data(acceptfd, &control, sizeof(char));
528 /* Condition to send TRANS_SOFT_ABORT */
529 if((*(v_matchlock) > 0 && *(v_nomatch) == 0) || (*(objnotfound) > 0 && *(v_nomatch) == 0)) {
530 control = TRANS_SOFT_ABORT;
532 /* Send control message */
533 send_data(acceptfd, &control, sizeof(char));
535 /* Send number of oids not found and the missing oids if objects are missing in the machine */
536 if(*(objnotfound) != 0) {
538 msg[0] = *(objnotfound);
539 send_data(acceptfd, &msg, sizeof(int));
540 int size = sizeof(unsigned int)* *(objnotfound);
541 send_data(acceptfd, oidnotfound, size);
545 /* Fill out the trans_commit_data_t data structure. This is required for a trans commit process
546 * if Participant receives a TRANS_COMMIT */
547 transinfo->objlocked = oidlocked;
548 transinfo->objnotfound = oidnotfound;
549 transinfo->modptr = modptr;
550 transinfo->numlocked = *(objlocked);
551 transinfo->numnotfound = *(objnotfound);
556 /* This function processes all modified objects involved in a TRANS_COMMIT and updates pointer
557 * addresses in lookup table and also changes version number
558 * Sends an ACK back to Coordinator */
559 int transCommitProcess(void *modptr, unsigned int *oidmod, unsigned int *oidlocked, int nummod, int numlocked, int acceptfd) {
561 objheader_t *newheader;
562 int i = 0, offset = 0;
566 /* Process each modified object saved in the mainobject store */
567 for(i = 0; i < nummod; i++) {
568 if((header = (objheader_t *) mhashSearch(oidmod[i])) == NULL) {
569 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
572 GETSIZE(tmpsize,header);
573 memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
574 header->version += 1;
575 /* If threads are waiting on this object to be updated, notify them */
576 pthread_mutex_lock(¬ifymutex);
577 if(header->notifylist != NULL) {
578 notifyAll(&header->notifylist, OID(header), header->version);
580 pthread_mutex_unlock(¬ifymutex);
581 offset += sizeof(objheader_t) + tmpsize;
587 /* Unlock locked objects */
588 for(i = 0; i < numlocked; i++) {
589 if((header = (objheader_t *) mhashSearch(oidlocked[i])) == NULL) {
590 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
593 STATUS(header) &= ~(LOCK);
595 //TODO Update location lookup table
597 /* Send ack to coordinator */
598 control = TRANS_SUCESSFUL;
599 send_data((int)acceptfd, &control, sizeof(char));
603 /* This function recevies the oid and offset tuples from the Coordinator's prefetch call.
604 * Looks for the objects to be prefetched in the main object store.
605 * If objects are not found then record those and if objects are found
606 * then use offset values to prefetch references to other objects */
608 int prefetchReq(int acceptfd) {
609 int i, size, objsize, numoffset = 0;
611 char *recvbuffer, control;
612 unsigned int oid, mid=-1;
618 recv_data((int)acceptfd, &numoffset, sizeof(int));
621 recv_data((int)acceptfd, &oidmid, 2*sizeof(unsigned int));
623 if (mid != oidmid.mid) {
625 freeSockWithLock(transPResponseSocketPool, mid, sd);
628 sd = getSockWithLock(transPResponseSocketPool, mid);
630 short offsetarry[numoffset];
631 recv_data((int) acceptfd, offsetarry, numoffset*sizeof(short));
633 /*Process each oid */
634 if ((header = mhashSearch(oid)) == NULL) {/* Obj not found */
635 /* Save the oids not found in buffer for later use */
636 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
637 char sendbuffer[size];
638 *((int *) sendbuffer) = size;
639 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
640 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
641 control = TRANS_PREFETCH_RESPONSE;
642 sendPrefetchResponse(sd, &control, sendbuffer, &size);
643 } else { /* Object Found */
645 GETSIZE(objsize, header);
646 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
647 char sendbuffer[size];
648 *((int *) (sendbuffer + incr)) = size;
650 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
651 incr += sizeof(char);
652 *((unsigned int *)(sendbuffer+incr)) = oid;
653 incr += sizeof(unsigned int);
654 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
656 control = TRANS_PREFETCH_RESPONSE;
657 sendPrefetchResponse(sd, &control, sendbuffer, &size);
659 /* Calculate the oid corresponding to the offset value */
660 for(i = 0 ; i< numoffset ; i++) {
661 /* Check for arrays */
662 if(TYPE(header) > NUMCLASSES) {
663 int elementsize = classsize[TYPE(header)];
664 struct ArrayObject *ao = (struct ArrayObject *) (((char *)header) + sizeof(objheader_t));
665 unsigned short length = ao->___length___;
666 /* Check if array out of bounds */
667 if(offsetarry[i]< 0 || offsetarry[i] >= length) {
670 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + sizeof(struct ArrayObject) + (elementsize*offsetarry[i])));
672 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + offsetarry[i]));
675 /* Don't continue if we hit a NULL pointer */
679 if((header = mhashSearch(oid)) == NULL) {
680 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
681 char sendbuffer[size];
682 *((int *) sendbuffer) = size;
683 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
684 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
686 control = TRANS_PREFETCH_RESPONSE;
687 sendPrefetchResponse(sd, &control, sendbuffer, &size);
689 } else {/* Obj Found */
691 GETSIZE(objsize, header);
692 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
693 char sendbuffer[size];
694 *((int *) (sendbuffer + incr)) = size;
696 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
697 incr += sizeof(char);
698 *((unsigned int *)(sendbuffer+incr)) = oid;
699 incr += sizeof(unsigned int);
700 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
702 control = TRANS_PREFETCH_RESPONSE;
703 sendPrefetchResponse(sd, &control, sendbuffer, &size);
710 freeSockWithLock(transPResponseSocketPool, mid, sd);
715 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size) {
716 send_data(sd, control, sizeof(char));
717 /* Send the buffer with its size */
718 int length = *(size);
719 send_data(sd, sendbuffer, length);
722 void processReqNotify(unsigned int numoid, unsigned int *oidarry, unsigned short *versionarry, unsigned int mid, unsigned int threadid) {
725 unsigned short newversion;
726 char msg[1+ 2 * sizeof(unsigned int) + sizeof(unsigned short)];
728 struct sockaddr_in remoteAddr;
734 oid = *(oidarry + i);
735 if((header = (objheader_t *) mhashSearch(oid)) == NULL) {
736 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
739 /* Check to see if versions are same */
741 if ((STATUS(header) & LOCK) != LOCK) {
742 pthread_mutex_lock(¬ifymutex);
743 STATUS(header) |= LOCK;
744 newversion = header->version;
745 if(newversion == *(versionarry + i)) {
746 //Add to the notify list
747 if((header->notifylist = insNode(header->notifylist, threadid, mid)) == NULL) {
748 printf("Error: Obj notify list points to NULL %s, %d\n", __FILE__, __LINE__);
749 pthread_mutex_unlock(¬ifymutex);
752 STATUS(header) &= ~(LOCK);
753 pthread_mutex_unlock(¬ifymutex);
755 STATUS(header) &= ~(LOCK);
756 pthread_mutex_unlock(¬ifymutex);
757 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
758 perror("processReqNotify():socket()");
761 bzero(&remoteAddr, sizeof(remoteAddr));
762 remoteAddr.sin_family = AF_INET;
763 remoteAddr.sin_port = htons(LISTEN_PORT);
764 remoteAddr.sin_addr.s_addr = htonl(mid);
766 if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
767 printf("Error: processReqNotify():error %d connecting to %s:%d\n", errno,
768 inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
772 //Send Update notification
773 msg[0] = THREAD_NOTIFY_RESPONSE;
774 *((unsigned int *)&msg[1]) = oid;
775 size = sizeof(unsigned int);
776 *((unsigned short *)(&msg[1]+size)) = newversion;
777 size += sizeof(unsigned short);
778 *((unsigned int *)(&msg[1]+size)) = threadid;
779 size = 1+ 2*sizeof(unsigned int) + sizeof(unsigned short);
780 send_data(sd, msg, size);