sidorares / dbus-native

D-bus protocol client and server for node.js written in native javascript
Other
261 stars 93 forks source link

[Question] - Shouldn't the `serial` be incremented in `bus.sendSignal()`? #126

Open nschoe opened 8 years ago

nschoe commented 8 years ago

I was scouting through the code and found this: in the functoin bus.sendSignal(), the signalMsg gets a field serial, like all other DBus messages, but usually, as seen here the serial is incremented.

So shouldn't it be incremented here? I do see that for the signal, as it doesn't expect a return, it doesn't store a callback handler with the serial being the key, but I'm wondering if this can still cause some problems with the daemon: suppose I send a DBus signal with serial 1089, the DBus dameon sees an incoming message to transmit to interested peers, with serial = 1089, what if I then send another message (not a signal), maybe a method call, it will have serial = 1089 too, is it a problem?


As a side question: is it mandatory that serials start at 1 and increment? Can they be random? In which case, maybe we could use a library like shortid or equivalent that generates a random serial each time, this ways we would not have to think about incrementing it.

sidorares commented 8 years ago

So shouldn't it be incremented here?

Need to double check, probably yes. Serials are important when you receive response and signals usually don't get reply

As a side question: is it mandatory that serials start at 1 and increment? Can they be random?

Yes, I think they can be arbitrary. To me it's easier to increment rather than worry about random numbers collisions ( also easier to debug - which one went out before which )