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_mutexattr_t mainobjstore_mutex_attr; /* Attribute for lock to make it a recursive lock */
23 sockPoolHashTable_t *transPResponseSocketPool;
25 /* This function initializes the main objects store and creates the
26 * global machine and location lookup table */
30 mainobjstore = objstrCreate(DEFAULT_OBJ_STORE_SIZE);
31 /* Initialize attribute for mutex */
32 pthread_mutexattr_init(&mainobjstore_mutex_attr);
33 pthread_mutexattr_settype(&mainobjstore_mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);
34 pthread_mutex_init(&mainobjstore_mutex, &mainobjstore_mutex_attr);
35 if (mhashCreate(HASH_SIZE, LOADFACTOR))
38 if (lhashCreate(HASH_SIZE, LOADFACTOR))
41 if (notifyhashCreate(N_HASH_SIZE, N_LOADFACTOR))
44 //Initialize socket pool
45 if((transPResponseSocketPool = createSockPool(transPResponseSocketPool, 2*numHostsInSystem+1)) == NULL) {
46 printf("Error in creating new socket pool at %s line %d\n", __FILE__, __LINE__);
53 /* This function starts the thread to listen on a socket
54 * for tranaction calls */
57 int listenfd, acceptfd;
58 struct sockaddr_in my_addr;
59 struct sockaddr_in client_addr;
60 socklen_t addrlength = sizeof(struct sockaddr);
61 pthread_t thread_dstm_accept;
65 listenfd = socket(AF_INET, SOCK_STREAM, 0);
72 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &setsockflag, sizeof (setsockflag)) < 0) {
77 if (setsockopt(listenfd, SOL_SOCKET, SO_NOSIGPIPE, &setsockflag, sizeof (setsockflag)) < 0) {
83 my_addr.sin_family = AF_INET;
84 my_addr.sin_port = htons(LISTEN_PORT);
85 my_addr.sin_addr.s_addr = INADDR_ANY;
86 memset(&(my_addr.sin_zero), '\0', 8);
88 if (bind(listenfd, (struct sockaddr *)&my_addr, addrlength) == -1)
94 if (listen(listenfd, BACKLOG) == -1)
100 printf("Listening on port %d, fd = %d\n", LISTEN_PORT, listenfd);
104 acceptfd = accept(listenfd, (struct sockaddr *)&client_addr, &addrlength);
106 retval=pthread_create(&thread_dstm_accept, NULL, dstmAccept, (void *)acceptfd);
108 pthread_detach(thread_dstm_accept);
111 /* This function accepts a new connection request, decodes the control message in the connection
112 * and accordingly calls other functions to process new requests */
113 void *dstmAccept(void *acceptfd) {
114 int val, retval, size, sum, sockid;
121 trans_commit_data_t transinfo;
122 unsigned short objType, *versionarry, version;
123 unsigned int *oidarry, numoid, mid, threadid;
125 /* Receive control messages from other machines */
127 int ret=recv_data_errorcode((int)acceptfd, &control, sizeof(char));
129 printf("DEBUG -> RECV Error!.. retrying\n");
134 /* Read oid requested and search if available */
135 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
136 if((srcObj = mhashSearch(oid)) == NULL) {
137 printf("Error: Object 0x%x is not found in Main Object Store %s, %d\n", oid, __FILE__, __LINE__);
140 h = (objheader_t *) srcObj;
142 size += sizeof(objheader_t);
143 sockid = (int) acceptfd;
146 ctrl = OBJECT_NOT_FOUND;
147 send_data(sockid, &ctrl, sizeof(char));
150 char msg[]={OBJECT_FOUND, 0, 0, 0, 0};
151 *((int *)&msg[1])=size;
152 send_data(sockid, &msg, sizeof(msg));
153 send_data(sockid, h, size);
157 case READ_MULT_REQUEST:
163 case MOVE_MULT_REQUEST:
167 /* Read transaction request */
168 transinfo.objlocked = NULL;
169 transinfo.objnotfound = NULL;
170 transinfo.modptr = NULL;
171 transinfo.numlocked = 0;
172 transinfo.numnotfound = 0;
173 if((val = readClientReq(&transinfo, (int)acceptfd)) != 0) {
174 printf("Error: In readClientReq() %s, %d\n", __FILE__, __LINE__);
179 if((val = prefetchReq((int)acceptfd)) != 0) {
180 printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__);
184 case TRANS_PREFETCH_RESPONSE:
185 if((val = getPrefetchResponse((int) acceptfd)) != 0) {
186 printf("Error: In getPrefetchResponse() %s, %d\n", __FILE__, __LINE__);
190 case START_REMOTE_THREAD:
191 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
192 objType = getObjType(oid);
193 startDSMthread(oid, objType);
196 case THREAD_NOTIFY_REQUEST:
197 recv_data((int)acceptfd, &numoid, sizeof(unsigned int));
198 size = (sizeof(unsigned int) + sizeof(unsigned short)) * numoid + 2 * sizeof(unsigned int);
199 if((buffer = calloc(1,size)) == NULL) {
200 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
204 recv_data((int)acceptfd, buffer, size);
206 oidarry = calloc(numoid, sizeof(unsigned int));
207 memcpy(oidarry, buffer, sizeof(unsigned int) * numoid);
208 size = sizeof(unsigned int) * numoid;
209 versionarry = calloc(numoid, sizeof(unsigned short));
210 memcpy(versionarry, buffer+size, sizeof(unsigned short) * numoid);
211 size += sizeof(unsigned short) * numoid;
212 mid = *((unsigned int *)(buffer+size));
213 size += sizeof(unsigned int);
214 threadid = *((unsigned int *)(buffer+size));
215 processReqNotify(numoid, oidarry, versionarry, mid, threadid);
220 case THREAD_NOTIFY_RESPONSE:
221 size = sizeof(unsigned short) + 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 oid = *((unsigned int *)buffer);
230 size = sizeof(unsigned int);
231 version = *((unsigned short *)(buffer+size));
232 size += sizeof(unsigned short);
233 threadid = *((unsigned int *)(buffer+size));
234 threadNotify(oid,version,threadid);
238 case CLOSE_CONNECTION:
239 goto closeconnection;
242 printf("Error: dstmAccept() Unknown opcode %d at %s, %d\n", control, __FILE__, __LINE__);
247 /* Close connection */
248 if (close((int)acceptfd) == -1)
253 /* This function reads the information available in a transaction request
254 * and makes a function call to process the request */
255 int readClientReq(trans_commit_data_t *transinfo, int acceptfd) {
258 unsigned int *oidmod, oid;
260 objheader_t *headaddr;
261 int sum, i, size, n, val;
265 /* Read fixed_data_t data structure */
266 size = sizeof(fixed) - 1;
267 ptr = (char *)&fixed;;
268 fixed.control = TRANS_REQUEST;
269 recv_data((int)acceptfd, ptr+1, size);
271 /* Read list of mids */
272 int mcount = fixed.mcount;
273 size = mcount * sizeof(unsigned int);
274 unsigned int listmid[mcount];
275 ptr = (char *) listmid;
276 recv_data((int)acceptfd, ptr, size);
278 /* Read oid and version tuples for those objects that are not modified in the transaction */
279 int numread = fixed.numread;
280 size = numread * (sizeof(unsigned int) + sizeof(unsigned short));
282 if(numread != 0) { //If pile contains more than one object to be read,
283 // keep reading all objects
284 recv_data((int)acceptfd, objread, size);
287 /* Read modified objects */
288 if(fixed.nummod != 0) {
289 if ((modptr = calloc(1, fixed.sum_bytes)) == NULL) {
290 printf("calloc error for modified objects %s, %d\n", __FILE__, __LINE__);
293 size = fixed.sum_bytes;
294 recv_data((int)acceptfd, modptr, size);
297 /* Create an array of oids for modified objects */
298 oidmod = (unsigned int *) calloc(fixed.nummod, sizeof(unsigned int));
301 printf("calloc error %s, %d\n", __FILE__, __LINE__);
304 ptr = (char *) modptr;
305 for(i = 0 ; i < fixed.nummod; i++) {
307 headaddr = (objheader_t *) ptr;
310 GETSIZE(tmpsize, headaddr);
311 ptr += sizeof(objheader_t) + tmpsize;
314 /*Process the information read */
315 if((val = processClientReq(&fixed, transinfo, listmid, objread, modptr, oidmod, acceptfd)) != 0) {
316 printf("Error: In processClientReq() %s, %d\n", __FILE__, __LINE__);
332 /* This function processes the Coordinator's transaction request using "handleTransReq"
333 * function and sends a reply to the co-ordinator.
334 * Following this it also receives a new control message from the co-ordinator and processes this message*/
335 int processClientReq(fixed_data_t *fixed, trans_commit_data_t *transinfo,
336 unsigned int *listmid, char *objread, void *modptr, unsigned int *oidmod, int acceptfd) {
337 char control, sendctrl, retval;
338 objheader_t *tmp_header;
342 /* Send reply to the Coordinator */
343 if((retval = handleTransReq(fixed, transinfo, listmid, objread, modptr,acceptfd)) == 0 ) {
344 printf("Error: In handleTransReq() %s, %d\n", __FILE__, __LINE__);
348 recv_data((int)acceptfd, &control, sizeof(char));
350 /* Process the new control message */
353 if (fixed->nummod > 0)
355 /* Unlock objects that was locked due to this transaction */
356 for(i = 0; i< transinfo->numlocked; i++) {
357 if((header = mhashSearch(transinfo->objlocked[i])) == NULL) {
358 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);// find the header address
361 STATUS(((objheader_t *)header)) &= ~(LOCK);
364 /* Send ack to Coordinator */
365 sendctrl = TRANS_UNSUCESSFUL;
366 send_data((int)acceptfd, &sendctrl, sizeof(char));
370 /* Invoke the transCommit process() */
371 if((val = transCommitProcess(modptr, oidmod, transinfo->objlocked, fixed->nummod, transinfo->numlocked, (int)acceptfd)) != 0) {
372 printf("Error: In transCommitProcess() %s, %d\n", __FILE__, __LINE__);
374 if (transinfo->objlocked != NULL) {
375 free(transinfo->objlocked);
377 if (transinfo->objnotfound != NULL) {
378 free(transinfo->objnotfound);
384 case TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING:
387 printf("Error: No response to TRANS_AGREE OR DISAGREE protocol %s, %d\n", __FILE__, __LINE__);
388 //TODO Use fixed.trans_id TID since Client may have died
393 if (transinfo->objlocked != NULL) {
394 free(transinfo->objlocked);
396 if (transinfo->objnotfound != NULL) {
397 free(transinfo->objnotfound);
403 /* This function increments counters while running a voting decision on all objects involved
404 * in TRANS_REQUEST and If a TRANS_DISAGREE sends the response immediately back to the coordinator */
405 char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigned int *listmid, char *objread, void *modptr, int acceptfd) {
407 unsigned short version;
408 char control = 0, *ptr;
410 unsigned int *oidnotfound, *oidlocked;
412 objheader_t *headptr;
414 /* Counters and arrays to formulate decision on control message to be sent */
415 oidnotfound = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
416 oidlocked = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
417 int objnotfound = 0, objlocked = 0;
418 int v_nomatch = 0, v_matchlock = 0, v_matchnolock = 0;
420 /* modptr points to the beginning of the object store
421 * created at the Pariticipant.
422 * Object store holds the modified objects involved in the transaction request */
423 ptr = (char *) modptr;
425 /* Process each oid in the machine pile/ group per thread */
426 for (i = 0; i < fixed->numread + fixed->nummod; i++) {
427 if (i < fixed->numread) {//Objs only read and not modified
428 int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array
430 oid = *((unsigned int *)(objread + incr));
431 incr += sizeof(unsigned int);
432 version = *((unsigned short *)(objread + incr));
433 } else {//Objs modified
435 headptr = (objheader_t *) ptr;
437 version = headptr->version;
438 GETSIZE(tmpsize, headptr);
439 ptr += sizeof(objheader_t) + tmpsize;
442 /* Check if object is still present in the machine since the beginning of TRANS_REQUEST */
444 if ((mobj = mhashSearch(oid)) == NULL) {/* Obj not found */
445 /* Save the oids not found and number of oids not found for later use */
446 oidnotfound[objnotfound] = oid;
448 } else { /* If Obj found in machine (i.e. has not moved) */
449 /* Check if Obj is locked by any previous transaction */
450 if ((STATUS(((objheader_t *)mobj)) & LOCK) == LOCK) {
451 if (version == ((objheader_t *)mobj)->version) { /* If locked then match versions */
453 } else {/* If versions don't match ...HARD ABORT */
455 /* Send TRANS_DISAGREE to Coordinator */
456 control = TRANS_DISAGREE;
458 for(j = 0; j < objlocked; j++) {
459 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
460 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
463 STATUS(headptr) &= ~(LOCK);
467 send_data(acceptfd, &control, sizeof(char));
470 } else {/* If Obj is not locked then lock object */
471 STATUS(((objheader_t *)mobj)) |= LOCK;
472 /* Save all object oids that are locked on this machine during this transaction request call */
473 oidlocked[objlocked] = OID(((objheader_t *)mobj));
475 if (version == ((objheader_t *)mobj)->version) { /* Check if versions match */
477 } else { /* If versions don't match ...HARD ABORT */
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 STATUS(headptr) &= ~(LOCK);
491 /* Send TRANS_DISAGREE to Coordinator */
492 send_data(acceptfd, &control, sizeof(char));
499 /* Decide what control message to send to Coordinator */
500 if ((control = decideCtrlMessage(fixed, transinfo, &v_matchnolock, &v_matchlock, &v_nomatch, &objnotfound, &objlocked,
501 modptr, oidnotfound, oidlocked, acceptfd)) == 0) {
502 printf("Error: In decideCtrlMessage() %s, %d\n", __FILE__, __LINE__);
509 /* This function decides what control message such as TRANS_AGREE, TRANS_DISAGREE or TRANS_SOFT_ABORT
510 * to send to Coordinator based on the votes of oids involved in the transaction */
511 char decideCtrlMessage(fixed_data_t *fixed, trans_commit_data_t *transinfo, int *v_matchnolock, int *v_matchlock,
512 int *v_nomatch, int *objnotfound, int *objlocked, void *modptr,
513 unsigned int *oidnotfound, unsigned int *oidlocked, int acceptfd) {
517 /* Condition to send TRANS_AGREE */
518 if(*(v_matchnolock) == fixed->numread + fixed->nummod) {
519 control = TRANS_AGREE;
520 /* Send control message */
521 send_data(acceptfd, &control, sizeof(char));
523 /* Condition to send TRANS_SOFT_ABORT */
524 if((*(v_matchlock) > 0 && *(v_nomatch) == 0) || (*(objnotfound) > 0 && *(v_nomatch) == 0)) {
525 control = TRANS_SOFT_ABORT;
527 /* Send control message */
528 send_data(acceptfd, &control, sizeof(char));
530 /* Send number of oids not found and the missing oids if objects are missing in the machine */
531 if(*(objnotfound) != 0) {
533 msg[0] = *(objnotfound);
534 send_data(acceptfd, &msg, sizeof(int));
535 int size = sizeof(unsigned int)* *(objnotfound);
536 send_data(acceptfd, oidnotfound, size);
540 /* Fill out the trans_commit_data_t data structure. This is required for a trans commit process
541 * if Participant receives a TRANS_COMMIT */
542 transinfo->objlocked = oidlocked;
543 transinfo->objnotfound = oidnotfound;
544 transinfo->modptr = modptr;
545 transinfo->numlocked = *(objlocked);
546 transinfo->numnotfound = *(objnotfound);
551 /* This function processes all modified objects involved in a TRANS_COMMIT and updates pointer
552 * addresses in lookup table and also changes version number
553 * Sends an ACK back to Coordinator */
554 int transCommitProcess(void *modptr, unsigned int *oidmod, unsigned int *oidlocked, int nummod, int numlocked, int acceptfd) {
556 objheader_t *newheader;
557 int i = 0, offset = 0;
561 /* Process each modified object saved in the mainobject store */
562 for(i = 0; i < nummod; i++) {
563 if((header = (objheader_t *) mhashSearch(oidmod[i])) == NULL) {
564 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
567 GETSIZE(tmpsize,header);
568 pthread_mutex_lock(&mainobjstore_mutex);
569 memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
570 header->version += 1;
571 /* If threads are waiting on this object to be updated, notify them */
572 pthread_mutex_lock(¬ifymutex);
573 if(header->notifylist != NULL) {
574 notifyAll(&header->notifylist, OID(header), header->version);
576 pthread_mutex_unlock(¬ifymutex);
577 pthread_mutex_unlock(&mainobjstore_mutex);
578 offset += sizeof(objheader_t) + tmpsize;
584 /* Unlock locked objects */
585 for(i = 0; i < numlocked; i++) {
586 if((header = (objheader_t *) mhashSearch(oidlocked[i])) == NULL) {
587 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
590 STATUS(header) &= ~(LOCK);
592 //TODO Update location lookup table
594 /* Send ack to coordinator */
595 control = TRANS_SUCESSFUL;
596 send_data((int)acceptfd, &control, sizeof(char));
600 /* This function recevies the oid and offset tuples from the Coordinator's prefetch call.
601 * Looks for the objects to be prefetched in the main object store.
602 * If objects are not found then record those and if objects are found
603 * then use offset values to prefetch references to other objects */
605 int prefetchReq(int acceptfd) {
606 int i, size, objsize, numoffset = 0;
608 char *recvbuffer, control;
609 unsigned int oid, mid=-1;
615 recv_data((int)acceptfd, &numoffset, sizeof(int));
618 recv_data((int)acceptfd, &oidmid, 2*sizeof(unsigned int));
620 if (mid != oidmid.mid) {
622 freeSockWithLock(transPResponseSocketPool, mid, sd);
625 sd = getSockWithLock(transPResponseSocketPool, mid);
627 short offsetarry[numoffset];
628 recv_data((int) acceptfd, offsetarry, numoffset*sizeof(short));
630 /*Process each oid */
631 if ((header = mhashSearch(oid)) == NULL) {/* Obj not found */
632 /* Save the oids not found in buffer for later use */
633 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
634 char sendbuffer[size];
635 *((int *) sendbuffer) = size;
636 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
637 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
638 control = TRANS_PREFETCH_RESPONSE;
639 sendPrefetchResponse(sd, &control, sendbuffer, &size);
640 } else { /* Object Found */
642 GETSIZE(objsize, header);
643 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
644 char sendbuffer[size];
645 *((int *) (sendbuffer + incr)) = size;
647 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
648 incr += sizeof(char);
649 *((unsigned int *)(sendbuffer+incr)) = oid;
650 incr += sizeof(unsigned int);
651 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
653 control = TRANS_PREFETCH_RESPONSE;
654 sendPrefetchResponse(sd, &control, sendbuffer, &size);
656 /* Calculate the oid corresponding to the offset value */
657 for(i = 0 ; i< numoffset ; i++) {
658 /* Check for arrays */
659 if(TYPE(header) > NUMCLASSES) {
660 int elementsize = classsize[TYPE(header)];
661 struct ArrayObject *ao = (struct ArrayObject *) (((char *)header) + sizeof(objheader_t));
662 unsigned short length = ao->___length___;
663 /* Check if array out of bounds */
664 if(offsetarry[i]< 0 || offsetarry[i] >= length) {
667 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + sizeof(struct ArrayObject) + (elementsize*offsetarry[i])));
669 oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + offsetarry[i]));
672 /* Don't continue if we hit a NULL pointer */
676 if((header = mhashSearch(oid)) == NULL) {
677 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) ;
678 char sendbuffer[size];
679 *((int *) sendbuffer) = size;
680 *((char *)(sendbuffer + sizeof(int))) = OBJECT_NOT_FOUND;
681 *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char))) = oid;
683 control = TRANS_PREFETCH_RESPONSE;
684 sendPrefetchResponse(sd, &control, sendbuffer, &size);
686 } else {/* Obj Found */
688 GETSIZE(objsize, header);
689 size = sizeof(int) + sizeof(char) + sizeof(unsigned int) + sizeof(objheader_t) + objsize;
690 char sendbuffer[size];
691 *((int *) (sendbuffer + incr)) = size;
693 *((char *)(sendbuffer + incr)) = OBJECT_FOUND;
694 incr += sizeof(char);
695 *((unsigned int *)(sendbuffer+incr)) = oid;
696 incr += sizeof(unsigned int);
697 memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
699 control = TRANS_PREFETCH_RESPONSE;
700 sendPrefetchResponse(sd, &control, sendbuffer, &size);
707 freeSockWithLock(transPResponseSocketPool, mid, sd);
712 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size) {
713 send_data(sd, control, sizeof(char));
714 /* Send the buffer with its size */
715 int length = *(size);
716 send_data(sd, sendbuffer, length);
719 void processReqNotify(unsigned int numoid, unsigned int *oidarry, unsigned short *versionarry, unsigned int mid, unsigned int threadid) {
722 unsigned short newversion;
723 char msg[1+ 2 * sizeof(unsigned int) + sizeof(unsigned short)];
725 struct sockaddr_in remoteAddr;
731 oid = *(oidarry + i);
732 if((header = (objheader_t *) mhashSearch(oid)) == NULL) {
733 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
736 /* Check to see if versions are same */
738 if ((STATUS(header) & LOCK) != LOCK) {
739 pthread_mutex_lock(¬ifymutex);
740 STATUS(header) |= LOCK;
741 newversion = header->version;
742 if(newversion == *(versionarry + i)) {
743 //Add to the notify list
744 if((header->notifylist = insNode(header->notifylist, threadid, mid)) == NULL) {
745 printf("Error: Obj notify list points to NULL %s, %d\n", __FILE__, __LINE__);
746 pthread_mutex_unlock(¬ifymutex);
749 STATUS(header) &= ~(LOCK);
750 pthread_mutex_unlock(¬ifymutex);
752 STATUS(header) &= ~(LOCK);
753 pthread_mutex_unlock(¬ifymutex);
754 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
755 perror("processReqNotify():socket()");
758 bzero(&remoteAddr, sizeof(remoteAddr));
759 remoteAddr.sin_family = AF_INET;
760 remoteAddr.sin_port = htons(LISTEN_PORT);
761 remoteAddr.sin_addr.s_addr = htonl(mid);
763 if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
764 printf("Error: processReqNotify():error %d connecting to %s:%d\n", errno,
765 inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
769 //Send Update notification
770 msg[0] = THREAD_NOTIFY_RESPONSE;
771 *((unsigned int *)&msg[1]) = oid;
772 size = sizeof(unsigned int);
773 *((unsigned short *)(&msg[1]+size)) = newversion;
774 size += sizeof(unsigned short);
775 *((unsigned int *)(&msg[1]+size)) = threadid;
776 size = 1+ 2*sizeof(unsigned int) + sizeof(unsigned short);
777 send_data(sd, msg, size);