Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > BestEffortMessaging
changeset 2:b6dd31dbab8c
Receiving only messages for the current endpoint
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 12 Mar 2012 18:35:10 +0100 |
| parents | 826448e34e80 |
| children | 5c0fb7c519d7 |
| files | LossyCom.c LossyCom.h |
| diffstat | 2 files changed, 28 insertions(+), 16 deletions(-) [+] |
line diff
1.1 --- a/LossyCom.c Thu Mar 08 20:06:00 2012 +0100 1.2 +++ b/LossyCom.c Mon Mar 12 18:35:10 2012 +0100 1.3 @@ -84,12 +84,14 @@ 1.4 msgDraft; 1.5 1.6 localEndpoint->centralExchange->triggerCounter = triggerCopy; 1.7 + //printf("send updated trigger to %d\n", triggerCopy); 1.8 } 1.9 1.10 void inline lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint) 1.11 { 1.12 uint16_t currentTriggerCopy; 1.13 lossyCom__endpointID_t senderEndpointID; 1.14 + lossyCom__endpointID_t receiverID; 1.15 lossyCom__msg_t msgCopy; 1.16 uint16_t msgTrigger; 1.17 lossyCom__msgBody_t msgBody; 1.18 @@ -98,26 +100,36 @@ 1.19 currentTriggerCopy = localEndpoint->centralExchange->triggerCounter; 1.20 1.21 //new message arrived if trigger counter is higher than the last time read 1.22 - while(senderEndpointID < localEndpoint->centralExchange->numEndpoints) 1.23 + if(currentTriggerCopy > localEndpoint->localTriggerCopy) 1.24 { 1.25 - if(senderEndpointID != localEndpoint->endpointID) 1.26 + while(senderEndpointID < localEndpoint->centralExchange->numEndpoints) 1.27 { 1.28 - msgCopy = localEndpoint->centralExchange->outboxArray[senderEndpointID]; 1.29 - msgTrigger = 0xFFFF & (msgCopy >> TRIGGER_SHIFT); 1.30 - // check if the message is new (msg trigger > archived trigger) 1.31 - // and already valid (msgTrigger <= currentTriggerCopy) 1.32 - if(msgTrigger > localEndpoint->localTriggerCopy && 1.33 - msgTrigger <= currentTriggerCopy) 1.34 + if(senderEndpointID != localEndpoint->endpointID) 1.35 { 1.36 - //let the message handler parse the message 1.37 - msgBody = 0xFFFFFFFF & msgCopy; 1.38 - (*(localEndpoint->msgHandler))(senderEndpointID, 1.39 - msgBody, 1.40 - localEndpoint->msgHandlerData); 1.41 + msgCopy = localEndpoint->centralExchange->outboxArray[senderEndpointID]; 1.42 + msgTrigger = 0xFFFF & (msgCopy >> TRIGGER_SHIFT); 1.43 + // check if the message is new (msg trigger > archived trigger) 1.44 + // and already valid (msgTrigger <= currentTriggerCopy) 1.45 + if(msgTrigger > localEndpoint->localTriggerCopy && 1.46 + msgTrigger <= currentTriggerCopy) 1.47 + { 1.48 + //printf("receive search until %d \n", currentTriggerCopy); 1.49 + //let the message handler parse the message 1.50 + msgBody = 0xFFFFFFFF & msgCopy; 1.51 + receiverID = 0xFFFF & (msgCopy >> ENDPOINT_ID_SHIFT); 1.52 + //only receive broadcast and p2p for own receiverID 1.53 + if(receiverID == BROADCAST_ID || 1.54 + receiverID == localEndpoint->endpointID) 1.55 + { 1.56 + (*(localEndpoint->msgHandler))(senderEndpointID, 1.57 + msgBody, 1.58 + localEndpoint->msgHandlerData); 1.59 + } 1.60 + } 1.61 } 1.62 + senderEndpointID++; 1.63 } 1.64 - senderEndpointID++; 1.65 } 1.66 - //save last parsed msg 1.67 + //save last TriggerCounter of last parsed Msg 1.68 localEndpoint->localTriggerCopy = currentTriggerCopy; 1.69 } 1.70 \ No newline at end of file
2.1 --- a/LossyCom.h Thu Mar 08 20:06:00 2012 +0100 2.2 +++ b/LossyCom.h Mon Mar 12 18:35:10 2012 +0100 2.3 @@ -57,7 +57,7 @@ 2.4 * Central communication structure. 2.5 */ 2.6 typedef struct{ 2.7 - uint16_t triggerCounter; 2.8 + volatile uint16_t triggerCounter; 2.9 uint16_t numEndpoints; 2.10 lossyCom__msg_t* outboxArray; 2.11 }lossyCom__exchange_t;
