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;
18 objstr_t *mainobjstore;
19 pthread_mutex_t mainobjstore_mutex;
20 pthread_mutexattr_t mainobjstore_mutex_attr; /* Attribute for lock to make it a recursive lock */
22 sockPoolHashTable_t *transPResponseSocketPool;
24 /* This function initializes the main objects store and creates the
25 * global machine and location lookup table */
29 mainobjstore = objstrCreate(DEFAULT_OBJ_STORE_SIZE);
30 /* Initialize attribute for mutex */
31 pthread_mutexattr_init(&mainobjstore_mutex_attr);
32 pthread_mutexattr_settype(&mainobjstore_mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);
33 pthread_mutex_init(&mainobjstore_mutex, &mainobjstore_mutex_attr);
34 if (mhashCreate(HASH_SIZE, LOADFACTOR))
37 if (lhashCreate(HASH_SIZE, LOADFACTOR))
40 if (notifyhashCreate(N_HASH_SIZE, N_LOADFACTOR))
43 //Initialize socket pool
44 if((transPResponseSocketPool = createSockPool(transPResponseSocketPool, 2*numHostsInSystem+1)) == NULL) {
45 printf("Error in creating new socket pool at %s line %d\n", __FILE__, __LINE__);
52 /* This function starts the thread to listen on a socket
53 * for tranaction calls */
56 int listenfd, acceptfd;
57 struct sockaddr_in my_addr;
58 struct sockaddr_in client_addr;
59 socklen_t addrlength = sizeof(struct sockaddr);
60 pthread_t thread_dstm_accept;
64 listenfd = socket(AF_INET, SOCK_STREAM, 0);
71 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &setsockflag, sizeof (setsockflag)) < 0) {
76 if (setsockopt(listenfd, SOL_SOCKET, SO_NOSIGPIPE, &setsockflag, sizeof (setsockflag)) < 0) {
82 my_addr.sin_family = AF_INET;
83 my_addr.sin_port = htons(LISTEN_PORT);
84 my_addr.sin_addr.s_addr = INADDR_ANY;
85 memset(&(my_addr.sin_zero), '\0', 8);
87 if (bind(listenfd, (struct sockaddr *)&my_addr, addrlength) == -1)
93 if (listen(listenfd, BACKLOG) == -1)
99 printf("Listening on port %d, fd = %d\n", LISTEN_PORT, listenfd);
103 acceptfd = accept(listenfd, (struct sockaddr *)&client_addr, &addrlength);
105 retval=pthread_create(&thread_dstm_accept, NULL, dstmAccept, (void *)acceptfd);
107 pthread_detach(thread_dstm_accept);
110 /* This function accepts a new connection request, decodes the control message in the connection
111 * and accordingly calls other functions to process new requests */
112 void *dstmAccept(void *acceptfd) {
113 int val, retval, size, sum, sockid;
120 trans_commit_data_t transinfo;
121 unsigned short objType, *versionarry, version;
122 unsigned int *oidarry, numoid, mid, threadid;
125 transinfo.objlocked = NULL;
126 transinfo.objnotfound = NULL;
127 transinfo.modptr = NULL;
128 transinfo.numlocked = 0;
129 transinfo.numnotfound = 0;
132 /* Receive control messages from other machines */
134 int ret=recv_data_errorcode((int)acceptfd, &control, sizeof(char));
139 /* Read oid requested and search if available */
140 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
141 if((srcObj = mhashSearch(oid)) == NULL) {
142 printf("Error: Object 0x%x is not found in Main Object Store %s, %d\n", oid, __FILE__, __LINE__);
145 h = (objheader_t *) srcObj;
147 size += sizeof(objheader_t);
148 sockid = (int) acceptfd;
151 ctrl = OBJECT_NOT_FOUND;
152 send_data(sockid, &ctrl, sizeof(char));
155 char msg[]={OBJECT_FOUND, 0, 0, 0, 0};
156 *((int *)&msg[1])=size;
157 send_data(sockid, &msg, sizeof(msg));
158 send_data(sockid, h, size);
162 case READ_MULT_REQUEST:
168 case MOVE_MULT_REQUEST:
172 /* Read transaction request */
173 transinfo.objlocked = NULL;
174 transinfo.objnotfound = NULL;
175 transinfo.modptr = NULL;
176 transinfo.numlocked = 0;
177 transinfo.numnotfound = 0;
178 if((val = readClientReq(&transinfo, (int)acceptfd)) != 0) {
179 printf("Error: In readClientReq() %s, %d\n", __FILE__, __LINE__);
184 if((val = prefetchReq((int)acceptfd)) != 0) {
185 printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__);
189 case TRANS_PREFETCH_RESPONSE:
190 if((val = getPrefetchResponse((int) acceptfd)) != 0) {
191 printf("Error: In getPrefetchResponse() %s, %d\n", __FILE__, __LINE__);
195 case START_REMOTE_THREAD:
196 recv_data((int)acceptfd, &oid, sizeof(unsigned int));
197 objType = getObjType(oid);
198 startDSMthread(oid, objType);
201 case THREAD_NOTIFY_REQUEST:
202 recv_data((int)acceptfd, &numoid, sizeof(unsigned int));
203 size = (sizeof(unsigned int) + sizeof(unsigned short)) * numoid + 2 * sizeof(unsigned int);
204 if((buffer = calloc(1,size)) == NULL) {
205 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
209 recv_data((int)acceptfd, buffer, size);
211 oidarry = calloc(numoid, sizeof(unsigned int));
212 memcpy(oidarry, buffer, sizeof(unsigned int) * numoid);
213 size = sizeof(unsigned int) * numoid;
214 versionarry = calloc(numoid, sizeof(unsigned short));
215 memcpy(versionarry, buffer+size, sizeof(unsigned short) * numoid);
216 size += sizeof(unsigned short) * numoid;
217 mid = *((unsigned int *)(buffer+size));
218 size += sizeof(unsigned int);
219 threadid = *((unsigned int *)(buffer+size));
220 processReqNotify(numoid, oidarry, versionarry, mid, threadid);
225 case THREAD_NOTIFY_RESPONSE:
226 size = sizeof(unsigned short) + 2 * sizeof(unsigned int);
227 if((buffer = calloc(1,size)) == NULL) {
228 printf("%s() Calloc error at %s, %d\n", __func__, __FILE__, __LINE__);
232 recv_data((int)acceptfd, buffer, size);
234 oid = *((unsigned int *)buffer);
235 size = sizeof(unsigned int);
236 version = *((unsigned short *)(buffer+size));
237 size += sizeof(unsigned short);
238 threadid = *((unsigned int *)(buffer+size));
239 threadNotify(oid,version,threadid);
243 case CLOSE_CONNECTION:
244 goto closeconnection;
247 printf("Error: dstmAccept() Unknown opcode %d at %s, %d\n", control, __FILE__, __LINE__);
252 /* Close connection */
253 if (close((int)acceptfd) == -1)
258 /* This function reads the information available in a transaction request
259 * and makes a function call to process the request */
260 int readClientReq(trans_commit_data_t *transinfo, int acceptfd) {
263 unsigned int *oidmod, oid;
265 objheader_t *headaddr;
266 int sum, i, size, n, val;
270 /* Read fixed_data_t data structure */
271 size = sizeof(fixed) - 1;
272 ptr = (char *)&fixed;;
273 fixed.control = TRANS_REQUEST;
274 recv_data((int)acceptfd, ptr+1, size);
276 /* Read list of mids */
277 int mcount = fixed.mcount;
278 size = mcount * sizeof(unsigned int);
279 unsigned int listmid[mcount];
280 ptr = (char *) listmid;
281 recv_data((int)acceptfd, ptr, size);
283 /* Read oid and version tuples for those objects that are not modified in the transaction */
284 int numread = fixed.numread;
285 size = numread * (sizeof(unsigned int) + sizeof(unsigned short));
287 if(numread != 0) { //If pile contains more than one object to be read,
288 // keep reading all objects
289 recv_data((int)acceptfd, objread, size);
292 /* Read modified objects */
293 if(fixed.nummod != 0) {
294 if ((modptr = calloc(1, fixed.sum_bytes)) == NULL) {
295 printf("calloc error for modified objects %s, %d\n", __FILE__, __LINE__);
298 size = fixed.sum_bytes;
299 recv_data((int)acceptfd, modptr, size);
302 /* Create an array of oids for modified objects */
303 oidmod = (unsigned int *) calloc(fixed.nummod, sizeof(unsigned int));
306 printf("calloc error %s, %d\n", __FILE__, __LINE__);
309 ptr = (char *) modptr;
310 for(i = 0 ; i < fixed.nummod; i++) {
312 headaddr = (objheader_t *) ptr;
315 GETSIZE(tmpsize, headaddr);
316 ptr += sizeof(objheader_t) + tmpsize;
319 /*Process the information read */
320 if((val = processClientReq(&fixed, transinfo, listmid, objread, modptr, oidmod, acceptfd)) != 0) {
321 printf("Error: In processClientReq() %s, %d\n", __FILE__, __LINE__);
337 /* This function processes the Coordinator's transaction request using "handleTransReq"
338 * function and sends a reply to the co-ordinator.
339 * Following this it also receives a new control message from the co-ordinator and processes this message*/
340 int processClientReq(fixed_data_t *fixed, trans_commit_data_t *transinfo,
341 unsigned int *listmid, char *objread, void *modptr, unsigned int *oidmod, int acceptfd) {
342 char control, sendctrl, retval;
343 objheader_t *tmp_header;
347 /* Send reply to the Coordinator */
348 if((retval = handleTransReq(fixed, transinfo, listmid, objread, modptr,acceptfd)) == 0 ) {
349 printf("Error: In handleTransReq() %s, %d\n", __FILE__, __LINE__);
353 recv_data((int)acceptfd, &control, sizeof(char));
355 /* Process the new control message */
358 if (fixed->nummod > 0)
360 /* Unlock objects that was locked due to this transaction */
361 for(i = 0; i< transinfo->numlocked; i++) {
362 if((header = mhashSearch(transinfo->objlocked[i])) == NULL) {
363 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);// find the header address
366 STATUS(((objheader_t *)header)) &= ~(LOCK);
369 /* Send ack to Coordinator */
370 sendctrl = TRANS_UNSUCESSFUL;
371 send_data((int)acceptfd, &sendctrl, sizeof(char));
375 /* Invoke the transCommit process() */
376 if((val = transCommitProcess(modptr, oidmod, transinfo->objlocked, fixed->nummod, transinfo->numlocked, (int)acceptfd)) != 0) {
377 printf("Error: In transCommitProcess() %s, %d\n", __FILE__, __LINE__);
379 if (transinfo->objlocked != NULL) {
380 free(transinfo->objlocked);
382 if (transinfo->objnotfound != NULL) {
383 free(transinfo->objnotfound);
389 case TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING:
392 printf("Error: No response to TRANS_AGREE OR DISAGREE protocol %s, %d\n", __FILE__, __LINE__);
393 //TODO Use fixed.trans_id TID since Client may have died
398 if (transinfo->objlocked != NULL) {
399 free(transinfo->objlocked);
401 if (transinfo->objnotfound != NULL) {
402 free(transinfo->objnotfound);
408 /* This function increments counters while running a voting decision on all objects involved
409 * in TRANS_REQUEST and If a TRANS_DISAGREE sends the response immediately back to the coordinator */
410 char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigned int *listmid, char *objread, void *modptr, int acceptfd) {
412 unsigned short version;
413 char control = 0, *ptr;
415 unsigned int *oidnotfound, *oidlocked;
417 objheader_t *headptr;
419 /* Counters and arrays to formulate decision on control message to be sent */
420 oidnotfound = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
421 oidlocked = (unsigned int *) calloc(fixed->numread + fixed->nummod, sizeof(unsigned int));
422 int objnotfound = 0, objlocked = 0;
423 int v_nomatch = 0, v_matchlock = 0, v_matchnolock = 0;
425 /* modptr points to the beginning of the object store
426 * created at the Pariticipant.
427 * Object store holds the modified objects involved in the transaction request */
428 ptr = (char *) modptr;
430 /* Process each oid in the machine pile/ group per thread */
431 for (i = 0; i < fixed->numread + fixed->nummod; i++) {
432 if (i < fixed->numread) {//Objs only read and not modified
433 int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array
435 oid = *((unsigned int *)(objread + incr));
436 incr += sizeof(unsigned int);
437 version = *((unsigned short *)(objread + incr));
438 } else {//Objs modified
440 headptr = (objheader_t *) ptr;
442 version = headptr->version;
443 GETSIZE(tmpsize, headptr);
444 ptr += sizeof(objheader_t) + tmpsize;
447 /* Check if object is still present in the machine since the beginning of TRANS_REQUEST */
449 if ((mobj = mhashSearch(oid)) == NULL) {/* Obj not found */
450 /* Save the oids not found and number of oids not found for later use */
451 oidnotfound[objnotfound] = oid;
453 } else { /* If Obj found in machine (i.e. has not moved) */
454 /* Check if Obj is locked by any previous transaction */
455 if ((STATUS(((objheader_t *)mobj)) & LOCK) == LOCK) {
456 if (version == ((objheader_t *)mobj)->version) { /* If locked then match versions */
458 } else {/* If versions don't match ...HARD ABORT */
460 /* Send TRANS_DISAGREE to Coordinator */
461 control = TRANS_DISAGREE;
463 for(j = 0; j < objlocked; j++) {
464 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
465 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
468 STATUS(headptr) &= ~(LOCK);
472 send_data(acceptfd, &control, sizeof(char));
475 } else {/* If Obj is not locked then lock object */
476 STATUS(((objheader_t *)mobj)) |= LOCK;
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 pthread_mutex_lock(&mainobjstore_mutex);
574 memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
575 header->version += 1;
576 /* If threads are waiting on this object to be updated, notify them */
577 if(header->notifylist != NULL) {
578 notifyAll(&header->notifylist, OID(header), header->version);
580 pthread_mutex_unlock(&mainobjstore_mutex);
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 //FIXME make locking atomic
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__);
751 STATUS(header) &= ~(LOCK);
753 STATUS(header) &= ~(LOCK);
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);