separated session from session_impl and made a real pimpl-class of it. Introduced the possibility to destruct the sessions async.

This commit is contained in:
Arvid Norberg 2006-10-11 14:02:21 +00:00
parent 8346841d35
commit f0519e86e8
24 changed files with 1215 additions and 822 deletions

View File

@ -29,137 +29,138 @@
<li><a class="reference" href="#session" id="id17" name="id17">session</a><ul>
<li><a class="reference" href="#id1" id="id18" name="id18">session()</a></li>
<li><a class="reference" href="#id2" id="id19" name="id19">~session()</a></li>
<li><a class="reference" href="#add-torrent" id="id20" name="id20">add_torrent()</a></li>
<li><a class="reference" href="#remove-torrent" id="id21" name="id21">remove_torrent()</a></li>
<li><a class="reference" href="#disable-extensions-enable-extension" id="id22" name="id22">disable_extensions() enable_extension()</a></li>
<li><a class="reference" href="#set-upload-rate-limit-set-download-rate-limit" id="id23" name="id23">set_upload_rate_limit() set_download_rate_limit()</a></li>
<li><a class="reference" href="#set-max-uploads-set-max-connections" id="id24" name="id24">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#set-max-half-open-connections" id="id25" name="id25">set_max_half_open_connections()</a></li>
<li><a class="reference" href="#set-ip-filter" id="id26" name="id26">set_ip_filter()</a></li>
<li><a class="reference" href="#status" id="id27" name="id27">status()</a></li>
<li><a class="reference" href="#is-listening-listen-port-listen-on" id="id28" name="id28">is_listening() listen_port() listen_on()</a></li>
<li><a class="reference" href="#pop-alert-set-severity-level" id="id29" name="id29">pop_alert() set_severity_level()</a></li>
<li><a class="reference" href="#start-dht-stop-dht-set-dht-settings-dht-state" id="id30" name="id30">start_dht() stop_dht() set_dht_settings() dht_state()</a></li>
<li><a class="reference" href="#add-dht-node-add-dht-router" id="id31" name="id31">add_dht_node() add_dht_router()</a></li>
<li><a class="reference" href="#abort" id="id20" name="id20">abort()</a></li>
<li><a class="reference" href="#add-torrent" id="id21" name="id21">add_torrent()</a></li>
<li><a class="reference" href="#remove-torrent" id="id22" name="id22">remove_torrent()</a></li>
<li><a class="reference" href="#disable-extensions-enable-extension" id="id23" name="id23">disable_extensions() enable_extension()</a></li>
<li><a class="reference" href="#set-upload-rate-limit-set-download-rate-limit" id="id24" name="id24">set_upload_rate_limit() set_download_rate_limit()</a></li>
<li><a class="reference" href="#set-max-uploads-set-max-connections" id="id25" name="id25">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#set-max-half-open-connections" id="id26" name="id26">set_max_half_open_connections()</a></li>
<li><a class="reference" href="#set-ip-filter" id="id27" name="id27">set_ip_filter()</a></li>
<li><a class="reference" href="#status" id="id28" name="id28">status()</a></li>
<li><a class="reference" href="#is-listening-listen-port-listen-on" id="id29" name="id29">is_listening() listen_port() listen_on()</a></li>
<li><a class="reference" href="#pop-alert-set-severity-level" id="id30" name="id30">pop_alert() set_severity_level()</a></li>
<li><a class="reference" href="#start-dht-stop-dht-set-dht-settings-dht-state" id="id31" name="id31">start_dht() stop_dht() set_dht_settings() dht_state()</a></li>
<li><a class="reference" href="#add-dht-node-add-dht-router" id="id32" name="id32">add_dht_node() add_dht_router()</a></li>
</ul>
</li>
<li><a class="reference" href="#entry" id="id32" name="id32">entry</a><ul>
<li><a class="reference" href="#integer-string-list-dict-type" id="id33" name="id33">integer() string() list() dict() type()</a></li>
<li><a class="reference" href="#operator" id="id34" name="id34">operator[]</a></li>
<li><a class="reference" href="#find-key" id="id35" name="id35">find_key()</a></li>
<li><a class="reference" href="#entry" id="id33" name="id33">entry</a><ul>
<li><a class="reference" href="#integer-string-list-dict-type" id="id34" name="id34">integer() string() list() dict() type()</a></li>
<li><a class="reference" href="#operator" id="id35" name="id35">operator[]</a></li>
<li><a class="reference" href="#find-key" id="id36" name="id36">find_key()</a></li>
</ul>
</li>
<li><a class="reference" href="#torrent-info" id="id36" name="id36">torrent_info</a><ul>
<li><a class="reference" href="#id3" id="id37" name="id37">torrent_info()</a></li>
<li><a class="reference" href="#set-comment-set-piece-size-set-creator-set-hash-add-tracker-add-file" id="id38" name="id38">set_comment() set_piece_size() set_creator() set_hash() add_tracker() add_file()</a></li>
<li><a class="reference" href="#create-torrent" id="id39" name="id39">create_torrent()</a></li>
<li><a class="reference" href="#begin-files-end-files-rbegin-files-rend-files" id="id40" name="id40">begin_files() end_files() rbegin_files() rend_files()</a></li>
<li><a class="reference" href="#num-files-file-at" id="id41" name="id41">num_files() file_at()</a></li>
<li><a class="reference" href="#map-block" id="id42" name="id42">map_block()</a></li>
<li><a class="reference" href="#map-file" id="id43" name="id43">map_file()</a></li>
<li><a class="reference" href="#url-seeds" id="id44" name="id44">url_seeds()</a></li>
<li><a class="reference" href="#print" id="id45" name="id45">print()</a></li>
<li><a class="reference" href="#trackers" id="id46" name="id46">trackers()</a></li>
<li><a class="reference" href="#total-size-piece-length-piece-size-num-pieces" id="id47" name="id47">total_size() piece_length() piece_size() num_pieces()</a></li>
<li><a class="reference" href="#hash-for-piece-info-hash" id="id48" name="id48">hash_for_piece() info_hash()</a></li>
<li><a class="reference" href="#name-comment-creation-date-creator" id="id49" name="id49">name() comment() creation_date() creator()</a></li>
<li><a class="reference" href="#priv-set-priv" id="id50" name="id50">priv() set_priv()</a></li>
<li><a class="reference" href="#nodes" id="id51" name="id51">nodes()</a></li>
<li><a class="reference" href="#add-node" id="id52" name="id52">add_node()</a></li>
<li><a class="reference" href="#torrent-info" id="id37" name="id37">torrent_info</a><ul>
<li><a class="reference" href="#id3" id="id38" name="id38">torrent_info()</a></li>
<li><a class="reference" href="#set-comment-set-piece-size-set-creator-set-hash-add-tracker-add-file" id="id39" name="id39">set_comment() set_piece_size() set_creator() set_hash() add_tracker() add_file()</a></li>
<li><a class="reference" href="#create-torrent" id="id40" name="id40">create_torrent()</a></li>
<li><a class="reference" href="#begin-files-end-files-rbegin-files-rend-files" id="id41" name="id41">begin_files() end_files() rbegin_files() rend_files()</a></li>
<li><a class="reference" href="#num-files-file-at" id="id42" name="id42">num_files() file_at()</a></li>
<li><a class="reference" href="#map-block" id="id43" name="id43">map_block()</a></li>
<li><a class="reference" href="#map-file" id="id44" name="id44">map_file()</a></li>
<li><a class="reference" href="#url-seeds" id="id45" name="id45">url_seeds()</a></li>
<li><a class="reference" href="#print" id="id46" name="id46">print()</a></li>
<li><a class="reference" href="#trackers" id="id47" name="id47">trackers()</a></li>
<li><a class="reference" href="#total-size-piece-length-piece-size-num-pieces" id="id48" name="id48">total_size() piece_length() piece_size() num_pieces()</a></li>
<li><a class="reference" href="#hash-for-piece-info-hash" id="id49" name="id49">hash_for_piece() info_hash()</a></li>
<li><a class="reference" href="#name-comment-creation-date-creator" id="id50" name="id50">name() comment() creation_date() creator()</a></li>
<li><a class="reference" href="#priv-set-priv" id="id51" name="id51">priv() set_priv()</a></li>
<li><a class="reference" href="#nodes" id="id52" name="id52">nodes()</a></li>
<li><a class="reference" href="#add-node" id="id53" name="id53">add_node()</a></li>
</ul>
</li>
<li><a class="reference" href="#torrent-handle" id="id53" name="id53">torrent_handle</a><ul>
<li><a class="reference" href="#file-progress" id="id54" name="id54">file_progress()</a></li>
<li><a class="reference" href="#save-path" id="id55" name="id55">save_path()</a></li>
<li><a class="reference" href="#move-storage" id="id56" name="id56">move_storage()</a></li>
<li><a class="reference" href="#force-reannounce" id="id57" name="id57">force_reannounce()</a></li>
<li><a class="reference" href="#connect-peer" id="id58" name="id58">connect_peer()</a></li>
<li><a class="reference" href="#set-ratio" id="id59" name="id59">set_ratio()</a></li>
<li><a class="reference" href="#set-upload-limit-set-download-limit" id="id60" name="id60">set_upload_limit() set_download_limit()</a></li>
<li><a class="reference" href="#set-sequenced-download-threshold" id="id61" name="id61">set_sequenced_download_threshold()</a></li>
<li><a class="reference" href="#set-peer-upload-limit-set-peer-download-limit" id="id62" name="id62">set_peer_upload_limit() set_peer_download_limit()</a></li>
<li><a class="reference" href="#pause-resume-is-paused" id="id63" name="id63">pause() resume() is_paused()</a></li>
<li><a class="reference" href="#is-seed" id="id64" name="id64">is_seed()</a></li>
<li><a class="reference" href="#has-metadata" id="id65" name="id65">has_metadata()</a></li>
<li><a class="reference" href="#set-tracker-login" id="id66" name="id66">set_tracker_login()</a></li>
<li><a class="reference" href="#trackers-replace-trackers" id="id67" name="id67">trackers() replace_trackers()</a></li>
<li><a class="reference" href="#add-url-seed" id="id68" name="id68">add_url_seed()</a></li>
<li><a class="reference" href="#use-interface" id="id69" name="id69">use_interface()</a></li>
<li><a class="reference" href="#info-hash" id="id70" name="id70">info_hash()</a></li>
<li><a class="reference" href="#id5" id="id71" name="id71">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#write-resume-data" id="id72" name="id72">write_resume_data()</a></li>
<li><a class="reference" href="#metadata" id="id73" name="id73">metadata()</a></li>
<li><a class="reference" href="#id6" id="id74" name="id74">status()</a></li>
<li><a class="reference" href="#get-download-queue" id="id75" name="id75">get_download_queue()</a></li>
<li><a class="reference" href="#get-peer-info" id="id76" name="id76">get_peer_info()</a></li>
<li><a class="reference" href="#get-torrent-info" id="id77" name="id77">get_torrent_info()</a></li>
<li><a class="reference" href="#is-valid" id="id78" name="id78">is_valid()</a></li>
<li><a class="reference" href="#torrent-handle" id="id54" name="id54">torrent_handle</a><ul>
<li><a class="reference" href="#file-progress" id="id55" name="id55">file_progress()</a></li>
<li><a class="reference" href="#save-path" id="id56" name="id56">save_path()</a></li>
<li><a class="reference" href="#move-storage" id="id57" name="id57">move_storage()</a></li>
<li><a class="reference" href="#force-reannounce" id="id58" name="id58">force_reannounce()</a></li>
<li><a class="reference" href="#connect-peer" id="id59" name="id59">connect_peer()</a></li>
<li><a class="reference" href="#set-ratio" id="id60" name="id60">set_ratio()</a></li>
<li><a class="reference" href="#set-upload-limit-set-download-limit" id="id61" name="id61">set_upload_limit() set_download_limit()</a></li>
<li><a class="reference" href="#set-sequenced-download-threshold" id="id62" name="id62">set_sequenced_download_threshold()</a></li>
<li><a class="reference" href="#set-peer-upload-limit-set-peer-download-limit" id="id63" name="id63">set_peer_upload_limit() set_peer_download_limit()</a></li>
<li><a class="reference" href="#pause-resume-is-paused" id="id64" name="id64">pause() resume() is_paused()</a></li>
<li><a class="reference" href="#is-seed" id="id65" name="id65">is_seed()</a></li>
<li><a class="reference" href="#has-metadata" id="id66" name="id66">has_metadata()</a></li>
<li><a class="reference" href="#set-tracker-login" id="id67" name="id67">set_tracker_login()</a></li>
<li><a class="reference" href="#trackers-replace-trackers" id="id68" name="id68">trackers() replace_trackers()</a></li>
<li><a class="reference" href="#add-url-seed" id="id69" name="id69">add_url_seed()</a></li>
<li><a class="reference" href="#use-interface" id="id70" name="id70">use_interface()</a></li>
<li><a class="reference" href="#info-hash" id="id71" name="id71">info_hash()</a></li>
<li><a class="reference" href="#id5" id="id72" name="id72">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#write-resume-data" id="id73" name="id73">write_resume_data()</a></li>
<li><a class="reference" href="#metadata" id="id74" name="id74">metadata()</a></li>
<li><a class="reference" href="#id6" id="id75" name="id75">status()</a></li>
<li><a class="reference" href="#get-download-queue" id="id76" name="id76">get_download_queue()</a></li>
<li><a class="reference" href="#get-peer-info" id="id77" name="id77">get_peer_info()</a></li>
<li><a class="reference" href="#get-torrent-info" id="id78" name="id78">get_torrent_info()</a></li>
<li><a class="reference" href="#is-valid" id="id79" name="id79">is_valid()</a></li>
</ul>
</li>
<li><a class="reference" href="#torrent-status" id="id79" name="id79">torrent_status</a></li>
<li><a class="reference" href="#peer-info" id="id80" name="id80">peer_info</a></li>
<li><a class="reference" href="#session-settings" id="id81" name="id81">session_settings</a></li>
<li><a class="reference" href="#ip-filter" id="id82" name="id82">ip_filter</a><ul>
<li><a class="reference" href="#id8" id="id83" name="id83">ip_filter()</a></li>
<li><a class="reference" href="#add-rule" id="id84" name="id84">add_rule()</a></li>
<li><a class="reference" href="#access" id="id85" name="id85">access()</a></li>
<li><a class="reference" href="#export-filter" id="id86" name="id86">export_filter()</a></li>
<li><a class="reference" href="#torrent-status" id="id80" name="id80">torrent_status</a></li>
<li><a class="reference" href="#peer-info" id="id81" name="id81">peer_info</a></li>
<li><a class="reference" href="#session-settings" id="id82" name="id82">session_settings</a></li>
<li><a class="reference" href="#ip-filter" id="id83" name="id83">ip_filter</a><ul>
<li><a class="reference" href="#id8" id="id84" name="id84">ip_filter()</a></li>
<li><a class="reference" href="#add-rule" id="id85" name="id85">add_rule()</a></li>
<li><a class="reference" href="#access" id="id86" name="id86">access()</a></li>
<li><a class="reference" href="#export-filter" id="id87" name="id87">export_filter()</a></li>
</ul>
</li>
<li><a class="reference" href="#big-number" id="id87" name="id87">big_number</a></li>
<li><a class="reference" href="#hasher" id="id88" name="id88">hasher</a></li>
<li><a class="reference" href="#fingerprint" id="id89" name="id89">fingerprint</a></li>
<li><a class="reference" href="#free-functions" id="id90" name="id90">free functions</a><ul>
<li><a class="reference" href="#identify-client" id="id91" name="id91">identify_client()</a></li>
<li><a class="reference" href="#client-fingerprint" id="id92" name="id92">client_fingerprint()</a></li>
<li><a class="reference" href="#bdecode-bencode" id="id93" name="id93">bdecode() bencode()</a></li>
<li><a class="reference" href="#big-number" id="id88" name="id88">big_number</a></li>
<li><a class="reference" href="#hasher" id="id89" name="id89">hasher</a></li>
<li><a class="reference" href="#fingerprint" id="id90" name="id90">fingerprint</a></li>
<li><a class="reference" href="#free-functions" id="id91" name="id91">free functions</a><ul>
<li><a class="reference" href="#identify-client" id="id92" name="id92">identify_client()</a></li>
<li><a class="reference" href="#client-fingerprint" id="id93" name="id93">client_fingerprint()</a></li>
<li><a class="reference" href="#bdecode-bencode" id="id94" name="id94">bdecode() bencode()</a></li>
</ul>
</li>
<li><a class="reference" href="#alerts" id="id94" name="id94">alerts</a><ul>
<li><a class="reference" href="#listen-failed-alert" id="id95" name="id95">listen_failed_alert</a></li>
<li><a class="reference" href="#file-error-alert" id="id96" name="id96">file_error_alert</a></li>
<li><a class="reference" href="#tracker-announce-alert" id="id97" name="id97">tracker_announce_alert</a></li>
<li><a class="reference" href="#tracker-alert" id="id98" name="id98">tracker_alert</a></li>
<li><a class="reference" href="#tracker-reply-alert" id="id99" name="id99">tracker_reply_alert</a></li>
<li><a class="reference" href="#tracker-warning-alert" id="id100" name="id100">tracker_warning_alert</a></li>
<li><a class="reference" href="#url-seed-alert" id="id101" name="id101">url_seed_alert</a></li>
<li><a class="reference" href="#hash-failed-alert" id="id102" name="id102">hash_failed_alert</a></li>
<li><a class="reference" href="#peer-ban-alert" id="id103" name="id103">peer_ban_alert</a></li>
<li><a class="reference" href="#peer-error-alert" id="id104" name="id104">peer_error_alert</a></li>
<li><a class="reference" href="#invalid-request-alert" id="id105" name="id105">invalid_request_alert</a></li>
<li><a class="reference" href="#torrent-finished-alert" id="id106" name="id106">torrent_finished_alert</a></li>
<li><a class="reference" href="#metadata-failed-alert" id="id107" name="id107">metadata_failed_alert</a></li>
<li><a class="reference" href="#metadata-received-alert" id="id108" name="id108">metadata_received_alert</a></li>
<li><a class="reference" href="#fastresume-rejected-alert" id="id109" name="id109">fastresume_rejected_alert</a></li>
<li><a class="reference" href="#dispatcher" id="id110" name="id110">dispatcher</a></li>
<li><a class="reference" href="#alerts" id="id95" name="id95">alerts</a><ul>
<li><a class="reference" href="#listen-failed-alert" id="id96" name="id96">listen_failed_alert</a></li>
<li><a class="reference" href="#file-error-alert" id="id97" name="id97">file_error_alert</a></li>
<li><a class="reference" href="#tracker-announce-alert" id="id98" name="id98">tracker_announce_alert</a></li>
<li><a class="reference" href="#tracker-alert" id="id99" name="id99">tracker_alert</a></li>
<li><a class="reference" href="#tracker-reply-alert" id="id100" name="id100">tracker_reply_alert</a></li>
<li><a class="reference" href="#tracker-warning-alert" id="id101" name="id101">tracker_warning_alert</a></li>
<li><a class="reference" href="#url-seed-alert" id="id102" name="id102">url_seed_alert</a></li>
<li><a class="reference" href="#hash-failed-alert" id="id103" name="id103">hash_failed_alert</a></li>
<li><a class="reference" href="#peer-ban-alert" id="id104" name="id104">peer_ban_alert</a></li>
<li><a class="reference" href="#peer-error-alert" id="id105" name="id105">peer_error_alert</a></li>
<li><a class="reference" href="#invalid-request-alert" id="id106" name="id106">invalid_request_alert</a></li>
<li><a class="reference" href="#torrent-finished-alert" id="id107" name="id107">torrent_finished_alert</a></li>
<li><a class="reference" href="#metadata-failed-alert" id="id108" name="id108">metadata_failed_alert</a></li>
<li><a class="reference" href="#metadata-received-alert" id="id109" name="id109">metadata_received_alert</a></li>
<li><a class="reference" href="#fastresume-rejected-alert" id="id110" name="id110">fastresume_rejected_alert</a></li>
<li><a class="reference" href="#dispatcher" id="id111" name="id111">dispatcher</a></li>
</ul>
</li>
<li><a class="reference" href="#exceptions" id="id111" name="id111">exceptions</a><ul>
<li><a class="reference" href="#invalid-handle" id="id112" name="id112">invalid_handle</a></li>
<li><a class="reference" href="#duplicate-torrent" id="id113" name="id113">duplicate_torrent</a></li>
<li><a class="reference" href="#invalid-encoding" id="id114" name="id114">invalid_encoding</a></li>
<li><a class="reference" href="#type-error" id="id115" name="id115">type_error</a></li>
<li><a class="reference" href="#invalid-torrent-file" id="id116" name="id116">invalid_torrent_file</a></li>
<li><a class="reference" href="#exceptions" id="id112" name="id112">exceptions</a><ul>
<li><a class="reference" href="#invalid-handle" id="id113" name="id113">invalid_handle</a></li>
<li><a class="reference" href="#duplicate-torrent" id="id114" name="id114">duplicate_torrent</a></li>
<li><a class="reference" href="#invalid-encoding" id="id115" name="id115">invalid_encoding</a></li>
<li><a class="reference" href="#type-error" id="id116" name="id116">type_error</a></li>
<li><a class="reference" href="#invalid-torrent-file" id="id117" name="id117">invalid_torrent_file</a></li>
</ul>
</li>
<li><a class="reference" href="#fast-resume" id="id117" name="id117">fast resume</a><ul>
<li><a class="reference" href="#file-format" id="id118" name="id118">file format</a></li>
<li><a class="reference" href="#fast-resume" id="id118" name="id118">fast resume</a><ul>
<li><a class="reference" href="#file-format" id="id119" name="id119">file format</a></li>
</ul>
</li>
<li><a class="reference" href="#threads" id="id119" name="id119">threads</a></li>
<li><a class="reference" href="#storage-allocation" id="id120" name="id120">storage allocation</a><ul>
<li><a class="reference" href="#full-allocation" id="id121" name="id121">full allocation</a></li>
<li><a class="reference" href="#compact-allocation" id="id122" name="id122">compact allocation</a></li>
<li><a class="reference" href="#threads" id="id120" name="id120">threads</a></li>
<li><a class="reference" href="#storage-allocation" id="id121" name="id121">storage allocation</a><ul>
<li><a class="reference" href="#full-allocation" id="id122" name="id122">full allocation</a></li>
<li><a class="reference" href="#compact-allocation" id="id123" name="id123">compact allocation</a></li>
</ul>
</li>
<li><a class="reference" href="#extensions" id="id123" name="id123">extensions</a><ul>
<li><a class="reference" href="#chat-messages" id="id124" name="id124">chat messages</a></li>
<li><a class="reference" href="#metadata-from-peers" id="id125" name="id125">metadata from peers</a></li>
<li><a class="reference" href="#http-seeding" id="id126" name="id126">HTTP seeding</a></li>
<li><a class="reference" href="#extensions" id="id124" name="id124">extensions</a><ul>
<li><a class="reference" href="#chat-messages" id="id125" name="id125">chat messages</a></li>
<li><a class="reference" href="#metadata-from-peers" id="id126" name="id126">metadata from peers</a></li>
<li><a class="reference" href="#http-seeding" id="id127" name="id127">HTTP seeding</a></li>
</ul>
</li>
<li><a class="reference" href="#filename-checks" id="id127" name="id127">filename checks</a></li>
<li><a class="reference" href="#acknowledgments" id="id128" name="id128">acknowledgments</a></li>
<li><a class="reference" href="#filename-checks" id="id128" name="id128">filename checks</a></li>
<li><a class="reference" href="#acknowledgments" id="id129" name="id129">acknowledgments</a></li>
</ul>
</div>
<div class="section" id="overview">
@ -240,6 +241,8 @@ class session: public boost::noncopyable
, bool compact_mode = true
, int block_size = 16 * 1024);
session_proxy abort();
void remove_torrent(torrent_handle const&amp; h);
void disable_extensions();
@ -309,6 +312,21 @@ returns. So, it's advised that any kind of interface (such as windows) are close
destructing the session object. Because it can take a few second for it to finish. The
timeout can be set with <tt class="docutils literal"><span class="pre">set_settings()</span></tt>.</p>
</div>
<div class="section" id="abort">
<h2><a name="abort">abort()</a></h2>
<p>In case you want to destruct the session asynchrounously, you can request a session
destruction proxy. If you don't do this, the destructor of the session object will
block while the trackers are contacted. If you keep one <tt class="docutils literal"><span class="pre">session_proxy</span></tt> to the
session when destructing it, the destructor will not block, but start to close down
the session, the destructor of the proxy will then synchronize the threads. So, the
destruction of the session is performed from the <tt class="docutils literal"><span class="pre">session</span></tt> destructor call until the
<tt class="docutils literal"><span class="pre">session_proxy</span></tt> destructor call. The <tt class="docutils literal"><span class="pre">session_proxy</span></tt> does not have any operations
on it (since the session is being closed down, no operations are allowed on it). The
only valid operation is calling the destructor:</p>
<pre class="literal-block">
class session_proxy { ~session_proxy() };
</pre>
</div>
<div class="section" id="add-torrent">
<h2><a name="add-torrent">add_torrent()</a></h2>
<blockquote>

