Thursday, June 29, 2006

TorrentService and TorrentPatron

The MainLine BitTorrent client is unfortunately not thread-safe, even segfaulting in some versions if you try to run two instances simultaenously. In any case, several BitTorrent clients would likely be less efficient than one controlling several downloads/uploads. To work around this problem, I've made it so a single TorrentClient (TC) can be shared between several components. TorrentPatron (TP) should now be used in place of TC in all user code. TP is completely compatible with TC's input/output IPC messages but any number of TPs can be created without things breaking.

When a TP spawns, it checks whether a TS exists. If it doesn't find one, it creates a new one. Either way it then registers with the TS to use the 'service' that TS provides. This then allows TP to relay requests to TC through TS and receive them from TC through TS in turn. TS co-ordinates how the TPs are 'multiplexed' to safely use TC together.

Labels: ,

0 Comments:

Post a Comment

<< Home