StreamMachine/StreamMachine — pull request #18 by bricker (2014-03-29 01:49:48+00:00)
Title: Fix multiple sources active at the same time.

If two sources connect at the same time (or very close together),
both of them will be considered "active". While one source is
waiting for vitals, the other may come along and do the same.
Once each of them receive vitals, they each get activated,
which results in a looping stream (every ~0.5 seconds is replayed).

This commit fixes this race condition by ensuring that once vitals
are received, the source we're replacing is still the same as it was
before vitals were received (stored in old_source). If it's not the
same, then it assumes that another source was made active in the
meantime and stops, with a log message.

I know this PR sucks to look at, but the important part is at the top of
the vitals callback — the rest is just indentation.