View File

@ -85,6 +85,8 @@ The ``session`` class has the following synopsis::
, bool compact_mode = true
, int block_size = 16 * 1024);
session_proxy abort();
void remove_torrent(torrent_handle const& h);
void disable_extensions();
@ -156,6 +158,21 @@ returns. So, it's advised that any kind of interface (such as windows) are close
destructing the session object. Because it can take a few second for it to finish. The
timeout can be set with ``set_settings()``.
abort()
-------
In case you want to destruct the session asynchrounously, you can request a session
destruction proxy. If you don't do this, the destructor of the session object will
block while the trackers are contacted. If you keep one ``session_proxy`` to the
session when destructing it, the destructor will not block, but start to close down
the session, the destructor of the proxy will then synchronize the threads. So, the
destruction of the session is performed from the ``session`` destructor call until the
``session_proxy`` destructor call. The ``session_proxy`` does not have any operations
on it (since the session is being closed down, no operations are allowed on it). The
only valid operation is calling the destructor::
class session_proxy { ~session_proxy() };
add_torrent()
-------------

View File

@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/ip_filter.hpp"
using boost::bind;

View File

@ -42,6 +42,7 @@ libtorrent/udp_tracker_connection.hpp \
libtorrent/utf8.hpp \
libtorrent/version.hpp \
libtorrent/aux_/allocate_resources_impl.hpp \
libtorrent/aux_/session_impl.hpp \
\
libtorrent/kademlia/closest_nodes.hpp \
libtorrent/kademlia/dht_tracker.hpp \

