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 UnLock(STATUSPTR(header));
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 if (test_and_set(STATUSPTR(mobj))) {
459 if (version == ((objheader_t *)mobj)->version) { /* If locked then match versions */
461 } else {/* If versions don't match ...HARD ABORT */
463 /* Send TRANS_DISAGREE to Coordinator */
464 control = TRANS_DISAGREE;
466 for(j = 0; j < objlocked; j++) {
467 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
468 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
471 UnLock(STATUSPTR(headptr));
475 send_data(acceptfd, &control, sizeof(char));
478 } else {/* If Obj is not locked then lock object */
479 /* Save all object oids that are locked on this machine during this transaction request call */
480 oidlocked[objlocked] = OID(((objheader_t *)mobj));
482 if (version == ((objheader_t *)mobj)->version) { /* Check if versions match */
484 } else { /* If versions don't match ...HARD ABORT */
486 control = TRANS_DISAGREE;
488 for(j = 0; j < objlocked; j++) {
489 if((headptr = mhashSearch(oidlocked[j])) == NULL) {
490 printf("mhashSearch returns NULL at %s, %d\n", __FILE__, __LINE__);
493 UnLock(STATUSPTR(headptr));
498 /* Send TRANS_DISAGREE to Coordinator */
499 send_data(acceptfd, &control, sizeof(char));
506 /* Decide what control message to send to Coordinator */
507 if ((control = decideCtrlMessage(fixed, transinfo, &v_matchnolock, &v_matchlock, &v_nomatch, &objnotfound, &objlocked,
508 modptr, oidnotfound, oidlocked, acceptfd)) == 0) {
509 printf("Error: In decideCtrlMessage() %s, %d\n", __FILE__, __LINE__);
516 /* This function decides what control message such as TRANS_AGREE, TRANS_DISAGREE or TRANS_SOFT_ABORT
517 * to send to Coordinator based on the votes of oids involved in the transaction */
518 char decideCtrlMessage(fixed_data_t *fixed, trans_commit_data_t *transinfo, int *v_matchnolock, int *v_matchlock,
519 int *v_nomatch, int *objnotfound, int *objlocked, void *modptr,
520 unsigned int *oidnotfound, unsigned int *oidlocked, int acceptfd) {
524 /* Condition to send TRANS_AGREE */
525 if(*(v_matchnolock) == fixed->numread + fixed->nummod) {
526 control = TRANS_AGREE;
527 /* Send control message */
528 send_data(acceptfd, &control, sizeof(char));
530 /* Condition to send TRANS_SOFT_ABORT */
531 if((*(v_matchlock) > 0 && *(v_nomatch) == 0) || (*(objnotfound) > 0 && *(v_nomatch) == 0)) {
532 control = TRANS_SOFT_ABORT;
534 /* Send control message */
535 send_data(acceptfd, &control, sizeof(char));
537 /* Send number of oids not found and the missing oids if objects are missing in the machine */
538 if(*(objnotfound) != 0) {
540 msg[0] = *(objnotfound);
541 send_data(acceptfd, &msg, sizeof(int));
542 int size = sizeof(unsigned int)* *(objnotfound);
543 send_data(acceptfd, oidnotfound, size);
547 /* Fill out the trans_commit_data_t data structure. This is required for a trans commit process
548 * if Participant receives a TRANS_COMMIT */
549 transinfo->objlocked = oidlocked;
550 transinfo->objnotfound = oidnotfound;
551 transinfo->modptr = modptr;
552 transinfo->numlocked = *(objlocked);
553 transinfo->numnotfound = *(objnotfound);
558 /* This function processes all modified objects involved in a TRANS_COMMIT and updates pointer
559 * addresses in lookup table and also changes version number
560 * Sends an ACK back to Coordinator */
561 int transCommitProcess(void *modptr, unsigned int *oidmod, unsigned int *oidlocked, int nummod, int numlocked, int acceptfd) {
563 objheader_t *newheader;
564 int i = 0, offset = 0;
568 /* Process each modified object saved in the mainobject store */
569 for(i = 0; i < nummod; i++) {
570 if((header = (objheader_t *) mhashSearch(oidmod[i])) == NULL) {
571 printf("Error: mhashsearch returns NULL at %s, %d\n", __FILE__, __LINE__);
574 GETSIZE(tmpsize,header);
575 memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
576 header->version += 1;
577 /* If threads are waiting on this object to be updated, notify them */
578 if(header->notifylist != NULL) {
579 notifyAll(&header->notifylist, OID(header), header->version);
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 UnLock(STATUSPTR(header));
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 (test_and_set(STATUSPTR(header))==0) {
743 newversion = header->version;
744 if(newversion == *(versionarry + i)) {
745 //Add to the notify list
746 if((header->notifylist = insNode(header->notifylist, threadid, mid)) == NULL) {
747 printf("Error: Obj notify list points to NULL %s, %d\n", __FILE__, __LINE__);
750 UnLock(STATUSPTR(header));
752 UnLock(STATUSPTR(header));
753 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
754 perror("processReqNotify():socket()");
757 bzero(&remoteAddr, sizeof(remoteAddr));
758 remoteAddr.sin_family = AF_INET;
759 remoteAddr.sin_port = htons(LISTEN_PORT);
760 remoteAddr.sin_addr.s_addr = htonl(mid);
762 if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
763 printf("Error: processReqNotify():error %d connecting to %s:%d\n", errno,
764 inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
768 //Send Update notification
769 msg[0] = THREAD_NOTIFY_RESPONSE;
770 *((unsigned int *)&msg[1]) = oid;
771 size = sizeof(unsigned int);
772 *((unsigned short *)(&msg[1]+size)) = newversion;
773 size += sizeof(unsigned short);
774 *((unsigned int *)(&msg[1]+size)) = threadid;
775 size = 1+ 2*sizeof(unsigned int) + sizeof(unsigned short);
776 send_data(sd, msg, size);