Sanko Robinson > Net-BitTorrent-0.052 > 003-threads.pl

Download:
Net-BitTorrent-0.052.tar.gz

Annotate this POD

Website

View/Report Bugs
Source  

NAME ^

003-threads.pl - Trivial Demonstration of a Multi-threaded Client

Description ^

This is a demonstration of Net::BitTorrent can be used in a thre-- ((sigh)) ya know, if you really want to try this, I can't stop you, but don't bug me if mixing threads and Net::BitTorrent turns your RAM into dark matter or causes you to foam at the mouth.

Synopsis ^

 000-basic.pl

Lowdown ^

This section only makes sense when you view the source.

Line 5-6

When Net::BitTorrent sees that threads::shared has been used, it tries its best to keep things organized. There is a limited subset of data that's actually shared between threads; just enough to be of some use but not enough to let you ruin everything.

Line 10

Creates a new thread. And this is where your sanity ends.

Line 12

Just a short delay to make it obvious that we're in the child.

Line 13-14

Sets callbacks to make it obvious that the data is being hashchecked.

Line 15

Steps aside for a moment.

Line 16

Validates data. As this starts, connections to peers related to this torrent in the parent thread are closed. While the child does the checking, our bitfield is kept in sync with the parent (thanks to threads::shared), and our status goes through some changes.

Line 17

Child says goodbye now that (s)he is finished.

Line 20

Works until we're finished downloading everything. Net::BitTorrent will continue to seed the torrent after download is complete.

Bugs/Notes/Warnings ^

Unless someone sends me a few good patches (hint, hint) threads will probably never be completely supported by Net::BitTorrent but there are a few things you can do with them.

Note: The data shared between threads is undocumented and subject to change.

Author ^

Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/

CPAN ID: SANKO

License and Legal ^

Copyright (C) 2008-2009 by Sanko Robinson <sanko@cpan.org>

This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the LICENSE file included with this distribution or http://www.perlfoundation.org/artistic_license_2_0. For clarification, see http://www.perlfoundation.org/artistic_2_0_notes.

When separated from the distribution, all POD documentation is covered by the Creative Commons Attribution-Share Alike 3.0 License. See http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification, see http://creativecommons.org/licenses/by-sa/3.0/us/.

Neither this module nor the Author is affiliated with BitTorrent, Inc.

syntax highlighting: