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;
63 /* Each document is downloaded with some priority. When downloading a
64 * document, the existing connections are checked to see if a
65 * connection to the host already exists before creating a new one. If
66 * it finds out that something had that idea earlier and connection for
67 * download of the very same URL is active already, it just attaches
68 * the struct download it got to the connection, _and_ updates its @pri
69 * array by the priority it has thus, sum of values in all fields of
70 * @pri is also kinda refcount of the connection. */
73 /* Private protocol specific info. If non-NULL it is free()d when
74 * stopping the connection. */
79 LIST_HEAD(struct popen_data
);
83 unsigned char *filename
;
86 extern LIST_OF(struct popen_data
) copiousoutput_data
;
88 int register_check_queue(void);
90 int get_connections_count(void);
91 int get_keepalive_connections_count(void);
92 int get_connections_connecting_count(void);
93 int get_connections_transfering_count(void);
95 void set_connection_state(struct connection
*, enum connection_state
);
97 int has_keepalive_connection(struct connection
*);
98 void add_keepalive_connection(struct connection
*conn
, long timeout_in_seconds
,
99 void (*done
)(struct connection
*));
101 void abort_connection(struct connection
*, enum connection_state
);
102 void retry_connection(struct connection
*, enum connection_state
);
104 void cancel_download(struct download
*download
, int interrupt
);
105 void move_download(struct download
*old
, struct download
*new,
106 enum connection_priority newpri
);
108 void detach_connection(struct download
*, off_t
);
109 void abort_all_connections(void);
110 void abort_background_connections(void);
112 void set_connection_timeout(struct connection
*);
114 void shutdown_connection_stream(struct connection
*conn
);
116 /* Initiates a connection to get the given @uri. */
117 /* Note that stat's data _MUST_ be struct file_download * if start > 0! Yes,
118 * that should be probably something else than data, but... ;-) */
119 /* Returns 0 on success and -1 on failure. */
120 int load_uri(struct uri
*uri
, struct uri
*referrer
, struct download
*download
,
121 enum connection_priority pri
, enum cache_mode cache_mode
, off_t start
);
123 int is_entry_used(struct cache_entry
*cached
);