summaryrefslogtreecommitdiff
blob: c1fcf6f2103dfe514be3eb4deb0d92d010c588b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
*
* Project: IDFetch.
* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
* Mentoring organization: Gentoo Linux.
* Sponsored by GSOC 2010.
*
* This file is part of Segget.
*
* Segget is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Segget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Segget; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef __CONNECTION_H__
#define __CONNECTION_H__

#include <time.h>
#include <curl/curl.h>
class Tsegment;
#include "segment.h"
#include "networkbroker.h"
#include "scriptserver.h"

using namespace std;

#define MAX_CONNECTS 20

class Tconnection{
	static uint total_connections;
	private:
		Tnetwork_distfile_broker_phases connection_start_time_network_phase_for_pf_networks;
	public:
		uint network_num;
		uint mirror_num;
		string url;
		ulong total_dld_bytes;
		ulong bytes_per_last_interval;
		uint connection_num;
		ulong max_speed_limit;
		bool active;
		timeval start_time;
		Tsegment *segment;
		Tconnection():
			connection_start_time_network_phase_for_pf_networks(E_USE_AS_LOCAL_MIRRORS),
			network_num(0),
			mirror_num(0),
			url(""),
			total_dld_bytes(0),
			bytes_per_last_interval(0),
			connection_num(0),
			max_speed_limit(0),
			active(0),
			start_time(),
			segment(0)
			{};
		Tconnection(const Tconnection &L);             // copy constructor
		Tconnection & operator=(const Tconnection &L);
		int start(CURLM *cm, uint network_number, uint distfile_num, Tsegment *started_segment, uint best_mirror_num);
		void stop(CURLcode connection_result);
		void inc_bytes_per_last_interval(ulong new_bytes_count);
		void show_connection_progress(ulong time_diff);
		string get_html_connection_progress();
};

extern long script_waiting_connection_num;
extern time_t prev_time;
extern Tconnection connection_array[MAX_CONNECTS];
void init_connections();
#endif