[bittorrent] Interactive client design

Ryan Walklin ryanwalklin at gmail.com
Sun Apr 1 10:03:12 EDT 2007


Hi All,

I'm currently beginning a Mac Bittorrent client based on the libbt engine (
libbt.sourceforge.net), and had a high-level design question I'd appreciate
some comment on.

I'm basing the logic for the application on the btget sample code included
with the library, which runs by accepting torrents from the command line,
parsing out the metadata, setting up a context to store the application's
state, contacting the trackers etc, all the usual stuff, then hands control
to an infinite loop which cycles through incoming and outgoing socket
requests and processes them. This loop runs until interrupted by a Ctrl-C,
then the program runs some cleanup code and exits.

This approach works really well for a non-interactive client, where you set
it up with some torrents and leave it alone, but not so well for an
interactive GUI client which will need to interrupt the socket processing to
add and remove torrents, change filesets, transfer rates etc. From my own
reading the obvious answer would be to hand the network code off to another
thread, so that the GUI is not blocked. However, this is far from simple for
me to implement, as I have no prior thread experience, and can see that it
would be easy to create a non-thread-safe condition if both the network
thread and GUI were accessing the thread at once.

I would appreciate it if anyone could suggest an alternate approach which
avoided threads, or some guidance as to how to avoid non-thread-safe code if
threads are the best solution.

The project is available at niagara.sourceforge.net.

Kind Regards,

Ryan Walklin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ibiblio.org/pipermail/bittorrent/attachments/20070401/237c1212/attachment.html 


More information about the BitTorrent mailing list