Alo Sarv
lead developer

Donate via

Latest Builds

version 0.3
tar.gz tar.bz2
Boost 1.33.1 Headers
MLDonkey Downloads Import Module Development
Payment completed
Development in progress.
Developer's Diary

Monday, November 14, 2005

Some more bits and pieces

11 hours of coding session, but the list of improvements is bit shorter today. Thing is, I lost like 3 hours trying to introduce an EventTable template specialization for shared_ptr-ptrs, but couldn't get it working properly. The original problem was that I realized that shared_ptr-contained objects that used event tables (such as hash-work objects) were never actually deleted, since EventTable engine stores a copy of the pointer internally (which is OK for raw pointers, but not OK for smart pointers). So this means we leaked roughly 32kb memory for each hash job (32kb io buffers which were supposed to be cleaned when the object was destroyed). It didn't show up too much in ed2k, altough enough to raise some eyebrows (if you downloaded a lot and fast, you noticed the leak). However, in BT, where there are thousands of chunks, this became a problem very fast.

Anyway, the idea was to use a rather clever construct - EventTable template class specialization, which is itself derived from the main EventTable class template, and overrides handleEvents virtual function. Great in theory, but practice turned out to be more complicated, since we still need some way for lookups in there, and Boost smart pointers are REALLY annoying for that thing - their operator<, which makes these smart pointers a nightmare when you need to do lookups on objects based on their pointer value (which is the case there). I tried to work around it by overriding the containers comparison predicate, but ran into further problems - namely, we need to store the pointers in there as weak_ptr, since only weak_ptr can implicitly be constructed from shared_ptr (raw pointers can't, which would mean I'd have to duplicate most of the code in the specialization - something I set out to avoid in the first place with the inheritance). However, weak_ptr can only be casted back to shared_ptr via explicit shared_ptr constructor call (which, can throw as well), and even IF all goes right, we still have the problem - if we have two weak_ptrs (in which case the comparison-value would be 0), we break std::map unique-key rule. *duh*.

Other than that, today's changelog is as follows:
Those that have forgotten, AutoStartTorrents configuration setting tells BT plugin to automatically start downloading torrents that were downloaded by other modules. So with this setting turned on, if you download a .torrent from ed2k, or via http, or any other means, BT plugin will start downloading it. It doesn't affect normal shared .torrent files - it only triggers when a download is completed, and filename ends with ".torrent". Hence, it's possible to type "do http://some.url/blah.torrent", and it first downloads the blah.torrent file using HTTP module, and then starts the torrent download using BT module.

Madcat, ZzZz

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?