Hello everyone.
I’m tackling the lack of documentation of some class and instance methods.
Here is the sendClumpedBundles
instance method of the NetAddr
class.
sendClumpedBundles { arg time ... args;
if(args.bundleSize > 65535) {// udp max size.
args.clumpBundles.do { |item|
if(time.notNil) { time = time + 1e-9 }; // make it a nanosecond later
this.sendBundle(time, *item)
};
} {
this.sendBundle(time, *args)
}
}
It seems that the “true” block of the if statement is unreachable.
Indeed, the bundleSize method returns an error when the bundle size is greater than 65535:
([["/s_new", "default", -1, "freq", 440], ["/s_new", "default", -1, "freq", 220]]!682).bundleSize; // returns 65488
([["/s_new", "default", -1, "freq", 440], ["/s_new", "default", -1, "freq", 220]]!683).bundleSize; // returns ERROR: Primitive '_NetAddr_BundleSize' failed. caught exception 'buffer overflow' in primitive in method ArrayedCollection:prBundleSize
In the same class, there is another instance method doing something similar, using 20000 instead of 65535 in the test condition:
if(bundles.bundleSize > 20000/*65515*/) { // 65515 = 65535 - 16 - 4 (sync msg size)
bundles.clumpBundles.do { |item|
id = this.makeSyncResponder(condition);
this.sendBundle(latency, *(item ++ [["/sync", id]]));
if(latency.notNil) { latency = latency + 1e-9 };
condition.wait;
}
}
Is the implementation of sendClumpedBundles
correct?
I preferred opening a topic before a bug because I’m not sure if my analysis is correct.
Thanks!
Matthieu