diff --git a/common/normApp.cpp b/common/normApp.cpp index eb7e132..7c71f0c 100644 --- a/common/normApp.cpp +++ b/common/normApp.cpp @@ -79,6 +79,7 @@ class NormApp : public NormController, public ProtoApp char* address; // session address UINT16 port; // session port number UINT8 ttl; + char* interface_name; // for multi-home hosts double tx_rate; // bits/sec bool cc_enable; @@ -120,7 +121,8 @@ NormApp::NormApp() push_stream(false), msg_flush_mode(NormStreamObject::FLUSH_PASSIVE), input_messaging(false), input_msg_length(0), input_msg_index(0), output_index(0), output_messaging(false), output_msg_length(0), output_msg_sync(false), - address(NULL), port(0), ttl(3), tx_rate(64000.0), cc_enable(false), + address(NULL), port(0), ttl(3), interface_name(NULL), + tx_rate(64000.0), cc_enable(false), segment_size(1024), ndata(32), nparity(16), auto_parity(0), extra_parity(0), backoff_factor(NormSession::DEFAULT_BACKOFF_FACTOR), tx_buffer_size(1024*1024), @@ -161,6 +163,7 @@ const char* const NormApp::cmd_list[] = "+rxloss", // rx packet loss percent (for testing) "+address", // session destination address "+ttl", // multicast hop count scope + "+interface", // multicast interface name to use "+cc", // congestion control on/off "+rate", // tx date rate (bps) "-push", // push stream writes for real-time messaging @@ -350,6 +353,17 @@ bool NormApp::OnCommand(const char* cmd, const char* val) } ttl = ttlTemp; } + else if (!strncmp("interface", cmd, len)) + { + if (interface_name) delete[] interface_name; + if (!(interface_name = new char[strlen(val)+1])) + { + DMSG(0, "NormApp::OnCommand(interface) error allocating string: %s\n", + GetErrorString()); + return false; + } + strcpy(interface_name, val); + } else if (!strncmp("rate", cmd, len)) { double txRate = atof(val); @@ -1273,11 +1287,11 @@ bool NormApp::OnStartup(int argc, const char*const* argv) return false; } + if (control_remote) return false; + #ifdef UNIX signal(SIGCHLD, SignalHandler); #endif // UNIX - - if (control_remote) return false; // Validate our application settings if (!address) @@ -1309,7 +1323,7 @@ bool NormApp::OnStartup(int argc, const char*const* argv) session->ServerSetBaseObjectId(baseId); session->SetCongestionControl(cc_enable); - if (!session->StartServer(tx_buffer_size, segment_size, ndata, nparity)) + if (!session->StartServer(tx_buffer_size, segment_size, ndata, nparity, interface_name)) { DMSG(0, "NormApp::OnStartup() start server error!\n"); session_mgr.Destroy(); @@ -1335,7 +1349,7 @@ bool NormApp::OnStartup(int argc, const char*const* argv) // StartClient(bufferMax (per-sender)) session->SetUnicastNacks(unicast_nacks); session->ClientSetSilent(silent_client); - if (!session->StartClient(rx_buffer_size)) + if (!session->StartClient(rx_buffer_size, interface_name)) { DMSG(0, "NormApp::OnStartup() start client error!\n"); session_mgr.Destroy(); diff --git a/common/normBitmask.cpp b/common/normBitmask.cpp index 54143b0..de7cba6 100644 --- a/common/normBitmask.cpp +++ b/common/normBitmask.cpp @@ -169,7 +169,7 @@ NormBitmask::~NormBitmask() Destroy(); } -bool NormBitmask::Init(unsigned long numBits) +bool NormBitmask::Init(UINT32 numBits) { if (mask) Destroy(); // Allocate memory for mask @@ -199,13 +199,13 @@ void NormBitmask::Destroy() } // end NormBitmask::Destroy() -bool NormBitmask::GetNextSet(unsigned long& index) const +bool NormBitmask::GetNextSet(UINT32& index) const { //TRACE("NormBitmask::GetNextSet(%lu) first_set:%lu num_bits:%lu\n", // index, first_set, num_bits); if (index >= num_bits) return false; if (index < first_set) return GetFirstSet(index); - unsigned long maskIndex = index >> 3; + UINT32 maskIndex = index >> 3; if (mask[maskIndex]) { int w = WEIGHT[mask[maskIndex]]; @@ -231,11 +231,11 @@ bool NormBitmask::GetNextSet(unsigned long& index) const return false; } // end NormBitmask::NextSet() -bool NormBitmask::GetPrevSet(unsigned long& index) const +bool NormBitmask::GetPrevSet(UINT32& index) const { if (index >= num_bits) index = num_bits - 1; if (index < first_set) return false; - unsigned long maskIndex = index >> 3; + UINT32 maskIndex = index >> 3; if (mask[maskIndex]) { int w = WEIGHT[mask[maskIndex]] - 1; @@ -251,7 +251,7 @@ bool NormBitmask::GetPrevSet(unsigned long& index) const } } maskIndex--; - unsigned long startIndex = first_set >> 3; + UINT32 startIndex = first_set >> 3; for (; maskIndex >= startIndex; maskIndex--) { if (mask[maskIndex]) @@ -264,11 +264,11 @@ bool NormBitmask::GetPrevSet(unsigned long& index) const return false; // (nothing prior was set) } // end NormBitmask::PrevSet() -bool NormBitmask::GetNextUnset(unsigned long& index) const +bool NormBitmask::GetNextUnset(UINT32& index) const { if (index >= num_bits) return false; - unsigned long next = index; - unsigned long maskIndex = next >> 3; + UINT32 next = index; + UINT32 maskIndex = next >> 3; unsigned char bit = 0x80 >> (next & 0x07); while (next < num_bits) { @@ -298,11 +298,11 @@ bool NormBitmask::GetNextUnset(unsigned long& index) const } // end NormBitmask::NextUnset() -bool NormBitmask::SetBits(unsigned long index, unsigned long count) +bool NormBitmask::SetBits(UINT32 index, UINT32 count) { if (0 == count) return true; if ((index+count) > num_bits) return false; - unsigned long maskIndex = index >> 3; + UINT32 maskIndex = index >> 3; // To set appropriate bits in first byte unsigned int bitIndex = index & 0x07; unsigned int bitRemainder = 8 - bitIndex; @@ -315,7 +315,7 @@ bool NormBitmask::SetBits(unsigned long index, unsigned long count) { mask[maskIndex] |= 0x00ff >> bitIndex; count -= bitRemainder; - unsigned long nbytes = count >> 3; + UINT32 nbytes = count >> 3; memset(&mask[++maskIndex], 0xff, nbytes); count &= 0x07; if (count) @@ -326,16 +326,16 @@ bool NormBitmask::SetBits(unsigned long index, unsigned long count) } // end NormBitmask::SetBits() -bool NormBitmask::UnsetBits(unsigned long index, unsigned long count) +bool NormBitmask::UnsetBits(UINT32 index, UINT32 count) { if ((index >= num_bits)|| (0 == count)) return true; - unsigned long end = index + count; + UINT32 end = index + count; if (end > num_bits) { end = num_bits; count = end - index; } - unsigned long maskIndex = index >> 3; + UINT32 maskIndex = index >> 3; // To unset appropriate bits in first byte unsigned int bitIndex = index & 0x07; unsigned int bitRemainder = 8 - bitIndex; @@ -348,7 +348,7 @@ bool NormBitmask::UnsetBits(unsigned long index, unsigned long count) { mask[maskIndex] &= 0x00ff << bitRemainder; count -= bitRemainder; - unsigned long nbytes = count >> 3; + UINT32 nbytes = count >> 3; memset(&mask[++maskIndex], 0, nbytes); count &= 0x07; if (count) mask[maskIndex+nbytes] &= 0xff >> count; @@ -385,8 +385,8 @@ bool NormBitmask::Add(const NormBitmask& b) // this = this & ~b bool NormBitmask::Subtract(const NormBitmask& b) { - unsigned long len = (mask_len < b.mask_len) ? mask_len : b.mask_len; - for(unsigned long i = 0; i < len; i++) + UINT32 len = (mask_len < b.mask_len) ? mask_len : b.mask_len; + for(UINT32 i = 0; i < len; i++) mask[i] &= ~b.mask[i]; if (first_set >= b.first_set) { @@ -421,7 +421,7 @@ bool NormBitmask::XCopy(const NormBitmask& b) // this = this & b bool NormBitmask::Multiply(const NormBitmask& b) { - unsigned long len = (mask_len < b.mask_len) ? mask_len : b.mask_len; + UINT32 len = (mask_len < b.mask_len) ? mask_len : b.mask_len; for(unsigned int i = 0; i < len; i++) mask[i] |= b.mask[i]; if (len < mask_len) memset(&mask[len], 0, mask_len - len); @@ -452,8 +452,8 @@ bool NormBitmask::Xor(const NormBitmask& b) void NormBitmask::Display(FILE* stream) { - unsigned long index = 0; - for (unsigned long i = 0; i < num_bits; i++) + UINT32 index = 0; + for (UINT32 i = 0; i < num_bits; i++) { if (Test(index++)) fprintf(stream, "1"); else fprintf(stream, "0"); if (0x07 == (i & 0x07)) fprintf(stream, " "); @@ -478,12 +478,12 @@ NormSlidingMask::~NormSlidingMask() Destroy(); } -bool NormSlidingMask::Init(long numBits, UINT32 rangeMask) +bool NormSlidingMask::Init(INT32 numBits, UINT32 rangeMask) { if (mask) Destroy(); if (numBits <= 0) return false; - unsigned long len = (numBits + 7) >> 3; + UINT32 len = (numBits + 7) >> 3; if ((mask = new unsigned char[len])) { range_mask = rangeMask; @@ -509,13 +509,13 @@ void NormSlidingMask::Destroy() } } // end NormSlidingMask::Destroy() -bool NormSlidingMask::CanSet(unsigned long index) const +bool NormSlidingMask::CanSet(UINT32 index) const { if (IsSet()) { // Determine position with respect to current start // and end, given the "offset" of the current start - long pos = Delta(index, offset); + INT32 pos = Delta(index, offset); if (pos < 0) { // Precedes start. @@ -555,14 +555,14 @@ bool NormSlidingMask::CanSet(unsigned long index) const } } // end NormSlidingMask::CanSet() -bool NormSlidingMask::Set(unsigned long index) +bool NormSlidingMask::Set(UINT32 index) { ASSERT(CanSet(index)); if (IsSet()) { // Determine position with respect to current start // and end, given the "offset" of the current start - long pos = Delta(index , offset); + INT32 pos = Delta(index , offset); if (pos < 0) { // Precedes start. @@ -607,7 +607,7 @@ bool NormSlidingMask::Set(unsigned long index) return false; // out of range } ASSERT((pos >> 3) >= 0); - ASSERT((pos >> 3) < (long)mask_len); + ASSERT((pos >> 3) < (INT32)mask_len); mask[(pos >> 3)] |= (0x80 >> (pos & 0x07)); } else @@ -619,12 +619,12 @@ bool NormSlidingMask::Set(unsigned long index) return true; } // end NormSlidingMask::Set() -bool NormSlidingMask::Unset(unsigned long index) +bool NormSlidingMask::Unset(UINT32 index) { //ASSERT(CanSet(index)); if (IsSet()) { - long pos = Delta(index, offset); + INT32 pos = Delta(index, offset); if (pos < 0) { return true; // out-of-range @@ -645,7 +645,7 @@ bool NormSlidingMask::Unset(unsigned long index) // Yes, it was in range. // Unset the corresponding bit ASSERT((pos >> 3) >= 0); - ASSERT((pos >> 3) < (long)mask_len); + ASSERT((pos >> 3) < (INT32)mask_len); mask[(pos >> 3)] &= ~(0x80 >> (pos & 0x07)); if (start == end) { @@ -655,9 +655,9 @@ bool NormSlidingMask::Unset(unsigned long index) } if (start == pos) { - unsigned long next = index; + UINT32 next = index; if (!GetNextSet(next)) ASSERT(0); - long delta = Delta(next, offset); + INT32 delta = Delta(next, offset); ASSERT(delta >= 0); start += delta; if (start >= num_bits) start -= num_bits; @@ -665,9 +665,9 @@ bool NormSlidingMask::Unset(unsigned long index) } if (pos == end) { - unsigned long prev = index; + UINT32 prev = index; if (!GetPrevSet(prev)) ASSERT(0); - long delta = Delta(prev, offset); + INT32 delta = Delta(prev, offset); ASSERT(delta >= 0); end = start + delta; if (end >= num_bits) end -= num_bits; @@ -681,16 +681,16 @@ bool NormSlidingMask::Unset(unsigned long index) return true; } // end NormSlidingMask::Unset() -bool NormSlidingMask::SetBits(unsigned long index, long count) +bool NormSlidingMask::SetBits(UINT32 index, INT32 count) { ASSERT(CanSet(index)); ASSERT(CanSet(index+count-1)); if (count < 0) return false; if (0 == count) return true; - long firstPos, lastPos; + INT32 firstPos, lastPos; if (IsSet()) { - long last = index + count - 1; + INT32 last = index + count - 1; if (!CanSet(index)) return false; if (!CanSet(last)) return false; // Calculate first set bit position @@ -733,29 +733,29 @@ bool NormSlidingMask::SetBits(unsigned long index, long count) { // Set bits from firstPos to num_bits count = num_bits - firstPos; - long maskIndex = firstPos >> 3; + INT32 maskIndex = firstPos >> 3; int bitIndex = firstPos & 0x07; int bitRemainder = 8 - bitIndex; ASSERT(maskIndex >= 0); if (count <= bitRemainder) { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] |= (0x00ff >> bitIndex) & (0x00ff << (bitRemainder - count)); } else { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] |= 0x00ff >> bitIndex; count -= bitRemainder; - long nbytes = count >> 3; - ASSERT((maskIndex+1+nbytes) <= (long)mask_len); + INT32 nbytes = count >> 3; + ASSERT((maskIndex+1+nbytes) <= (INT32)mask_len); memset(&mask[++maskIndex], 0xff, nbytes); count &= 0x07; if (count) { ASSERT((maskIndex+nbytes) >= 0); - ASSERT((maskIndex+nbytes) < (long)mask_len); + ASSERT((maskIndex+nbytes) < (INT32)mask_len); mask[maskIndex+nbytes] |= 0xff << (8-count); } } @@ -766,51 +766,51 @@ bool NormSlidingMask::SetBits(unsigned long index, long count) { if (count > num_bits) return false; start = firstPos = 0; - end = lastPos = (long)(count - 1); + end = lastPos = (INT32)(count - 1); offset = index; } // Set bits from firstPos to lastPos count = lastPos - firstPos + 1; - long maskIndex = firstPos >> 3; + INT32 maskIndex = firstPos >> 3; int bitIndex = firstPos & 0x07; int bitRemainder = 8 - bitIndex; ASSERT(maskIndex >= 0); if (count <= bitRemainder) { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] |= (0x00ff >> bitIndex) & (0x00ff << (bitRemainder - count)); } else { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] |= 0x00ff >> bitIndex; count -= bitRemainder; - long nbytes = count >> 3; - ASSERT((maskIndex+1+nbytes) <= (long)mask_len); + INT32 nbytes = count >> 3; + ASSERT((maskIndex+1+nbytes) <= (INT32)mask_len); memset(&mask[++maskIndex], 0xff, nbytes); count &= 0x07; if (count) { ASSERT((maskIndex+nbytes) >= 0); - ASSERT((maskIndex+nbytes) < (long)mask_len); + ASSERT((maskIndex+nbytes) < (INT32)mask_len); mask[maskIndex+nbytes] |= 0xff << (8-count); } } return true; } // end NormSlidingMask::SetBits() -bool NormSlidingMask::UnsetBits(unsigned long index, long count) +bool NormSlidingMask::UnsetBits(UINT32 index, INT32 count) { //ASSERT(CanSet(index)); //ASSERT(CanSet(index+count-1)); if (IsSet()) { // Trim to fit as needed. - long firstPos; + INT32 firstPos; if (count <= 0) return true; if (count > num_bits) count = num_bits; - long delta = Delta(index , offset); + INT32 delta = Delta(index , offset); if (delta >= num_bits) { return true; @@ -829,7 +829,7 @@ bool NormSlidingMask::UnsetBits(unsigned long index, long count) UINT32 lastSet; if (!GetLastSet(lastSet)) ASSERT(0); delta = Delta((index+count-1), lastSet); - long lastPos; + INT32 lastPos; if (delta < 0) { lastPos = firstPos + count - 1; @@ -839,26 +839,26 @@ bool NormSlidingMask::UnsetBits(unsigned long index, long count) { lastPos = end; } - long startPos; + INT32 startPos; if (lastPos < firstPos) { // Set bits from firstPos to num_bits count = num_bits - firstPos; - long maskIndex = firstPos >> 3; + INT32 maskIndex = firstPos >> 3; int bitIndex = firstPos & 0x07; int bitRemainder = 8 - bitIndex; if (count <= bitRemainder) { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] &= (0x00ff << bitRemainder) | (0x00ff >> (bitIndex + count)); } else { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] &= 0x00ff << bitRemainder; count -= bitRemainder; - unsigned long nbytes = count >> 3; + UINT32 nbytes = count >> 3; ASSERT((maskIndex+1+nbytes) <= mask_len); memset(&mask[++maskIndex], 0, nbytes); count &= 0x07; @@ -876,21 +876,21 @@ bool NormSlidingMask::UnsetBits(unsigned long index, long count) } // Unset bits from firstPos to lastPos count = lastPos - startPos + 1; - long maskIndex = startPos >> 3; + INT32 maskIndex = startPos >> 3; int bitIndex = startPos & 0x07; int bitRemainder = 8 - bitIndex; if (count <= bitRemainder) { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] &= (0x00ff << bitRemainder) | (0x00ff >> (bitIndex + count)); } else { - ASSERT(maskIndex < (long)mask_len); + ASSERT(maskIndex < (INT32)mask_len); mask[maskIndex] &= 0x00ff << bitRemainder; count -= bitRemainder; - unsigned long nbytes = count >> 3; + UINT32 nbytes = count >> 3; ASSERT((maskIndex+1+nbytes) <= mask_len); memset(&mask[++maskIndex], 0, nbytes); count &= 0x07; @@ -922,11 +922,11 @@ bool NormSlidingMask::UnsetBits(unsigned long index, long count) return true; } // end NormSlidingMask::UnsetBits() -bool NormSlidingMask::Test(unsigned long index) const +bool NormSlidingMask::Test(UINT32 index) const { if (IsSet()) { - long pos = Delta(index , offset); + INT32 pos = Delta(index , offset); if (pos >= 0) { // Is it in range? @@ -950,12 +950,12 @@ bool NormSlidingMask::Test(unsigned long index) const } // end NormSlidingMask::Test() -bool NormSlidingMask::GetNextSet(unsigned long& index) const +bool NormSlidingMask::GetNextSet(UINT32& index) const { if (IsSet()) { - unsigned long next = index; - long pos = Delta(next, offset); + UINT32 next = index; + INT32 pos = Delta(next, offset); if (pos >= 0) { // Is it in range? @@ -972,7 +972,7 @@ bool NormSlidingMask::GetNextSet(unsigned long& index) const if ((pos < start) || (pos > end)) return false; } // Seek next set bit - unsigned long maskIndex = pos >> 3; + UINT32 maskIndex = pos >> 3; if (mask[maskIndex]) { int w = WEIGHT[mask[maskIndex]]; @@ -1006,7 +1006,7 @@ bool NormSlidingMask::GetNextSet(unsigned long& index) const } maskIndex = 0; } - unsigned long endIndex = end >> 3; + UINT32 endIndex = end >> 3; for (; maskIndex <= endIndex; maskIndex++) { if (mask[maskIndex]) @@ -1027,12 +1027,12 @@ bool NormSlidingMask::GetNextSet(unsigned long& index) const return false; // indicates nothing was set } // end NormSlidingMask::GetNextSet() -bool NormSlidingMask::GetPrevSet(unsigned long& index) const +bool NormSlidingMask::GetPrevSet(UINT32& index) const { if (IsSet()) { - unsigned long prev = index; - long pos = Delta(prev, offset); + UINT32 prev = index; + INT32 pos = Delta(prev, offset); if (pos >= 0) { // Is it in range? @@ -1051,7 +1051,7 @@ bool NormSlidingMask::GetPrevSet(unsigned long& index) const if ((pos < start) || (pos > end)) return false; } // Seek prev set bits, starting with index - long maskIndex = pos >> 3; + INT32 maskIndex = pos >> 3; if (mask[maskIndex]) { int w = WEIGHT[mask[maskIndex]] - 1; @@ -1087,7 +1087,7 @@ bool NormSlidingMask::GetPrevSet(unsigned long& index) const } maskIndex = mask_len - 1; } - long startIndex = start >> 3; + INT32 startIndex = start >> 3; for (; maskIndex >= startIndex; maskIndex--) { if (mask[maskIndex]) @@ -1105,10 +1105,10 @@ bool NormSlidingMask::GetPrevSet(unsigned long& index) const return false; // indicates nothing prior was set } // end NormSlidingMask::GetPrevSet() -/*unsigned long NormSlidingMask::RawNextSet(const char* mask, long index, long end) +/*UINT32 NormSlidingMask::RawNextSet(const char* mask, INT32 index, INT32 end) { // Seek next set bit - unsigned long maskIndex = index >> 3; + UINT32 maskIndex = index >> 3; if (mask[maskIndex]) { int w = WEIGHT[mask[maskIndex]]; @@ -1121,7 +1121,7 @@ bool NormSlidingMask::GetPrevSet(unsigned long& index) const } } maskIndex++; - unsigned long endIndex = end >> 3; + UINT32 endIndex = end >> 3; for (; maskIndex <= endIndex; maskIndex++) { if (mask[maskIndex]) @@ -1130,10 +1130,10 @@ bool NormSlidingMask::GetPrevSet(unsigned long& index) const return (index-1); // (nothing was set) } // end NormSlidingMask::RawNextSet() -unsigned long NormSlidingMask::RawPrevSet(const char* mask, long index, long start) +UINT32 NormSlidingMask::RawPrevSet(const char* mask, INT32 index, INT32 start) { // Seek prev set bits, starting with index - unsigned long maskIndex = index >> 3; + UINT32 maskIndex = index >> 3; if (mask[maskIndex]) { int w = WEIGHT[mask[maskIndex]] - 1; @@ -1148,7 +1148,7 @@ unsigned long NormSlidingMask::RawPrevSet(const char* mask, long index, long sta } } maskIndex--; - unsigned long startIndex = start >> 3; + UINT32 startIndex = start >> 3; for (; maskIndex >= startIndex; maskIndex--) { if (mask[maskIndex]) @@ -1164,7 +1164,7 @@ bool NormSlidingMask::Copy(const NormSlidingMask& b) { if (b.IsSet()) { - long range = b.end - b.start; + INT32 range = b.end - b.start; if (range < 0) range += b.num_bits; if (range <= num_bits) { @@ -1176,8 +1176,8 @@ bool NormSlidingMask::Copy(const NormSlidingMask& b) end = bLastSet - bFirstSet + start; offset = b.offset; // Copy start to mask_len - long startIndex = b.start >> 3; - long endIndex = b.end >> 3; + INT32 startIndex = b.start >> 3; + INT32 endIndex = b.end >> 3; if (b.end < b.start) { ASSERT((b.mask_len - startIndex) <= mask_len); @@ -1193,14 +1193,14 @@ bool NormSlidingMask::Copy(const NormSlidingMask& b) remainder = end & 0x7; if (remainder) { - ASSERT((startIndex+endIndex) < (long)mask_len); + ASSERT((startIndex+endIndex) < (INT32)mask_len); mask[startIndex+endIndex] &= 0xff << (8 - remainder); } } } else { - ASSERT((endIndex-startIndex+1) <= (long)mask_len); + ASSERT((endIndex-startIndex+1) <= (INT32)mask_len); memcpy(mask, b.mask+startIndex, endIndex-startIndex+1); } return true; @@ -1230,11 +1230,11 @@ bool NormSlidingMask::Add(const NormSlidingMask& b) UINT32 bLastSet; b.GetFirstSet(bLastSet); if (!CanSet(bLastSet)) return false; - long range = b.end - b.start; + INT32 range = b.end - b.start; if (range < 0) range += b.num_bits; - unsigned long index; + UINT32 index; b.GetFirstSet(index); - for (long i = 0; i < range; i++) + for (INT32 i = 0; i < range; i++) { // (TBD) Improve performance by getting/setting // ranges of set bits. @@ -1259,10 +1259,10 @@ bool NormSlidingMask::Subtract(const NormSlidingMask& b) { if (IsSet()) { - unsigned long index = offset; - long range = end - start; + UINT32 index = offset; + INT32 range = end - start; if (range < 0) range += num_bits; - for (long i = 0; i < range; i++) + for (INT32 i = 0; i < range; i++) { if (Test(index) && b.Test(index)) Unset(index); index++; @@ -1286,11 +1286,11 @@ bool NormSlidingMask::XCopy(const NormSlidingMask& b) UINT32 bLastSet; b.GetFirstSet(bLastSet); if (!CanSet(bLastSet)) return false; - unsigned long index; + UINT32 index; b.GetFirstSet(index); - long range = b.end - b.start; + INT32 range = b.end - b.start; if (range < 0) range += b.num_bits; - for (long i = 0; i < range; i++) + for (INT32 i = 0; i < range; i++) { if (Test(index)) Unset(index); @@ -1318,10 +1318,10 @@ bool NormSlidingMask::Multiply(const NormSlidingMask& b) { if (IsSet()) { - unsigned long index = offset; - long range = end - start; + UINT32 index = offset; + INT32 range = end - start; if (range < 0) range += num_bits; - for (long i = 0; i < range; i++) + for (INT32 i = 0; i < range; i++) { if (Test(index) && !b.Test(index)) Unset(index); index++; @@ -1347,11 +1347,11 @@ bool NormSlidingMask::Xor(const NormSlidingMask& b) UINT32 bLastSet; b.GetFirstSet(bLastSet); if (!CanSet(bLastSet)) return false; - unsigned long index; + UINT32 index; b.GetFirstSet(index); - long range = b.end - b.start; + INT32 range = b.end - b.start; if (range < 0) range += b.num_bits; - for (long i = 0; i < range; i++) + for (INT32 i = 0; i < range; i++) { if (b.Test(index)) Invert(index); index++; @@ -1362,8 +1362,8 @@ bool NormSlidingMask::Xor(const NormSlidingMask& b) void NormSlidingMask::Display(FILE* stream) { - unsigned long index = offset; - for (long i = 0; i < num_bits; i++) + UINT32 index = offset; + for (INT32 i = 0; i < num_bits; i++) { if (Test(index++)) fprintf(stream, "1"); else fprintf(stream, "0"); if (0x07 == (i & 0x07)) fprintf(stream, " "); @@ -1371,12 +1371,12 @@ void NormSlidingMask::Display(FILE* stream) } } // end NormSlidingMask::Display() -void NormSlidingMask::Debug(long theCount) +void NormSlidingMask::Debug(INT32 theCount) { - unsigned long index = offset; + UINT32 index = offset; theCount = MIN(theCount, num_bits); DMSG(0, "NormSlidingMask::Debug() offset:%lu\n ", index); - long i; + INT32 i; for (i = 0; i < theCount; i++) { if (Test(index++)) DMSG(0, "1"); else DMSG(0, "0"); diff --git a/common/normBitmask.h b/common/normBitmask.h index a5351f4..0f0650d 100644 --- a/common/normBitmask.h +++ b/common/normBitmask.h @@ -21,9 +21,9 @@ class NormBitmask NormBitmask(); ~NormBitmask(); - bool Init(unsigned long numBits); + bool Init(UINT32 numBits); void Destroy(); - unsigned long Size() {return num_bits;} + UINT32 Size() {return num_bits;} void Clear() // set to all zero's { memset(mask, 0, mask_len); @@ -37,27 +37,27 @@ class NormBitmask } bool IsSet() const {return (first_set < num_bits);} - bool GetFirstSet(unsigned long& index) const + bool GetFirstSet(UINT32& index) const { index = first_set; return IsSet(); } - bool GetLastSet(unsigned long& index) const + bool GetLastSet(UINT32& index) const { index = num_bits - 1; return GetPrevSet(index); } - bool Test(unsigned long index) const + bool Test(UINT32 index) const { return ((index < num_bits) ? (0 != (mask[(index >> 3)] & (0x80 >> (index & 0x07)))) : false); } - bool CanSet(unsigned long index) const + bool CanSet(UINT32 index) const {return (index < num_bits);} - bool Set(unsigned long index) + bool Set(UINT32 index) { if (index < num_bits) { @@ -70,7 +70,7 @@ class NormBitmask return false; } } - bool Unset(unsigned long index) + bool Unset(UINT32 index) { if (index < num_bits) { @@ -79,15 +79,15 @@ class NormBitmask } return true; } - bool Invert(unsigned long index) + bool Invert(UINT32 index) {return (Test(index) ? Unset(index) : Set(index));} - bool SetBits(unsigned long baseIndex, unsigned long count); - bool UnsetBits(unsigned long baseIndex, unsigned long count); + bool SetBits(UINT32 baseIndex, UINT32 count); + bool UnsetBits(UINT32 baseIndex, UINT32 count); - bool GetNextSet(unsigned long& index) const; - bool GetPrevSet(unsigned long& index) const; - bool GetNextUnset(unsigned long& index) const; + bool GetNextSet(UINT32& index) const; + bool GetPrevSet(UINT32& index) const; + bool GetNextUnset(UINT32& index) const; bool Copy(const NormBitmask &b); // this = b bool Add(const NormBitmask & b); // this = this | b @@ -101,9 +101,9 @@ class NormBitmask // Members private: unsigned char* mask; - unsigned long mask_len; - unsigned long num_bits; - unsigned long first_set; // index of lowest _set_ bit + UINT32 mask_len; + UINT32 num_bits; + UINT32 first_set; // index of lowest _set_ bit }; // end class NormBitmask @@ -125,16 +125,16 @@ class NormSlidingMask const char* GetMask() const {return (const char*)mask;} - bool Init(long numBits, UINT32 rangeMax); + bool Init(INT32 numBits, UINT32 rangeMax); void Destroy(); - long Size() const {return num_bits;} + INT32 Size() const {return num_bits;} void Clear() { memset(mask, 0, mask_len); start = end = num_bits; offset = 0; } - void Reset(unsigned long index = 0) + void Reset(UINT32 index = 0) { ASSERT(num_bits); memset(mask, 0xff, mask_len); @@ -144,38 +144,34 @@ class NormSlidingMask offset = index; } bool IsSet() const {return (start < num_bits);} - bool GetFirstSet(unsigned long& index) const + bool GetFirstSet(UINT32& index) const { index = offset; return IsSet(); } - bool GetLastSet(unsigned long& index) const + bool GetLastSet(UINT32& index) const { - long n = end - start; + INT32 n = end - start; n = (n < 0) ? (n + num_bits) : n; index = offset + n; return IsSet(); } - bool Test(unsigned long index) const; - bool CanSet(unsigned long index) const; + bool Test(UINT32 index) const; + bool CanSet(UINT32 index) const; - bool Set(unsigned long index); - bool Unset(unsigned long index); - bool Invert(unsigned long index) + bool Set(UINT32 index); + bool Unset(UINT32 index); + bool Invert(UINT32 index) {return (Test(index) ? Unset(index): Set(index));} - bool SetBits(unsigned long index, long count); - bool UnsetBits(unsigned long index, long count); + bool SetBits(UINT32 index, INT32 count); + bool UnsetBits(UINT32 index, INT32 count); // These return "false" when finding nothing - bool GetNextSet(unsigned long& index) const; - bool GetPrevSet(unsigned long& index) const; - - //static unsigned long RawNextSet(const char* mask, long index, long start); - //static unsigned long RawPrevSet(const char* mask, long index, long end); - + bool GetNextSet(UINT32& index) const; + bool GetPrevSet(UINT32& index) const; bool Copy(const NormSlidingMask& b); // this = b bool Add(const NormSlidingMask & b); // this = this | b @@ -185,13 +181,13 @@ class NormSlidingMask bool Xor(const NormSlidingMask & b); // this = this ^ b void Display(FILE* stream); - void Debug(long theCount); + void Debug(INT32 theCount); private: // Calculate "circular" delta between two indices - long Delta(unsigned long a, unsigned long b) const + INT32 Delta(UINT32 a, UINT32 b) const { - long result = a - b; + INT32 result = a - b; return ((0 == (result & range_sign)) ? (result & range_mask) : (((result != range_sign) || (a < b)) ? @@ -200,13 +196,13 @@ class NormSlidingMask unsigned char* mask; - unsigned long mask_len; - unsigned long range_mask; - long range_sign; - long num_bits; - long start; - long end; - unsigned long offset; + UINT32 mask_len; + UINT32 range_mask; + INT32 range_sign; + INT32 num_bits; + INT32 start; + INT32 end; + UINT32 offset; }; // end class NormSlidingMask #endif // _NORM_BITMASK_ diff --git a/common/normObject.cpp b/common/normObject.cpp index 9357588..dcd5f40 100644 --- a/common/normObject.cpp +++ b/common/normObject.cpp @@ -1601,7 +1601,7 @@ bool NormFileObject::WriteSegment(NormBlockId blockId, segmentOffset = segmentOffset + small_block_length*smallBlockIndex + segmentSize*segmentId; } - off_t offsetScaleMSB = 0xffffffff + 1; + off_t offsetScaleMSB = 0xffffffff + 1; // yuk! can't we do better? off_t offset = (off_t)segmentOffset.LSB() + ((off_t)segmentOffset.MSB() * offsetScaleMSB); if (offset != file.GetOffset()) { @@ -1644,7 +1644,7 @@ UINT16 NormFileObject::ReadSegment(NormBlockId blockId, segmentOffset = segmentOffset + small_block_length*smallBlockIndex + segmentSize*segmentId; } - off_t offsetScaleMSB = 0xffffffff + 1; + off_t offsetScaleMSB = 0xffffffff + 1; // yuk! can't we do better off_t offset = (off_t)segmentOffset.LSB() + ((off_t)segmentOffset.MSB() * offsetScaleMSB); if (offset != file.GetOffset()) { @@ -1674,7 +1674,7 @@ NormStreamObject::~NormStreamObject() Close(); } -bool NormStreamObject::Open(unsigned long bufferSize, +bool NormStreamObject::Open(UINT32 bufferSize, const char* infoPtr, UINT16 infoLen) { @@ -1701,7 +1701,7 @@ bool NormStreamObject::Open(unsigned long bufferSize, ASSERT(0 == numBlocks.MSB()); // Buffering requires at least 2 blocks numBlocks = MAX(2, numBlocks.LSB()); - unsigned long numSegments = numBlocks.LSB() * numData; + UINT32 numSegments = numBlocks.LSB() * numData; if (!block_pool.Init(numBlocks.LSB(), numData)) { @@ -1742,7 +1742,7 @@ bool NormStreamObject::Open(unsigned long bufferSize, return true; } // end NormStreamObject::Open() -bool NormStreamObject::Accept(unsigned long bufferSize) +bool NormStreamObject::Accept(UINT32 bufferSize) { if (Open(bufferSize)) { @@ -2168,10 +2168,10 @@ bool NormStreamObject::Read(char* buffer, unsigned int* buflen, bool findMsgStar return true; } // end NormStreamObject::Read() -unsigned long NormStreamObject::Write(const char* buffer, unsigned long len, +UINT32 NormStreamObject::Write(const char* buffer, UINT32 len, FlushType flushType, bool eom, bool push) { - unsigned long nBytes = 0; + UINT32 nBytes = 0; do { NormBlock* block = stream_buffer.Find(write_index.block); diff --git a/common/normObject.h b/common/normObject.h index fda8d83..9b71d2f 100644 --- a/common/normObject.h +++ b/common/normObject.h @@ -72,28 +72,28 @@ class NormObject bool IsPendingInfo() {return pending_info;} bool GetFirstPending(NormBlockId& blockId) const { - unsigned long index = 0; + UINT32 index = 0; bool result = pending_mask.GetFirstSet(index); blockId = NormBlockId(index); return result; } bool GetNextPending(NormBlockId& blockId) const { - unsigned long index = (UINT32)blockId; + UINT32 index = (UINT32)blockId; bool result = pending_mask.GetNextSet(index); blockId = NormBlockId(index); return result; } bool GetLastPending(NormBlockId& blockId) const { - unsigned long index = 0; + UINT32 index = 0; bool result = pending_mask.GetLastSet(index); blockId = NormBlockId(index); return result; } bool GetFirstRepair(NormBlockId& blockId) const { - unsigned long index = 0; + UINT32 index = 0; bool result = repair_mask.GetFirstSet(index); blockId = NormBlockId(index); return result; @@ -101,14 +101,14 @@ class NormObject bool GetNextRepair(NormBlockId& blockId) const { - unsigned long index = (UINT32)blockId; + UINT32 index = (UINT32)blockId; bool result = repair_mask.GetNextSet(index); blockId = NormBlockId(index); return result; } bool GetLastRepair(NormBlockId& blockId) const { - unsigned long index = 0; + UINT32 index = 0; bool result = repair_mask.GetLastSet(index); blockId = NormBlockId(index); return result; @@ -263,11 +263,11 @@ class NormStreamObject : public NormObject const NormObjectId& objectId); ~NormStreamObject(); - bool Open(unsigned long bufferSize, + bool Open(UINT32 bufferSize, const char* infoPtr = NULL, UINT16 infoLen = 0); void Close(); - bool Accept(unsigned long bufferSize); + bool Accept(UINT32 bufferSize); enum FlushType { @@ -276,7 +276,7 @@ class NormStreamObject : public NormObject FLUSH_ACTIVE // pending queued data is transmitted, _and_ active CMD(FLUSH) }; bool Read(char* buffer, unsigned int* buflen, bool findMsgStart = false); - unsigned long Write(const char* buffer, unsigned long len, FlushType flushType, bool eom, bool push); + UINT32 Write(const char* buffer, UINT32 len, FlushType flushType, bool eom, bool push); bool StreamUpdateStatus(NormBlockId blockId); @@ -343,7 +343,7 @@ class NormSimObject : public NormObject const NormObjectId& objectId); ~NormSimObject(); - bool Open(unsigned long objectSize, + bool Open(UINT32 objectSize, const char* infoPtr = NULL, UINT16 infoLen = 0) { @@ -382,7 +382,7 @@ class NormObjectTable NormObjectId RangeLo() const {return range_lo;} NormObjectId RangeHi() const {return range_hi;} bool IsEmpty() const {return (0 == range);} - unsigned long Count() const {return count;} + UINT32 Count() const {return count;} const NormObjectSize& Size() const {return size;} class Iterator diff --git a/common/normSession.cpp b/common/normSession.cpp index 66d9d27..0c51fd8 100644 --- a/common/normSession.cpp +++ b/common/normSession.cpp @@ -83,7 +83,7 @@ NormSession::~NormSession() } -bool NormSession::Open() +bool NormSession::Open(const char* interfaceName) { ASSERT(address.IsValid()); if (!tx_socket.IsOpen()) @@ -106,7 +106,7 @@ bool NormSession::Open() if (address.IsMulticast()) { - if (!rx_socket.JoinGroup(address)) + if (!rx_socket.JoinGroup(address, interfaceName)) { DMSG(0, "NormSession::Open() rx_socket join group error\n"); Close(); @@ -118,6 +118,11 @@ bool NormSession::Open() Close(); return false; } + if (interfaceName) + { + rx_socket.SetMulticastInterface(interfaceName); + tx_socket.SetMulticastInterface(interfaceName); + } } for (unsigned int i = 0; i < DEFAULT_MESSAGE_POOL_DEPTH; i++) { @@ -158,11 +163,12 @@ void NormSession::Close() bool NormSession::StartServer(unsigned long bufferSpace, UINT16 segmentSize, UINT16 numData, - UINT16 numParity) + UINT16 numParity, + const char* interfaceName) { if (!IsOpen()) { - if (!Open()) return false; + if (!Open(interfaceName)) return false; } // (TBD) parameterize the object history depth if (!tx_table.Init(256)) @@ -255,11 +261,11 @@ void NormSession::StopServer() if (!IsClient()) Close(); } // end NormSession::StopServer() -bool NormSession::StartClient(unsigned long bufferSize) +bool NormSession::StartClient(unsigned long bufferSize, const char* interfaceName) { if (!IsOpen()) { - if (!Open()) return false; + if (!Open(interfaceName)) return false; } is_client = true; remote_server_buffer_size = bufferSize; @@ -921,10 +927,6 @@ void NormSession::HandleReceiveMessage(NormMsg& msg, bool wasUnicast) } } if (IsClient()) ClientHandleNackMessage((NormNackMsg&)msg); - if ((3 == LocalNodeId()) && (currentTime.tv_sec > 26)) - { - int x = 5; - } break; case NormMsg::ACK: if (IsServer() && (((NormAckMsg&)msg).GetServerId() == LocalNodeId())) diff --git a/common/normSession.h b/common/normSession.h index 0fc9726..ac9d866 100644 --- a/common/normSession.h +++ b/common/normSession.h @@ -41,8 +41,7 @@ class NormSessionMgr class NormSession* NewSession(const char* sessionAddress, UINT16 sessionPort, - NormNodeId localNodeId = - NORM_NODE_ANY); + NormNodeId localNodeId = NORM_NODE_ANY); void DeleteSession(class NormSession* theSession); void Notify(NormController::Event event, @@ -88,7 +87,7 @@ class NormSession // General methods const NormNodeId& LocalNodeId() {return local_node_id;} - bool Open(); + bool Open(const char* interfaceName = NULL); void Close(); bool IsOpen() {return (rx_socket.IsOpen() || tx_socket.IsOpen());} const ProtoAddress& Address() {return address;} @@ -134,7 +133,8 @@ class NormSession bool StartServer(unsigned long bufferSpace, UINT16 segmentSize, UINT16 numData, - UINT16 numParity); + UINT16 numParity, + const char* interfaceName = NULL); void StopServer(); NormStreamObject* QueueTxStream(UINT32 bufferSize, const char* infoPtr = NULL, @@ -210,7 +210,8 @@ class NormSession } // Client methods - bool StartClient(unsigned long bufferSpace); + bool StartClient(unsigned long bufferSpace, + const char* interfaceName = NULL); void StopClient(); bool IsClient() {return is_client;} unsigned long RemoteServerBufferSize() @@ -293,7 +294,7 @@ class NormSession // General session parameters NormNodeId local_node_id; - ProtoAddress address; // session destination address + ProtoAddress address; // session destination address & port UINT8 ttl; // session multicast ttl double tx_rate; // bytes per second double backoff_factor; diff --git a/common/normVersion.h b/common/normVersion.h index 57e6ad6..ff49c60 100644 --- a/common/normVersion.h +++ b/common/normVersion.h @@ -32,6 +32,6 @@ #ifndef _NORM_VERSION #define _NORM_VERSION -#define VERSION "1.1b9" +#define VERSION "1.2b1" #endif // _NORM_VERSION diff --git a/win32/Norm.opt b/win32/Norm.opt index 055447b..8b3b48e 100644 Binary files a/win32/Norm.opt and b/win32/Norm.opt differ diff --git a/win32/norm/norm.dsp b/win32/norm/norm.dsp index ed644d7..245a5b5 100644 --- a/win32/norm/norm.dsp +++ b/win32/norm/norm.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /vmg /GX /O2 /I "..\..\common" /I "..\..\protolib\common" /I "..\..\protolib\win32" /D "NDEBUG" /D "PROTO_DEBUG" /D "HAVE_IPV6" /D "HAVE_ASSERT" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /vmg /GX /O2 /I "..\..\common" /I "..\..\protolib\common" /I "..\..\protolib\win32" /D "NDEBUG" /D "PROTO_DEBUG" /D "HAVE_IPV6" /D "HAVE_ASSERT" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG"