1 #ifndef EL__NETWORK_CONNECTION_H
2 #define EL__NETWORK_CONNECTION_H
4 #include "cache/cache.h"
5 #include "encoding/encoding.h"
6 #include "main/timer.h" /* timer_id_T */
7 #include "network/state.h"
8 #include "util/lists.h"
17 LIST_HEAD(struct connection
);
19 LIST_OF(struct download
) downloads
;
20 struct progress
*progress
;
22 /* If no proxy is used uri and proxied_uri are the same. */
24 struct uri
*proxied_uri
;
27 /* Cache information. */
28 enum cache_mode cache_mode
;
29 struct cache_entry
*cached
;
31 off_t from
; /* Position for new data in the cache entry. */
32 off_t received
; /* The number of received bytes. */
33 off_t est_length
; /* Estimated number of bytes to transfer. */
35 enum stream_encoding content_encoding
;
36 struct stream_encoded
*stream
;
38 /* Called if non NULL when shutting down a connection. */
39 void (*done
)(struct connection
*);
43 enum connection_state state
;
44 enum connection_state prev_error
;
46 /* The communication socket with the other side. */
47 struct socket
*socket
;
48 /* The data socket. It is used, when @socket is used for the control,
49 * and the actual data is transmitted through a different channel. */
50 /* The only users now are FTP, FSP, and SMB. */
51 struct socket
*data_socket
;
57 unsigned int running
:1;
58 unsigned int unrestartable
:1;
59 unsigned int detached
:1;
62 /* Each document is downloaded with some priority. When downloading a
63 * document, the existing connections are checked to see if a
64 * connection to the host already exists before creating a new one. If
65 * it finds out that something had that idea earlier and connection for
66 * download of the very same URL is active already, it just attaches
67 * the struct download it got to the connection, _and_ updates its @pri
68 * array by the priority it has thus, sum of values in all fields of
69 * @pri is also kinda refcount of the connection. */
72 /* Private protocol specific info. If non-NULL it is free()d when
73 * stopping the connection. */
77 int register_check_queue(void);
79 int get_connections_count(void);
80 int get_keepalive_connections_count(void);
81 int get_connections_connecting_count(void);
82 int get_connections_transfering_count(void);
84 void set_connection_state(struct connection
*, enum connection_state
);
86 int has_keepalive_connection(struct connection
*);
87 void add_keepalive_connection(struct connection
*conn
, long timeout_in_seconds
,
88 void (*done
)(struct connection
*));
90 void abort_connection(struct connection
*, enum connection_state
);
91 void retry_connection(struct connection
*, enum connection_state
);
93 void cancel_download(struct download
*download
, int interrupt
);
94 void move_download(struct download
*old
, struct download
*new,
95 enum connection_priority newpri
);
97 void detach_connection(struct download
*, off_t
);
98 void abort_all_connections(void);
99 void abort_background_connections(void);
101 void set_connection_timeout(struct connection
*);
103 void shutdown_connection_stream(struct connection
*conn
);
105 /* Initiates a connection to get the given @uri. */
106 /* Note that stat's data _MUST_ be struct file_download * if start > 0! Yes,
107 * that should be probably something else than data, but... ;-) */
108 /* Returns 0 on success and -1 on failure. */
109 int load_uri(struct uri
*uri
, struct uri
*referrer
, struct download
*download
,
110 enum connection_priority pri
, enum cache_mode cache_mode
, off_t start
);
112 int is_entry_used(struct cache_entry
*cached
);