From 105f8a6504f317f7008c668380e1ce76fc2ca2c0 Mon Sep 17 00:00:00 2001 From: dedok Date: Wed, 14 Nov 2012 01:36:39 +0400 Subject: [PATCH] #21 #20 #18 #17 + code improve --- release note.txt | 30 +++++- src/apps/full_model.cpp | 2 +- .../details/http_mongoose_transport.cpp | 47 ++++++---- src/core/common/setting_manager.cpp | 2 +- .../http_server/details/file_info_buffer.cpp | 93 +++++++++---------- .../http_server/details/file_info_buffer.hpp | 10 +- src/core/http_server/http_server_core.cpp | 73 +++++++++------ .../sequential_torrent_controller.cpp | 12 ++- src/core/torrent_core/torrent_info.cpp | 6 +- src/core/torrent_core/torrent_info.hpp | 4 +- src/tests/core_tests/http_server.cpp | 22 ++++- 11 files changed, 179 insertions(+), 122 deletions(-) diff --git a/release note.txt b/release note.txt index e3a23fe..1c40c8c 100644 --- a/release note.txt +++ b/release note.txt @@ -1,16 +1,35 @@ +torrent to http (t2h) release note + +*-----------------------------------------------------* version 1.4.1.2 libcommon - --added new http transport based on mongoose; + --added new http transport implementation based on libmongoose(embedded by me in t2h); --fixed hang connection in http transport; --added uri specs validator(for wrong slashes); + --fixed infinity loop in common::notification_unit::execution_loop; + --performance tuning of notification_model; + --fixed hang in t2h_core::details::file_info_buffer(buffer for files information)::wait_avaliable_bytes; http_core --update Partial-Content handling, buffered sending of http body; + --added workaraund for vlc web-straming; --added more strong file information sync with torrent_core; --add Date/ETag headers to Partial-Content reply; - -- + --fixed crash under Windwos in file_info::on_add_file; + --performance tuning; + --added workaraund for libtorrent(1.6.3) + issue: pieces migth not write to file at the momemt of event came from libtorrent session; + +torrent_core + --fixed wrong piece length calculation; + --fixed avaliable bytes calculation for on_progress notification(for case avaliable bytes > file size); + --performance tuning; + +settings manager + --update defaults values/keys; +*-----------------------------------------------------* version 1.2.9.6 libcommon @@ -18,6 +37,7 @@ libcommon --fixed crash inside notification_unit(notify_recv at std::list::erase call) under Windows; --fixed crash inside systemlogger api; +*-----------------------------------------------------* version 1.2.9.5 libcommon @@ -29,6 +49,7 @@ tests settings manager --update default value for hc_max_sync_timeout(120 sec) +*-----------------------------------------------------* version 1.2.9.2 http core @@ -58,7 +79,8 @@ tests --add http request test; --add http server test; --add notification center test; - + +*-----------------------------------------------------* version 1.0.1.1 http core @@ -80,4 +102,4 @@ settings_manager(settings) full_model --fixed crash on NULL value return from get_torrent_files(); - + \ No newline at end of file diff --git a/src/apps/full_model.cpp b/src/apps/full_model.cpp index 2e5ed64..137e827 100644 --- a/src/apps/full_model.cpp +++ b/src/apps/full_model.cpp @@ -83,7 +83,7 @@ void dispatch_text_command(char const * ibuf, std::size_t ibuf_size, bool & exit int main(int argc, char ** argv) { sig_state.sig_exit = false; - std::cin.get(); + try { #if defined(UNIX) || defined(__APPLE__) diff --git a/src/common/network/details/http_mongoose_transport.cpp b/src/common/network/details/http_mongoose_transport.cpp index 8ac705a..c23e4ed 100644 --- a/src/common/network/details/http_mongoose_transport.cpp +++ b/src/common/network/details/http_mongoose_transport.cpp @@ -28,13 +28,16 @@ static inline bool mon_is_range_request( { BOOST_ASSERT(ri != NULL); - if (strcmp(ri->http_version, "1.1") != 0 && strcmp(ri->request_method, "GET") != 0) + if (strcmp(ri->http_version, "1.1") != 0) + return false; + + if (strcmp(ri->request_method, "GET") != 0) return false; char const * range_header = mg_get_header(conn, "Range"); if (range_header) return utility::http_translate_range_header(rheader, range_header); - + char const * accept_header = mg_get_header(conn, "Accept"); if (accept_header) return utility::http_translate_accept_header(rheader, range_header); @@ -68,7 +71,7 @@ static void * mongoose_completion_routine(enum mg_event event, struct mg_connect } /* mics helpers */ -static void * http_stok_reply( +static void * http_stock_reply( struct mg_connection * conn, http_transport_event_handler::operation_status status, http_transport_event_handler_ptr far_handler, @@ -105,34 +108,45 @@ static void * far_handler_on_range_request( http_transport_event_handler::http_data pcd; std::string const uri = utility::http_normalize_uri_c(ri->uri); - far_handler->on_get_partial_content_headers(pcd, rheader.bstart_1, rheader.bend_1, uri.c_str()); - if (pcd.op_status != http_transport_event_handler::ok) - return http_stok_reply(conn, pcd.op_status, far_handler, ri); + far_handler->on_get_partial_content_headers(pcd, rheader.bstart_1, rheader.bend_1, uri.c_str()); + if (pcd.op_status != http_transport_event_handler::ok) + return http_stock_reply(conn, pcd.op_status, far_handler, ri); + if (mg_write(conn, pcd.reply_header.c_str(), pcd.reply_header.size()) > 0) { bool has_data = true; pcd.seek_offset_pos = rheader.bstart_1; - for (boost::int64_t bytes_writed = 0;;) { - has_data = - far_handler->on_get_content_body(pcd, rheader.bstart_1, rheader.bend_1, bytes_writed, uri.c_str()); + for (boost::int64_t bytes_writed = 0;;) + { + has_data = far_handler->on_get_content_body(pcd, + rheader.bstart_1, + rheader.bend_1, + bytes_writed, + uri.c_str()); + + if (pcd.op_status != http_transport_event_handler::ok) + return http_stock_reply(conn, pcd.op_status, far_handler, ri); + if ((bytes_writed = mg_write(conn, &pcd.io_buffer.at(0), pcd.last_readed)) <= 0) { - LC_WARNING("writing body data failed, for uri '%s'", uri.c_str()) far_handler->error(http_transport_event_handler::write_op_error, uri.c_str()); break; } // if - if (!has_data) + + if (!has_data) break; } // read & send loop return NOT_NULL; } + LC_WARNING("writing header data failed, for uri '%s'", uri.c_str()) - return NULL; + return NOT_NULL; } static void * far_handler_on_head_request( transport_context_ptr far_handler, struct mg_connection * conn, struct mg_request_info const * ri) { BOOST_ASSERT(ri != NULL); + // TODO impl this return NULL; } @@ -140,6 +154,7 @@ static void * far_handler_on_content_request( transport_context_ptr far_handler, struct mg_connection * conn, struct mg_request_info const * ri) { BOOST_ASSERT(ri != NULL); + // TODO impl this return NULL; } @@ -233,7 +248,7 @@ void * http_mongoose_transport::dispatch_http_message( switch (event) { - case MG_NEW_REQUEST : + case MG_NEW_REQUEST : if (mon_is_range_request(conn, ri, rheader)) return far_handler_on_range_request(http_context_, conn, ri, rheader); else if(mon_is_head_request(conn, ri)) @@ -241,11 +256,10 @@ void * http_mongoose_transport::dispatch_http_message( else if (mon_is_content_requst(conn, ri)) return far_handler_on_content_request(http_context_, conn, ri); break; - + case MG_HTTP_ERROR : - LC_WARNING("error detected, code '%i', for uri '%s'", (long) ri->ev_data, ri->uri) return NULL; - + case MG_REQUEST_COMPLETE : return NULL; @@ -254,7 +268,6 @@ void * http_mongoose_transport::dispatch_http_message( } // switch STD_EXCEPTION_HANDLE_END - return NULL; } diff --git a/src/core/common/setting_manager.cpp b/src/core/common/setting_manager.cpp index 0f3c5d9..06a7ce6 100644 --- a/src/core/common/setting_manager.cpp +++ b/src/core/common/setting_manager.cpp @@ -33,7 +33,7 @@ ADD_KEY_TYPE(tc_port_end, "", "", true) // torrent core keys, with some defaults values ADD_KEY_TYPE(cores_sync_timeout, "260", "", false) ADD_KEY_TYPE(max_size_for_reply, "102400", "", false) -ADD_KEY_TYPE(tc_max_alert_wait_time, "15", "", false) +ADD_KEY_TYPE(tc_max_alert_wait_time, "10", "", false) ADD_KEY_TYPE(tc_max_partial_download_size, "5242880", "", false) ADD_KEY_TYPE(tc_root, "", "doc_root", false) ADD_KEY_TYPE(tc_futures_timeout, "10", "", false) diff --git a/src/core/http_server/details/file_info_buffer.cpp b/src/core/http_server/details/file_info_buffer.cpp index 2133e38..4444de5 100644 --- a/src/core/http_server/details/file_info_buffer.cpp +++ b/src/core/http_server/details/file_info_buffer.cpp @@ -4,10 +4,10 @@ #include "core_notification_center.hpp" #include "file_info_buffer_realtime_updater.hpp" +#include #include #include -#define T2H_DEEP_DEBUG #define HCORE_FIB_UPDATER_NAME "hcore_notification_recv"; namespace t2h_core { namespace details { @@ -37,54 +37,42 @@ file_info_buffer::file_info_buffer() file_info_buffer::~file_info_buffer() { core_notification_center()->remove_notification_receiver(updater_.recv_name); + boost::mutex::scoped_lock guard(lock_); + guard.unlock(); + waiter_.notify_one(); } bool file_info_buffer::wait_avaliable_bytes( std::string const & file_path, boost::int64_t avaliable_bytes, std::size_t secs) { + /* */ using boost::posix_time::seconds; - bool state = false; hc_file_info_ptr finfo; - - if ((finfo = get_info(file_path))) - { - if (finfo->avaliable_bytes >= avaliable_bytes) { -#if defined(T2H_DEEP_DEBUG) - HCORE_TRACE("for path '%s', bytes avaliable '%i', bytes requested '%i'", - finfo->file_path.c_str(), finfo->avaliable_bytes, avaliable_bytes) -#endif // T2H_DEEP_DEBUG - return true; - } - boost::unique_lock guard(finfo->waiter_lock); - for (boost::system_time timeout; - ; - timeout = boost::get_system_time() + seconds(secs)) - { + + if ((finfo = get_info(file_path))) { + boost::mutex::scoped_lock guard(lock_); + for (;;) { + if (finfo->avaliable_bytes >= avaliable_bytes) { #if defined(T2H_DEEP_DEBUG) - HCORE_TRACE("for path '%s', bytes avaliable '%i', bytes requested '%i'", - finfo->file_path.c_str(), finfo->avaliable_bytes, avaliable_bytes) + HCORE_TRACE("wait bytes for path '%s' finished", finfo->file_path.c_str()) #endif // T2H_DEEP_DEBUG - if (finfo->avaliable_bytes >= avaliable_bytes) { - state = true; - break; + return true; } - - if (!(state = finfo->waiter.timed_wait(guard, timeout))) { -#if defined(T2H_DEEP_DEBUG) - HCORE_WARNING("for path '%s' waiting bytes failed", finfo->file_path.c_str()) -#endif // T2H_DEEP_DEBUG - break; + boost::system_time timeout = boost::get_system_time() + seconds(secs); + if (!waiter_.timed_wait(guard, timeout)) { + HCORE_WARNING("wait bytes for path '%s' failed", finfo->file_path.c_str()) + return false; } } // wait loop } // state - - return state; + HCORE_WARNING("finfo not valid for path '%s'", file_path.c_str()) + return false; } void file_info_buffer::remove_info(std::string const & path) { - boost::lock_guard guard(lock_); + boost::mutex::scoped_lock guard(lock_); infos_type::iterator found = infos_.find(path); if (found != infos_.end()) { #if defined(T2H_DEEP_DEBUG) @@ -96,37 +84,45 @@ void file_info_buffer::remove_info(std::string const & path) void file_info_buffer::update_info(hc_file_info_ptr info) { - boost::lock_guard guard(lock_); + BOOST_ASSERT(info != NULL); + boost::mutex::scoped_lock guard(lock_); + infos_type::iterator found = infos_.find(info->file_path); - if (found != infos_.end()) { + if (found == infos_.end()) { + HCORE_WARNING("update info failed, item not found", info->file_path.c_str()) + return; + } #if defined(T2H_DEEP_DEBUG) - HCORE_TRACE("updating existing file info entry '%s', bytes avaliable '"SL_SSIZE_T"'", - info->file_path.c_str(), info->avaliable_bytes) + HCORE_TRACE("updating existing file info entry '%s', bytes avaliable '"SL_SSIZE_T"'", + info->file_path.c_str(), info->avaliable_bytes) #endif // T2H_DEEP_DEBUG - found->second->file_size = info->file_size; - found->second->avaliable_bytes = info->avaliable_bytes; - found->second->waiter.notify_all(); - } + found->second->file_size = info->file_size; + found->second->avaliable_bytes = info->avaliable_bytes; + guard.unlock(); + waiter_.notify_one(); } void file_info_buffer::update_info(std::string const & file_path, boost::int64_t avaliable_bytes) { - boost::lock_guard guard(lock_); + boost::mutex::scoped_lock guard(lock_); + infos_type::iterator found = infos_.find(file_path); - if (found != infos_.end()) { + if (found == infos_.end()) { + HCORE_WARNING("update info failed, item not found", file_path.c_str()) + return; + } #if defined(T2H_DEEP_DEBUG) - HCORE_TRACE("updating existing file info entry '%s', bytes avaliable '"SL_SSIZE_T"'", - found->second->file_path.c_str(), avaliable_bytes) + HCORE_TRACE("updating existing item '%s', bytes avaliable '"SL_SSIZE_T"'", + found->second->file_path.c_str(), avaliable_bytes) #endif // T2H_DEEP_DEBUG - - found->second->avaliable_bytes = avaliable_bytes; - found->second->waiter.notify_all(); - } + found->second->avaliable_bytes = avaliable_bytes; + guard.unlock(); + waiter_.notify_one(); } hc_file_info_ptr file_info_buffer::get_info(std::string const & path) const { - boost::lock_guard guard(lock_); + boost::mutex::scoped_lock guard(lock_); infos_type::const_iterator found = infos_.find(path); if (found != infos_.end()) return found->second; @@ -140,4 +136,3 @@ hc_file_info_ptr file_info_buffer::get_info(std::string const & path) const } } // namespace t2h_core, details #undef HCORE_FIB_UPDATER_NAME - diff --git a/src/core/http_server/details/file_info_buffer.hpp b/src/core/http_server/details/file_info_buffer.hpp index 7168662..5414b99 100644 --- a/src/core/http_server/details/file_info_buffer.hpp +++ b/src/core/http_server/details/file_info_buffer.hpp @@ -17,7 +17,7 @@ namespace t2h_core { namespace details { */ struct hc_file_info : boost::noncopyable { hc_file_info() - : file_path(""), file_size(0), avaliable_bytes(0), waiter_lock(), waiter() + : file_path(""), file_size(0), avaliable_bytes(0) { } @@ -25,17 +25,13 @@ struct hc_file_info : boost::noncopyable { std::string const & file_path_, boost::int64_t file_size_, boost::int64_t avaliable_bytes_) : file_path(file_path_), file_size(file_size_), - avaliable_bytes(avaliable_bytes_), - waiter_lock(), - waiter() + avaliable_bytes(avaliable_bytes_) { } std::string file_path; // Path to file(this use as key to find hc_file_info) boost::int64_t file_size; // File size(real) boost::int64_t avaliable_bytes; // Current file_size - boost::mutex mutable waiter_lock; // Waiter for wait_avaliable_bytes(notified via add/update) - boost::condition_variable mutable waiter; // Waiter locker }; typedef boost::shared_ptr hc_file_info_ptr; @@ -80,6 +76,8 @@ public : private : boost::mutex mutable lock_; + boost::condition_variable waiter_; + infos_type infos_; struct { std::string mutable recv_name; diff --git a/src/core/http_server/http_server_core.cpp b/src/core/http_server/http_server_core.cpp index 72454c3..5f67b38 100644 --- a/src/core/http_server/http_server_core.cpp +++ b/src/core/http_server/http_server_core.cpp @@ -36,8 +36,8 @@ inline static details::hsc_local_config hcs_from_setting_manager(setting_manager { details::hsc_local_config const hcsc = { setting_manager->get_value("doc_root"), - setting_manager->get_value("cores_sync_timeout"), - setting_manager->get_value("max_size_for_reply") + 320, + 1024*1000 }; boost::system::error_code error; @@ -167,9 +167,10 @@ void http_server_core::on_get_partial_content_headers( std::string const req_path = local_config_.doc_root + uri; if (!(fi = file_info_buffer_->get_info(req_path))) { + HCORE_WARNING("can not find path '%s' in buffer", req_path.c_str()) http_d.op_status = common::http_transport_event_handler::not_found; return; - } + } // if // if client wish whole file the passed bytes_end == 0 if (bytes_end == 0) bytes_end = fi->file_size - 1; @@ -178,6 +179,16 @@ void http_server_core::on_get_partial_content_headers( content_size = (content_size > fi->file_size ? fi->file_size : content_size); std::string const gmt_time = utility::http_get_gmt_time_string(); + if (!file_info_buffer_->wait_avaliable_bytes( + fi, + 1024*1000, + 360)) + { + HCORE_WARNING("sync with file system failed, timeout expired, for path '%s'", req_path.c_str()) + http_d.op_status = common::http_transport_event_handler::io_error; + return; + } // if + /* NOTE : Prepare Etag, Date, Last-Modified headers. Must be in UTC, according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.*/ http_d.reply_header = "HTTP/1.1 206 Partial-Content\r\n"; @@ -233,59 +244,60 @@ bool http_server_core::on_get_content_body( std::string const req_path = local_config_.doc_root + uri; std::ios::openmode const open_mode = std::ios::in | std::ios::binary; - if (cur_state_ == base_service::service_stoped) + http_d.last_readed = 0; + + if (cur_state_ == base_service::service_stoped) return false; if (!(fi = file_info_buffer_->get_info(req_path))) { - HCORE_WARNING("can not find item by path '%s'", req_path.c_str()); http_d.op_status = common::http_transport_event_handler::not_found; return false; } // if - // if client wish whole file the bytes_end var will == 0 + // if client wish whole file the bytes_end var will equal to 0 if (bytes_end == 0) - bytes_end = fi->file_size - 1; + bytes_end = fi->file_size; - boost::int64_t read_offset = local_config_.max_read_offset; + boost::int64_t read_offset = 1 * (bytes_end - bytes_start) + 1; + if (1024*1000 <= read_offset) + read_offset = 1024*1000; + if (http_d.seek_offset_pos + read_offset > fi->file_size) + read_offset = fi->file_size; + if (!file_info_buffer_->wait_avaliable_bytes( - fi, http_d.seek_offset_pos + read_offset, - local_config_.fs_cores_sync_timeout)) + fi, + http_d.seek_offset_pos + read_offset + 100, + 360)) { - HCORE_WARNING("sync with file system failed, timeout expired, for path '%s'", req_path.c_str()) http_d.op_status = common::http_transport_event_handler::io_error; return false; } // if - - bool end = false; + + bool has_next_data_block = true; io::file_descriptor_source file_handle(req_path, open_mode); if (file_handle.is_open()) { - if (http_d.io_buffer.empty()) + if (http_d.io_buffer.size() < read_offset) http_d.io_buffer.resize(read_offset + 1); - if (http_d.seek_offset_pos > bytes_end) { - end = true; + + if (http_d.seek_offset_pos >= bytes_end) { + has_next_data_block = false; http_d.seek_offset_pos = 1 * (bytes_end - (1 * (bytes_start - http_d.seek_offset_pos))); - } else if (http_d.seek_offset_pos == bytes_end) - return false; + } // if - if (io::seek(file_handle, http_d.seek_offset_pos, BOOST_IOS::beg) < 0) { - HCORE_WARNING("seek file to pos '%i' failed for path '%s'", - http_d.seek_offset_pos, req_path.c_str()) + if (io::seek(file_handle, http_d.seek_offset_pos, BOOST_IOS::beg) < 0) return false; - } - else if ((http_d.last_readed = + + if ((http_d.last_readed = io::read(file_handle, &http_d.io_buffer.at(0), read_offset)) <= 0) { return false; - } - - if (end || http_d.last_readed < local_config_.max_read_offset) - return false; + } // if http_d.seek_offset_pos += read_offset; - return true; + return has_next_data_block; } // if - - HCORE_WARNING("open file failed, path '%s'", req_path.c_str()) + + http_d.op_status = common::http_transport_event_handler::io_error; return false; } @@ -293,6 +305,7 @@ void http_server_core::error( common::http_transport_event_handler::operation_status status, char const * uri) { HCORE_WARNING("got error from http transport, status '%i', uri '%s'", (int)status, uri); + // TODO impl this } /** diff --git a/src/core/torrent_core/sequential_torrent_controller.cpp b/src/core/torrent_core/sequential_torrent_controller.cpp index 410f795..6a5ca8b 100644 --- a/src/core/torrent_core/sequential_torrent_controller.cpp +++ b/src/core/torrent_core/sequential_torrent_controller.cpp @@ -335,14 +335,17 @@ void sequential_torrent_controller::on_piece_finished(libtorrent::piece_finished details::torrent_ex_info_ptr ex_info = shared_buffer_ref_->get(alert->handle.save_path()); if (!ex_info) { - TCORE_WARNING("get extended info failed, args '%s', '%i'", alert->handle.save_path().c_str(), alert->piece_index) + TCORE_WARNING("get extended info failed, args '%s', '%i'", + alert->handle.save_path().c_str(), alert->piece_index) torrent_remove(alert->handle); return; } // if - boost::tie(update_state, info) = details::file_info_update(ex_info->avaliables_files, alert->handle, alert->piece_index); + boost::tie(update_state, info) = + details::file_info_update(ex_info->avaliables_files, alert->handle, alert->piece_index); if (update_state) - event_handler_->on_progress_update(info.path, info.avaliable_bytes); + event_handler_->on_progress_update(info.path, + (info.avaliable_bytes > info.size) ? info.size : info.avaliable_bytes); } void sequential_torrent_controller::on_file_complete(libtorrent::file_completed_alert * alert) @@ -350,7 +353,8 @@ void sequential_torrent_controller::on_file_complete(libtorrent::file_completed_ details::file_info info; details::torrent_ex_info_ptr ex_info = shared_buffer_ref_->get(alert->handle.save_path()); if (!ex_info) { - TCORE_WARNING("get extended info failed, args '%s', '%i'", alert->handle.save_path().c_str(), alert->index) + TCORE_WARNING("get extended info failed, args '%s', '%i'", + alert->handle.save_path().c_str(), alert->index) torrent_remove(alert->handle); return; } // if diff --git a/src/core/torrent_core/torrent_info.cpp b/src/core/torrent_core/torrent_info.cpp index 62b5f38..5eb89c9 100644 --- a/src/core/torrent_core/torrent_info.cpp +++ b/src/core/torrent_core/torrent_info.cpp @@ -3,6 +3,7 @@ #include "torrent_core_utility.hpp" #include +#include #include #include @@ -64,7 +65,6 @@ static void file_info_clear_priority(file_info & finfo, libtorrent::torrent_hand static inline int file_info_get_download_offset(file_info const & info, int max_partial_download_size) { - int size = info.block_size; if (max_partial_download_size > info.size) return info.pieces; @@ -93,7 +93,7 @@ file_info file_info_add(file_info::list_type & flist, int const pieces_range_first = ti.map_file(file_index, 0, 0).piece; int const pieces_range_last = ti.map_file(file_index, (std::max)(size_type(fe.size) - 1, size_type(0)), 0).piece; - int const block_size = handle.status().block_size; + int const block_size = handle.get_torrent_info().piece_length(); /* initialize file information */ info.file_index = file_index; @@ -194,7 +194,6 @@ boost::tuple ++first->pieces_download_count; if (first->total_pieces_download_count < first->pieces) ++first->total_pieces_download_count; - if (first->pieces_download_count > first->pieces_download_offset || first->total_pieces_download_count == first->pieces) { @@ -346,4 +345,3 @@ std::string torrent_info_to_json( #if defined(WIN32) # pragma warning(pop) #endif - diff --git a/src/core/torrent_core/torrent_info.hpp b/src/core/torrent_core/torrent_info.hpp index 56082cc..3e966ba 100644 --- a/src/core/torrent_core/torrent_info.hpp +++ b/src/core/torrent_core/torrent_info.hpp @@ -46,8 +46,8 @@ struct file_info { int pieces; // Pieces number in file int total_pieces_download_count; // Cound of downloaded pieces int pieces_download_count; // Count of downloaded pieces(not total) - int pieces_download_offset; // - int pieces_download_offset_min; // + int pieces_download_offset; // Pices offset for current torrent file(size) + int pieces_download_offset_min; // Same as pieces_download_offset_min(low bound) boost::int64_t avaliable_bytes; // Bytes which was downloaded and saved to the HDD(eg current size) int pieces_range_first; // File piece range start offset int pieces_range_last; // File piece range end offset diff --git a/src/tests/core_tests/http_server.cpp b/src/tests/core_tests/http_server.cpp index d8195e4..40387cf 100644 --- a/src/tests/core_tests/http_server.cpp +++ b/src/tests/core_tests/http_server.cpp @@ -1,5 +1,6 @@ #include "http_server_core.hpp" +#include "http_utility.hpp" #include "hc_event_source_adapter.hpp" #include "core_notification_center.hpp" @@ -46,9 +47,12 @@ inline static void die(std::string const & message, int exit_code) static void sig_handler(int signo) { +#if defined(__APPLE__) if (signo != SIGINT) return; - +#else + std::cin.get(); +#endif // _APPLE_ if (http_server) { http_server->stop_service(); http_server->wait_service(); @@ -114,9 +118,11 @@ public : { if (boost::filesystem::is_directory(*dir, ec)) continue; - file_data fd = { dir->path().string(), boost::filesystem::file_size(*dir, ec) }; + std::string const path = utility::http_normalize_uri(dir->path().string()); + file_data fd = { path, boost::filesystem::file_size(*dir, ec) }; if (!ec) { files_in_root_.push_back(fd); + std::cout << "traked file : " << fd.path << std::endl; event_sender_.on_file_add(fd.path, fd.size); } // if } // for @@ -124,6 +130,7 @@ public : void slow_files_info_update() { + Sleep(15000); for (std::list::iterator first = files_in_root_.begin(), last = files_in_root_.end(); first != last; ++first) @@ -131,7 +138,11 @@ public : boost::int64_t const offset = first->size / 30; boost::int64_t cur_offset = offset; while (cur_offset < first->size) { +#if defined(WIN32) + Sleep(1000); +#else sleep(1); +#endif // WIN32 cur_offset += offset; if (cur_offset > first->size) cur_offset = first->size; @@ -188,7 +199,7 @@ int main(int argc, char* argv[]) #if defined(__APPLE__) if (signal(SIGINT, sig_handler) == SIG_ERR) die("failed to add signal handler", 1); -#endif +#endif // __APPLE__ program_options po = get_options(argc, argv); LOG_INIT(log_settings) @@ -218,8 +229,11 @@ int main(int argc, char* argv[]) cns.default_files_info_update(); break; } - +#if defined(WIN32) + sig_handler(0); +#else http_server->wait_service(); +#endif //WIN32 } catch (std::exception const & expt) {