View File

@ -0,0 +1,382 @@
/*
Copyright (c) 2006, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_SESSION_IMPL_HPP_INCLUDED
#define TORRENT_SESSION_IMPL_HPP_INCLUDED
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <deque>
#ifdef _MSC_VER
#pragma warning(push, 1)
#endif
#include <boost/limits.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/thread.hpp>
#include <boost/thread/recursive_mutex.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/policy.hpp"
#include "libtorrent/tracker_manager.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/debug.hpp"
#include "libtorrent/peer_request.hpp"
#include "libtorrent/piece_block_progress.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/kademlia/dht_tracker.hpp"
#include "libtorrent/session_status.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/stat.hpp"
namespace libtorrent
{
namespace aux
{
struct session_impl;
// this data is shared between the main thread and the
// thread that initialize pieces
struct piece_checker_data
{
piece_checker_data()
: processing(false), progress(0.f), abort(false) {}
boost::shared_ptr<torrent> torrent_ptr;
boost::filesystem::path save_path;
sha1_hash info_hash;
void parse_resume_data(
const entry& rd
, const torrent_info& info
, std::string& error);
std::vector<int> piece_map;
std::vector<piece_picker::downloading_piece> unfinished_pieces;
std::vector<tcp::endpoint> peers;
entry resume_data;
// this is true if this torrent is being processed (checked)
// if it is not being processed, then it can be removed from
// the queue without problems, otherwise the abort flag has
// to be set.
bool processing;
// is filled in by storage::initialize_pieces()
// and represents the progress. It should be a
// value in the range [0, 1]
float progress;
// abort defaults to false and is typically
// filled in by torrent_handle when the user
// aborts the torrent
bool abort;
};
struct checker_impl: boost::noncopyable
{
checker_impl(session_impl& s): m_ses(s), m_abort(false) {}
void operator()();
piece_checker_data* find_torrent(const sha1_hash& info_hash);
void remove_torrent(sha1_hash const& info_hash);
#ifndef NDEBUG
void check_invariant() const;
#endif
// when the files has been checked
// the torrent is added to the session
session_impl& m_ses;
mutable boost::mutex m_mutex;
boost::condition m_cond;
// a list of all torrents that are currently in queue
// or checking their files
std::deque<boost::shared_ptr<piece_checker_data> > m_torrents;
std::deque<boost::shared_ptr<piece_checker_data> > m_processing;
bool m_abort;
};
// this is the link between the main thread and the
// thread started to run the main downloader loop
struct session_impl: boost::noncopyable
{
#ifndef NDEBUG
friend class ::libtorrent::peer_connection;
#endif
friend class checker_impl;
friend class invariant_access;
typedef std::map<boost::shared_ptr<stream_socket>
, boost::intrusive_ptr<peer_connection> >
connection_map;
typedef std::map<sha1_hash, boost::shared_ptr<torrent> > torrent_map;
typedef std::deque<boost::intrusive_ptr<peer_connection> >
connection_queue;
session_impl(
std::pair<int, int> listen_port_range
, fingerprint const& cl_fprint
, char const* listen_interface = "0.0.0.0");
~session_impl();
void operator()();
void open_listen_port();
void async_accept();
void on_incoming_connection(boost::shared_ptr<stream_socket> const& s
, boost::weak_ptr<socket_acceptor> const& as, asio::error const& e);
// must be locked to access the data
// in this struct
typedef boost::recursive_mutex mutex_t;
mutable mutex_t m_mutex;
boost::weak_ptr<torrent> find_torrent(const sha1_hash& info_hash);
peer_id const& get_peer_id() const { return m_peer_id; }
// this will see if there are any pending connection attempts
// and in that case initiate new connections until the limit
// is reached.
void process_connection_queue();
void close_connection(boost::intrusive_ptr<peer_connection> const& p);
void connection_completed(boost::intrusive_ptr<peer_connection> const& p);
void connection_failed(boost::shared_ptr<stream_socket> const& s
, tcp::endpoint const& a, char const* message);
void set_settings(session_settings const& s);
session_settings const& settings() const { return m_settings; }
#ifndef TORRENT_DISABLE_DHT
void add_dht_node(std::pair<std::string, int> const& node);
void add_dht_node(udp::endpoint n);
void add_dht_router(std::pair<std::string, int> const& node);
void set_dht_settings(dht_settings const& s);
dht_settings const& kad_settings() const { return m_dht_settings; }
void start_dht(entry const& startup_state);
void stop_dht();
entry dht_state() const;
#endif
bool is_aborted() const { return m_abort; }
void set_ip_filter(ip_filter const& f);
bool listen_on(
std::pair<int, int> const& port_range
, const char* net_interface = 0);
bool is_listening() const;
torrent_handle add_torrent(
torrent_info const& ti
, boost::filesystem::path const& save_path
, entry const& resume_data
, bool compact_mode
, int block_size);
torrent_handle add_torrent(
char const* tracker_url
, sha1_hash const& info_hash
, boost::filesystem::path const& save_path
, entry const& resume_data
, bool compact_mode
, int block_size);
void remove_torrent(torrent_handle const& h);
void disable_extensions();
void enable_extension(extension_index i);
bool extensions_enabled() const;
bool extension_enabled(int i) const
{ return m_extension_enabled[i]; }
std::vector<torrent_handle> get_torrents();
void set_severity_level(alert::severity_t s);
std::auto_ptr<alert> pop_alert();
void set_download_rate_limit(int bytes_per_second);
void set_upload_rate_limit(int bytes_per_second);
void set_max_half_open_connections(int limit);
void set_max_connections(int limit);
void set_max_uploads(int limit);
session_status status() const;
void set_peer_id(peer_id const& id);
void set_key(int key);
unsigned short listen_port() const;
void abort();
// handles delayed alerts
alert_manager m_alerts;
// private:
// this is where all active sockets are stored.
// the selector can sleep while there's no activity on
// them
demuxer m_selector;
tracker_manager m_tracker_manager;
torrent_map m_torrents;
// this maps sockets to their peer_connection
// object. It is the complete list of all connected
// peers.
connection_map m_connections;
// this is a list of half-open tcp connections
// (only outgoing connections)
connection_map m_half_open;
// this is a queue of pending outgoing connections. If the
// list of half-open connections is full (given the global
// limit), new outgoing connections are put on this queue,
// waiting for one slot in the half-open queue to open up.
connection_queue m_connection_queue;
// filters incoming connections
ip_filter m_ip_filter;
// the peer id that is generated at the start of the session
peer_id m_peer_id;
// the key is an id that is used to identify the
// client with the tracker only. It is randomized
// at startup
int m_key;
// the range of ports we try to listen on
std::pair<int, int> m_listen_port_range;
// the ip-address of the interface
// we are supposed to listen on.
// if the ip is set to zero, it means
// that we should let the os decide which
// interface to listen on
tcp::endpoint m_listen_interface;
boost::shared_ptr<socket_acceptor> m_listen_socket;
// the entries in this array maps the
// extension index (as specified in peer_connection)
bool m_extension_enabled[num_supported_extensions];
// the settings for the client
session_settings m_settings;
// set to true when the session object
// is being destructed and the thread
// should exit
volatile bool m_abort;
// maximum upload rate given in
// bytes per second. -1 means
// unlimited
int m_upload_rate;
int m_download_rate;
int m_max_uploads;
int m_max_connections;
// the number of simultaneous half-open tcp
// connections libtorrent will have.
int m_half_open_limit;
// statistics gathered from all torrents.
stat m_stat;
// is false by default and set to true when
// the first incoming connection is established
// this is used to know if the client is behind
// NAT or not.
bool m_incoming_connection;
// does the actual disconnections
// that are queued up in m_disconnect_peer
void second_tick(asio::error const& e);
boost::posix_time::ptime m_last_tick;
#ifndef TORRENT_DISABLE_DHT
boost::scoped_ptr<dht::dht_tracker> m_dht;
dht_settings m_dht_settings;
#endif
// the timer used to fire the second_tick
deadline_timer m_timer;
#ifndef NDEBUG
void check_invariant(const char *place = 0);
#endif
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
boost::shared_ptr<logger> create_log(std::string const& name, bool append = true);
public:
boost::shared_ptr<logger> m_logger;
private:
#endif
// data shared between the main thread
// and the checker thread
checker_impl m_checker_impl;
// the main working thread
boost::scoped_ptr<boost::thread> m_thread;
// the thread that calls initialize_pieces()
// on all torrents before they start downloading
boost::scoped_ptr<boost::thread> m_checker_thread;
};
}
}
#endif

View File

@ -89,7 +89,7 @@ namespace libtorrent
// The peer_conenction should handshake and verify that the
// other end has the correct id
bt_peer_connection(
detail::session_impl& ses
aux::session_impl& ses
, boost::weak_ptr<torrent> t
, boost::shared_ptr<stream_socket> s
, tcp::endpoint const& remote);
@ -97,7 +97,7 @@ namespace libtorrent
// with this constructor we have been contacted and we still don't
// know which torrent the connection belongs to
bt_peer_connection(
detail::session_impl& ses
aux::session_impl& ses
, boost::shared_ptr<stream_socket> s);
~bt_peer_connection();

View File

@ -105,7 +105,7 @@ namespace libtorrent
// The peer_conenction should handshake and verify that the
// other end has the correct id
peer_connection(
detail::session_impl& ses
aux::session_impl& ses
, boost::weak_ptr<torrent> t
, boost::shared_ptr<stream_socket> s
, tcp::endpoint const& remote);
@ -113,7 +113,7 @@ namespace libtorrent
// with this constructor we have been contacted and we still don't
// know which torrent the connection belongs to
peer_connection(
detail::session_impl& ses
aux::session_impl& ses
, boost::shared_ptr<stream_socket> s);
// this function is called once the torrent associated
@ -350,7 +350,7 @@ namespace libtorrent
// a back reference to the session
// the peer belongs to.
detail::session_impl& m_ses;
aux::session_impl& m_ses;
boost::intrusive_ptr<peer_connection> self()
{ return boost::intrusive_ptr<peer_connection>(this); }

View File

@ -1,6 +1,6 @@
/*
Copyright (c) 2003, Arvid Norberg
Copyright (c) 2006, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -48,7 +48,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/tuple/tuple.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/thread.hpp>
#include <boost/thread/recursive_mutex.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
@ -56,24 +55,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/policy.hpp"
#include "libtorrent/tracker_manager.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/debug.hpp"
#include "libtorrent/peer_request.hpp"
#include "libtorrent/piece_block_progress.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/kademlia/dht_tracker.hpp"
#include "libtorrent/session_status.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/fingerprint.hpp"
#if !defined(NDEBUG) && defined(_MSC_VER)
# include <float.h>
@ -83,6 +69,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
class torrent;
class ip_filter;
enum extension_index
{
@ -93,7 +80,7 @@ namespace libtorrent
num_supported_extensions
};
namespace detail
namespace aux
{
// workaround for microsofts
// hardware exceptions that makes
@ -116,222 +103,19 @@ namespace libtorrent
#else
struct eh_initializer {};
#endif
// this data is shared between the main thread and the
// thread that initialize pieces
struct piece_checker_data
{
piece_checker_data()
: processing(false), progress(0.f), abort(false) {}
boost::shared_ptr<torrent> torrent_ptr;
boost::filesystem::path save_path;
sha1_hash info_hash;
void parse_resume_data(
const entry& rd
, const torrent_info& info
, std::string& error);
std::vector<int> piece_map;
std::vector<piece_picker::downloading_piece> unfinished_pieces;
std::vector<tcp::endpoint> peers;
entry resume_data;
// this is true if this torrent is being processed (checked)
// if it is not being processed, then it can be removed from
// the queue without problems, otherwise the abort flag has
// to be set.
bool processing;
// is filled in by storage::initialize_pieces()
// and represents the progress. It should be a
// value in the range [0, 1]
float progress;
// abort defaults to false and is typically
// filled in by torrent_handle when the user
// aborts the torrent
bool abort;
};
struct checker_impl: boost::noncopyable
{
checker_impl(session_impl& s): m_ses(s), m_abort(false) {}
void operator()();
piece_checker_data* find_torrent(const sha1_hash& info_hash);
void remove_torrent(sha1_hash const& info_hash);
#ifndef NDEBUG
void check_invariant() const;
#endif
// when the files has been checked
// the torrent is added to the session
session_impl& m_ses;
mutable boost::mutex m_mutex;
boost::condition m_cond;
// a list of all torrents that are currently in queue
// or checking their files
std::deque<boost::shared_ptr<piece_checker_data> > m_torrents;
std::deque<boost::shared_ptr<piece_checker_data> > m_processing;
bool m_abort;
};
// this is the link between the main thread and the
// thread started to run the main downloader loop
struct session_impl: boost::noncopyable
{
friend class invariant_access;
typedef std::map<boost::shared_ptr<stream_socket>
, boost::intrusive_ptr<peer_connection> >
connection_map;
typedef std::map<sha1_hash, boost::shared_ptr<torrent> > torrent_map;
typedef std::deque<boost::intrusive_ptr<peer_connection> >
connection_queue;
session_impl(
std::pair<int, int> listen_port_range
, fingerprint const& cl_fprint
, char const* listen_interface = "0.0.0.0");
void operator()();
void open_listen_port();
void async_accept();
void on_incoming_connection(boost::shared_ptr<stream_socket> const& s
, boost::weak_ptr<socket_acceptor> const& as, asio::error const& e);
// must be locked to access the data
// in this struct
typedef boost::recursive_mutex mutex_t;
mutable mutex_t m_mutex;
boost::weak_ptr<torrent> find_torrent(const sha1_hash& info_hash);
peer_id const& get_peer_id() const { return m_peer_id; }
// this is where all active sockets are stored.
// the selector can sleep while there's no activity on
// them
demuxer m_selector;
tracker_manager m_tracker_manager;
torrent_map m_torrents;
// this will see if there are any pending connection attempts
// and in that case initiate new connections until the limit
// is reached.
void process_connection_queue();
void close_connection(boost::intrusive_ptr<peer_connection> const& p);
void connection_completed(boost::intrusive_ptr<peer_connection> const& p);
void connection_failed(boost::shared_ptr<stream_socket> const& s
, tcp::endpoint const& a, char const* message);
void set_settings(session_settings const& s);
// this maps sockets to their peer_connection
// object. It is the complete list of all connected
// peers.
connection_map m_connections;
// this is a list of half-open tcp connections
// (only outgoing connections)
connection_map m_half_open;
// this is a queue of pending outgoing connections. If the
// list of half-open connections is full (given the global
// limit), new outgoing connections are put on this queue,
// waiting for one slot in the half-open queue to open up.
connection_queue m_connection_queue;
// filters incoming connections
ip_filter m_ip_filter;
// the peer id that is generated at the start of the session
peer_id m_peer_id;
// the key is an id that is used to identify the
// client with the tracker only. It is randomized
// at startup
int m_key;
// the range of ports we try to listen on
std::pair<int, int> m_listen_port_range;
// the ip-address of the interface
// we are supposed to listen on.
// if the ip is set to zero, it means
// that we should let the os decide which
// interface to listen on
tcp::endpoint m_listen_interface;
boost::shared_ptr<socket_acceptor> m_listen_socket;
// the entries in this array maps the
// extension index (as specified in peer_connection)
bool m_extension_enabled[num_supported_extensions];
bool extensions_enabled() const;
// the settings for the client
session_settings m_settings;
// set to true when the session object
// is being destructed and the thread
// should exit
volatile bool m_abort;
// maximum upload rate given in
// bytes per second. -1 means
// unlimited
int m_upload_rate;
int m_download_rate;
int m_max_uploads;
int m_max_connections;
// the number of simultaneous half-open tcp
// connections libtorrent will have.
int m_half_open_limit;
// statistics gathered from all torrents.
stat m_stat;
// handles delayed alerts
alert_manager m_alerts;
// is false by default and set to true when
// the first incoming connection is established
// this is used to know if the client is behind
// NAT or not.
bool m_incoming_connection;
// does the actual disconnections
// that are queued up in m_disconnect_peer
void second_tick(asio::error const& e);
boost::posix_time::ptime m_last_tick;
#ifndef TORRENT_DISABLE_DHT
boost::scoped_ptr<dht::dht_tracker> m_dht;
dht_settings m_dht_settings;
#endif
// the timer used to fire the second_tick
deadline_timer m_timer;
#ifndef NDEBUG
void check_invariant(const char *place = 0);
#endif
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
boost::shared_ptr<logger> create_log(std::string const& name, bool append = true);
boost::shared_ptr<logger> m_logger;
#endif
};
struct session_impl;
}
class TORRENT_EXPORT session: public boost::noncopyable, detail::eh_initializer
class TORRENT_EXPORT session_proxy
{
friend class session;
private:
session_proxy(boost::shared_ptr<aux::session_impl> impl)
: m_impl(impl) {}
boost::shared_ptr<aux::session_impl> m_impl;
};
class TORRENT_EXPORT session: public boost::noncopyable, aux::eh_initializer
{
public:
@ -341,10 +125,10 @@ namespace libtorrent
fingerprint const& print
, std::pair<int, int> listen_port_range
, char const* listen_interface = "0.0.0.0");
~session();
std::vector<torrent_handle> get_torrents();
std::vector<torrent_handle> get_torrents() const;
// all torrent_handles must be destructed before the session is destructed!
torrent_handle add_torrent(
@ -374,6 +158,8 @@ namespace libtorrent
, bool compact_mode = true
, int block_size = 16 * 1024);
session_proxy abort() { return session_proxy(m_impl); }
session_status status() const;
#ifndef TORRENT_DISABLE_DHT
@ -429,18 +215,7 @@ namespace libtorrent
// data shared between the main thread
// and the working thread
detail::session_impl m_impl;
// data shared between the main thread
// and the checker thread
detail::checker_impl m_checker_impl;
// the main working thread
boost::thread m_thread;
// the thread that calls initialize_pieces()
// on all torrents before they start downloading
boost::thread m_checker_thread;
boost::shared_ptr<aux::session_impl> m_impl;
};
}

View File

@ -55,7 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
namespace detail
namespace aux
{
struct piece_checker_data;
}
@ -129,7 +129,7 @@ namespace libtorrent
~piece_manager();
bool check_fastresume(detail::piece_checker_data& d
bool check_fastresume(aux::piece_checker_data& d
, std::vector<bool>& pieces, int& num_pieces, bool compact_mode);
std::pair<bool, float> check_files(std::vector<bool>& pieces
, int& num_pieces);

View File

@ -75,7 +75,7 @@ namespace libtorrent
class piece_manager;
namespace detail
namespace aux
{
struct session_impl;
struct piece_checker_data;
@ -94,8 +94,8 @@ namespace libtorrent
public:
torrent(
detail::session_impl& ses
, detail::checker_impl& checker
aux::session_impl& ses
, aux::checker_impl& checker
, torrent_info const& tf
, boost::filesystem::path const& save_path
, tcp::endpoint const& net_interface
@ -106,8 +106,8 @@ namespace libtorrent
// used with metadata-less torrents
// (the metadata is downloaded from the peers)
torrent(
detail::session_impl& ses
, detail::checker_impl& checker
aux::session_impl& ses
, aux::checker_impl& checker
, char const* tracker_url
, sha1_hash const& info_hash
, boost::filesystem::path const& save_path
@ -150,7 +150,7 @@ namespace libtorrent
// each piece of metadata it receives
void metadata_progress(int total_size, int received);
bool check_fastresume(detail::piece_checker_data&);
bool check_fastresume(aux::piece_checker_data&);
std::pair<bool, float> check_files();
void files_checked(std::vector<piece_picker::downloading_piece> const&
unfinished_pieces);
@ -515,8 +515,8 @@ namespace libtorrent
// a back reference to the session
// this torrent belongs to.
detail::session_impl& m_ses;
detail::checker_impl& m_checker;
aux::session_impl& m_ses;
aux::checker_impl& m_checker;
boost::scoped_ptr<piece_picker> m_picker;

View File

@ -53,7 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
namespace detail
namespace aux
{
struct session_impl;
struct checker_impl;
@ -215,7 +215,7 @@ namespace libtorrent
struct TORRENT_EXPORT torrent_handle
{
friend class invariant_access;
friend class session;
friend class aux::session_impl;
friend class torrent;
torrent_handle(): m_ses(0), m_chk(0) {}
@ -324,8 +324,8 @@ namespace libtorrent
private:
torrent_handle(detail::session_impl* s,
detail::checker_impl* c,
torrent_handle(aux::session_impl* s,
aux::checker_impl* c,
const sha1_hash& h)
: m_ses(s)
, m_chk(c)
@ -338,8 +338,8 @@ namespace libtorrent
void check_invariant() const;
#endif
detail::session_impl* m_ses;
detail::checker_impl* m_chk;
aux::session_impl* m_ses;
aux::checker_impl* m_chk;
sha1_hash m_info_hash;
};

View File

@ -94,7 +94,7 @@ namespace libtorrent
// The peer_conenction should handshake and verify that the
// other end has the correct id
web_peer_connection(
detail::session_impl& ses
aux::session_impl& ses
, boost::weak_ptr<torrent> t
, boost::shared_ptr<stream_socket> s
, tcp::endpoint const& remote

View File

@ -45,11 +45,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/io.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/aux_/session_impl.hpp"
using namespace boost::posix_time;
using boost::bind;
using boost::shared_ptr;
using libtorrent::detail::session_impl;
using libtorrent::aux::session_impl;
namespace libtorrent
{
@ -78,7 +79,7 @@ namespace libtorrent
bt_peer_connection::bt_peer_connection(
detail::session_impl& ses
session_impl& ses
, boost::weak_ptr<torrent> tor
, shared_ptr<stream_socket> s
, tcp::endpoint const& remote)
@ -128,7 +129,7 @@ namespace libtorrent
}
bt_peer_connection::bt_peer_connection(
detail::session_impl& ses
session_impl& ses
, boost::shared_ptr<stream_socket> s)
: peer_connection(ses, s)
, m_state(read_protocol_length)
@ -625,7 +626,7 @@ namespace libtorrent
int extended_id = detail::read_uint8(recv_buffer.begin);
if (extended_id > 0 && extended_id < num_supported_extensions
&& !m_ses.m_extension_enabled[extended_id])
&& !m_ses.extension_enabled(extended_id))
throw protocol_error("'extended' message using disabled extension");
switch (extended_id)
@ -1116,18 +1117,18 @@ namespace libtorrent
{
// if this specific extension is disabled
// just don't add it to the supported set
if (!m_ses.m_extension_enabled[i]) continue;
if (!m_ses.extension_enabled(i)) continue;
extension_list[extension_names[i]] = i;
}
handshake["m"] = extension_list;
handshake["p"] = m_ses.m_listen_interface.port();
handshake["v"] = m_ses.m_settings.user_agent;
handshake["p"] = m_ses.listen_port();
handshake["v"] = m_ses.settings().user_agent;
std::string remote_address;
std::back_insert_iterator<std::string> out(remote_address);
detail::write_address(remote().address(), out);
handshake["ip"] = remote_address;
handshake["reqq"] = m_ses.m_settings.max_allowed_in_request_queue;
handshake["reqq"] = m_ses.settings().max_allowed_in_request_queue;
std::vector<char> msg;
bencode(std::back_inserter(msg), handshake);
@ -1370,7 +1371,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_DHT
if (m_supports_dht_port && m_ses.m_dht)
write_dht_port(m_ses.m_dht_settings.service_port);
write_dht_port(m_ses.kad_settings().service_port);
#endif
m_state = read_peer_id;

View File

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/bind.hpp>
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
@ -46,11 +45,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/aux_/session_impl.hpp"
using namespace boost::posix_time;
using boost::bind;
using boost::shared_ptr;
using libtorrent::detail::session_impl;
using libtorrent::aux::session_impl;
namespace libtorrent
{
@ -71,7 +71,7 @@ namespace libtorrent
}
peer_connection::peer_connection(
detail::session_impl& ses
session_impl& ses
, boost::weak_ptr<torrent> tor
, shared_ptr<stream_socket> s
, tcp::endpoint const& remote)
@ -82,8 +82,8 @@ namespace libtorrent
,
#endif
m_ses(ses)
, m_max_out_request_queue(m_ses.m_settings.max_out_request_queue)
, m_timeout(m_ses.m_settings.peer_timeout)
, m_max_out_request_queue(m_ses.settings().max_out_request_queue)
, m_timeout(m_ses.settings().peer_timeout)
, m_last_piece(second_clock::universal_time())
, m_packet_size(0)
, m_recv_pos(0)
@ -164,7 +164,7 @@ namespace libtorrent
}
peer_connection::peer_connection(
detail::session_impl& ses
session_impl& ses
, boost::shared_ptr<stream_socket> s)
:
#ifndef NDEBUG
@ -173,8 +173,8 @@ namespace libtorrent
,
#endif
m_ses(ses)
, m_max_out_request_queue(m_ses.m_settings.max_out_request_queue)
, m_timeout(m_ses.m_settings.peer_timeout)
, m_max_out_request_queue(m_ses.settings().max_out_request_queue)
, m_timeout(m_ses.settings().peer_timeout)
, m_last_piece(second_clock::universal_time())
, m_packet_size(0)
, m_recv_pos(0)
@ -799,7 +799,7 @@ namespace libtorrent
return;
}
if (int(m_requests.size()) > m_ses.m_settings.max_allowed_in_request_queue)
if (int(m_requests.size()) > m_ses.settings().max_allowed_in_request_queue)
{
// don't allow clients to abuse our
// memory consumption.
@ -1083,7 +1083,7 @@ namespace libtorrent
<< " <== DHT_PORT [ p: " << listen_port << " ]\n";
#endif
#ifndef TORRENT_DISABLE_DHT
if (m_ses.m_dht) m_ses.m_dht->add_node(udp::endpoint(
m_ses.add_dht_node(udp::endpoint(
m_remote.address(), listen_port));
#endif
}
@ -1408,7 +1408,7 @@ namespace libtorrent
if (!t->valid_metadata()) return;
// calculate the desired download queue size
const float queue_time = m_ses.m_settings.request_queue_time;
const float queue_time = m_ses.settings().request_queue_time;
// (if the latency is more than this, the download will stall)
// so, the queue size is queue_time * down_rate / 16 kiB
// (16 kB is the size of each request)
@ -1426,7 +1426,7 @@ namespace libtorrent
m_desired_queue_size = min_request_queue;
if (!m_download_queue.empty()
&& now - m_last_piece > seconds(m_ses.m_settings.piece_timeout))
&& now - m_last_piece > seconds(m_ses.settings().piece_timeout))
{
// this peer isn't sending the pieces we've
// requested (this has been observed by BitComet)
@ -1956,7 +1956,7 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock();
if (!t)
{
typedef detail::session_impl::torrent_map torrent_map;
typedef session_impl::torrent_map torrent_map;
torrent_map& m = m_ses.m_torrents;
for (torrent_map::iterator i = m.begin(), end(m.end()); i != end; ++i)
{

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
//#include <algo.h>
#include "libtorrent/piece_picker.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#ifndef NDEBUG
#include "libtorrent/peer_connection.hpp"

View File

@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/aux_/session_impl.hpp"
namespace libtorrent
{

File diff suppressed because it is too large Load Diff

View File

@ -64,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_id.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#ifndef NDEBUG
#include <ios>
@ -864,7 +865,7 @@ namespace libtorrent
, path const& path);
bool check_fastresume(
detail::piece_checker_data& d
aux::piece_checker_data& d
, std::vector<bool>& pieces
, int& num_pieces
, bool compact_mode);
@ -1362,7 +1363,7 @@ namespace libtorrent
// isn't return false and the full check
// will be run
bool piece_manager::impl::check_fastresume(
detail::piece_checker_data& data
aux::piece_checker_data& data
, std::vector<bool>& pieces
, int& num_pieces, bool compact_mode)
{
@ -1807,7 +1808,7 @@ namespace libtorrent
}
bool piece_manager::check_fastresume(
detail::piece_checker_data& d, std::vector<bool>& pieces
aux::piece_checker_data& d, std::vector<bool>& pieces
, int& num_pieces, bool compact_mode)
{
return m_pimpl->check_fastresume(d, pieces, num_pieces, compact_mode);

View File

@ -66,6 +66,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/aux_/session_impl.hpp"
using namespace libtorrent;
using namespace boost::posix_time;
@ -75,7 +76,7 @@ using boost::tuples::make_tuple;
using boost::filesystem::complete;
using boost::bind;
using boost::mutex;
using libtorrent::detail::session_impl;
using libtorrent::aux::session_impl;
// PROFILING CODE
@ -158,7 +159,7 @@ namespace
, tor(t)
{ assert(t != 0); }
bool operator()(const detail::session_impl::connection_map::value_type& c) const
bool operator()(const session_impl::connection_map::value_type& c) const
{
tcp::endpoint sender = c.first->remote_endpoint();
if (sender.address() != ip.address()) return false;
@ -190,8 +191,8 @@ namespace
namespace libtorrent
{
torrent::torrent(
detail::session_impl& ses
, detail::checker_impl& checker
session_impl& ses
, aux::checker_impl& checker
, torrent_info const& tf
, boost::filesystem::path const& save_path
, tcp::endpoint const& net_interface
@ -289,8 +290,8 @@ namespace libtorrent
}
torrent::torrent(
detail::session_impl& ses
, detail::checker_impl& checker
session_impl& ses
, aux::checker_impl& checker
, char const* tracker_url
, sha1_hash const& info_hash
, boost::filesystem::path const& save_path
@ -402,7 +403,7 @@ namespace libtorrent
INVARIANT_CHECK;
if (m_ses.m_abort)
if (m_ses.is_aborted())
m_abort = true;
if (!m_connections.empty())
disconnect_all();
@ -1037,7 +1038,7 @@ namespace libtorrent
= parse_url_components(url);
m_resolving_web_seeds.insert(url);
if (m_ses.m_settings.proxy_ip.empty())
if (m_ses.settings().proxy_ip.empty())
{
tcp::resolver::query q(hostname, boost::lexical_cast<std::string>(port));
m_host_resolver.async_resolve(q, bind(&torrent::on_name_lookup
@ -1046,8 +1047,8 @@ namespace libtorrent
else
{
// use proxy
tcp::resolver::query q(m_ses.m_settings.proxy_ip
, boost::lexical_cast<std::string>(m_ses.m_settings.proxy_port));
tcp::resolver::query q(m_ses.settings().proxy_ip
, boost::lexical_cast<std::string>(m_ses.settings().proxy_port));
m_host_resolver.async_resolve(q, bind(&torrent::on_name_lookup
, shared_from_this(), _1, _2, url));
}
@ -1057,7 +1058,7 @@ namespace libtorrent
void torrent::on_name_lookup(asio::error const& e, tcp::resolver::iterator host
, std::string url) try
{
detail::session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
INVARIANT_CHECK;
@ -1088,7 +1089,7 @@ namespace libtorrent
return;
}
if (m_ses.m_abort) return;
if (m_ses.is_aborted()) return;
tcp::endpoint a(host->endpoint());
@ -1211,7 +1212,7 @@ namespace libtorrent
throw protocol_error("peer is not properly constructed");
}
if (m_ses.m_abort)
if (m_ses.is_aborted())
{
throw protocol_error("session is closing");
}
@ -1361,7 +1362,7 @@ namespace libtorrent
}
bool torrent::check_fastresume(detail::piece_checker_data& data)
bool torrent::check_fastresume(aux::piece_checker_data& data)
{
INVARIANT_CHECK;
@ -1475,7 +1476,7 @@ namespace libtorrent
{
INVARIANT_CHECK;
return m_ses.m_settings;
return m_ses.settings();
}
#ifndef NDEBUG
@ -2025,14 +2026,14 @@ namespace libtorrent
{
boost::mutex::scoped_lock(m_checker.m_mutex);
boost::shared_ptr<detail::piece_checker_data> d(
new detail::piece_checker_data);
boost::shared_ptr<aux::piece_checker_data> d(
new aux::piece_checker_data);
d->torrent_ptr = shared_from_this();
d->save_path = m_save_path;
d->info_hash = m_torrent_file.info_hash();
// add the torrent to the queue to be checked
m_checker.m_torrents.push_back(d);
typedef detail::session_impl::torrent_map torrent_map;
typedef session_impl::torrent_map torrent_map;
torrent_map::iterator i = m_ses.m_torrents.find(
m_torrent_file.info_hash());
assert(i != m_ses.m_torrents.end());

View File

@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/hasher.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/invariant_check.hpp"
#if defined(_MSC_VER) && _MSC_VER < 1300
@ -73,7 +74,7 @@ namespace std
using boost::bind;
using boost::mutex;
using libtorrent::detail::session_impl;
using libtorrent::aux::session_impl;
namespace libtorrent
{
@ -86,8 +87,8 @@ namespace libtorrent
template<class Ret, class F>
Ret call_member(
detail::session_impl* ses
, detail::checker_impl* chk
session_impl* ses
, aux::checker_impl* chk
, sha1_hash const& hash
, F f)
{
@ -96,7 +97,7 @@ namespace libtorrent
if (chk)
{
mutex::scoped_lock l(chk->m_mutex);
detail::piece_checker_data* d = chk->find_torrent(hash);
aux::piece_checker_data* d = chk->find_torrent(hash);
if (d != 0) return f(*d->torrent_ptr);
}
@ -253,7 +254,7 @@ namespace libtorrent
{
mutex::scoped_lock l(m_chk->m_mutex);
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
aux::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
if (d != 0)
{
if (!d->processing)
@ -287,7 +288,7 @@ namespace libtorrent
{
mutex::scoped_lock l(m_chk->m_mutex);
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
aux::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
if (d != 0)
{
torrent_status st;
@ -404,7 +405,7 @@ namespace libtorrent
if (m_chk)
{
mutex::scoped_lock l(m_chk->m_mutex);
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
aux::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
if (d != 0) return true;
}
@ -572,7 +573,7 @@ namespace libtorrent
// once the checking is complete.
mutex::scoped_lock l2(m_chk->m_mutex);
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
aux::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
if (d == 0) throw_invalid_handle();
d->peers.push_back(adr);
return;

View File

@ -46,16 +46,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/io.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/aux_/session_impl.hpp"
using namespace boost::posix_time;
using boost::bind;
using boost::shared_ptr;
using libtorrent::detail::session_impl;
using libtorrent::aux::session_impl;
namespace libtorrent
{
web_peer_connection::web_peer_connection(
detail::session_impl& ses
session_impl& ses
, boost::weak_ptr<torrent> t
, boost::shared_ptr<stream_socket> s
, tcp::endpoint const& remote
@ -66,11 +67,11 @@ namespace libtorrent
{
INVARIANT_CHECK;
m_max_out_request_queue = ses.m_settings.urlseed_pipeline_size;
m_max_out_request_queue = ses.settings().urlseed_pipeline_size;
// since this is a web seed, change the timeout
// according to the settings.
set_timeout(ses.m_settings.urlseed_timeout);
set_timeout(ses.settings().urlseed_timeout);
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << "*** web_peer_connection\n";
#endif
@ -141,7 +142,7 @@ namespace libtorrent
m_requests.push_back(r);
bool using_proxy = false;
if (!m_ses.m_settings.proxy_ip.empty())
if (!m_ses.settings().proxy_ip.empty())
using_proxy = true;
if (single_file_request)
@ -155,13 +156,13 @@ namespace libtorrent
if (m_first_request)
{
request += "\r\nUser-Agent: ";
request += m_ses.m_settings.user_agent;
request += m_ses.settings().user_agent;
}
if (using_proxy && !m_ses.m_settings.proxy_login.empty())
if (using_proxy && !m_ses.settings().proxy_login.empty())
{
request += "\r\nProxy-Authorization: Basic ";
request += base64encode(m_ses.m_settings.proxy_login + ":"
+ m_ses.m_settings.proxy_password);
request += base64encode(m_ses.settings().proxy_login + ":"
+ m_ses.settings().proxy_password);
}
if (using_proxy)
{
@ -208,13 +209,13 @@ namespace libtorrent
if (m_first_request)
{
request += "\r\nUser-Agent: ";
request += m_ses.m_settings.user_agent;
request += m_ses.settings().user_agent;
}
if (using_proxy && !m_ses.m_settings.proxy_login.empty())
if (using_proxy && !m_ses.settings().proxy_login.empty())
{
request += "\r\nProxy-Authorization: Basic ";
request += base64encode(m_ses.m_settings.proxy_login + ":"
+ m_ses.m_settings.proxy_password);
request += base64encode(m_ses.settings().proxy_login + ":"
+ m_ses.settings().proxy_password);
}
if (using_proxy)
{

View File

@ -1,10 +1,16 @@
#include "libtorrent/session.hpp"
#include "libtorrent/hasher.hpp"
#include <fstream>
#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include "test.hpp"
using boost::filesystem::remove_all;
using boost::filesystem::create_directory;
void sleep(int msec)
{
boost::xtime xt;

View File

@ -2,10 +2,13 @@
#include "libtorrent/hasher.hpp"
#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/filesystem/operations.hpp>
#include "test.hpp"
#include "setup_transfer.hpp"
using boost::filesystem::remove_all;
void test_transfer(bool clear_files = true, bool disconnect = false)
{
using namespace libtorrent;

View File

@ -1,6 +1,7 @@
#include "libtorrent/storage.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include <boost/utility.hpp>
#include <boost/filesystem/operations.hpp>
@ -80,7 +81,7 @@ int test_main()
// make sure the piece_manager can identify the pieces
piece_manager pm(info, initial_path());
boost::mutex lock;
libtorrent::detail::piece_checker_data d;
libtorrent::aux::piece_checker_data d;
std::vector<bool> pieces;
num_pieces = 0;