ELinks 0.18.0
connection.c File Reference
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "elinks.h"
#include "cache/cache.h"
#include "config/options.h"
#include "document/document.h"
#include "encoding/encoding.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "main/select.h"
#include "main/timer.h"
#include "network/connection.h"
#include "network/dns.h"
#include "network/progress.h"
#include "network/socket.h"
#include "network/ssl/ssl.h"
#include "protocol/http/http.h"
#include "protocol/protocol.h"
#include "protocol/proxy.h"
#include "protocol/uri.h"
#include "session/session.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
#include "util/time.h"
Include dependency graph for connection.c:

Data Structures

struct  keepalive_connection
struct  host_connection

Functions

static void check_keepalive_connections (void)
static void notify_connection_callbacks (struct connection *conn)
static connection_priority_T get_priority (struct connection *conn)
int get_connections_count (void)
int get_keepalive_connections_count (void)
int get_connections_connecting_count (void)
int get_connections_transfering_count (void)
static int connection_disappeared (struct connection *conn, unsigned int id)
 Check whether the pointer conn still points to a connection with the given id.
static struct host_connectionget_host_connection (struct connection *conn)
static int add_host_connection (struct connection *conn)
static void done_host_connection (struct connection *conn)
static void sort_queue ()
static void check_queue_bugs (void)
static void set_connection_socket_state (struct socket *socket, struct connection_state state)
static void set_connection_socket_timeout (struct socket *socket, struct connection_state state)
static void retry_connection_socket (struct socket *socket, struct connection_state state)
static void done_connection_socket (struct socket *socket, struct connection_state state)
static struct connectioninit_connection (struct uri *uri, struct uri *proxied_uri, struct uri *referrer, off_t start, cache_mode_T cache_mode, connection_priority_T priority)
static void update_connection_progress (struct connection *conn)
static void stat_timer (struct connection *conn)
 Progress timer callback for conn->progress.
static void upload_stat_timer (struct connection *conn)
 Progress timer callback for conn->upload_progress.
void set_connection_state (struct connection *conn, struct connection_state state)
void shutdown_connection_stream (struct connection *conn)
static void free_connection_data (struct connection *conn)
static void done_connection (struct connection *conn)
static void add_to_queue (struct connection *conn)
static int do_keepalive_connection_callback (struct keepalive_connection *keep_conn)
static void done_keepalive_connection (struct keepalive_connection *keep_conn)
static struct keepalive_connectioninit_keepalive_connection (struct connection *conn, long timeout_in_seconds, void(*done)(struct connection *))
static struct keepalive_connectionget_keepalive_connection (struct connection *conn)
int has_keepalive_connection (struct connection *conn)
void add_keepalive_connection (struct connection *conn, long timeout_in_seconds, void(*done)(struct connection *))
static void keepalive_timer (void *x)
static void abort_all_keepalive_connections (void)
static void interrupt_connection (struct connection *conn)
static void suspend_connection (struct connection *conn)
static void run_connection (struct connection *conn)
void abort_connection (struct connection *conn, struct connection_state state)
void retry_connection (struct connection *conn, struct connection_state state)
static int try_to_suspend_connection (struct connection *conn, struct uri *uri)
static int try_connection (struct connection *conn, int max_conns_to_host, int max_conns)
static void check_queue (void)
int register_check_queue (void)
int load_uri (struct uri *uri, struct uri *referrer, struct download *download, connection_priority_T pri, cache_mode_T cache_mode, off_t start)
void cancel_download (struct download *download, int interrupt)
void move_download (struct download *old, struct download *new_, connection_priority_T newpri)
void detach_connection (struct download *download, off_t pos)
static void connection_timeout (struct connection *conn)
static void connection_timeout_1 (struct connection *conn)
void set_connection_timeout (struct connection *conn)
static void connection_timeout_xhr_1 (struct connection *conn)
void set_connection_timeout_xhr (struct connection *conn, milliseconds_T timeout)
void abort_all_connections (void)
void abort_background_connections (void)
int is_entry_used (struct cache_entry *cached)

Variables

static unsigned int connection_id = 0
static int active_connections = 0
static timer_id_T keepalive_timeout = TIMER_ID_UNDEF
static struct connection list connection_queue = { D_LIST_HEAD_EL(connection_queue) }
static struct host_connection list host_connections = { D_LIST_HEAD_EL(host_connections) }
static struct keepalive_connection list keepalive_connections = { D_LIST_HEAD_EL(keepalive_connections) }

Function Documentation

◆ abort_all_connections()

void abort_all_connections ( void )

◆ abort_all_keepalive_connections()

void abort_all_keepalive_connections ( void )
inlinestatic

◆ abort_background_connections()

void abort_background_connections ( void )

◆ abort_connection()

void abort_connection ( struct connection * conn,
struct connection_state state )

◆ add_host_connection()

int add_host_connection ( struct connection * conn)
static

◆ add_keepalive_connection()

void add_keepalive_connection ( struct connection * conn,
long timeout_in_seconds,
void(* done )(struct connection *) )

◆ add_to_queue()

void add_to_queue ( struct connection * conn)
inlinestatic

◆ cancel_download()

void cancel_download ( struct download * download,
int interrupt )

◆ check_keepalive_connections()

void check_keepalive_connections ( void )
static

◆ check_queue()

void check_queue ( void )
static

◆ check_queue_bugs()

void check_queue_bugs ( void )
static

◆ connection_disappeared()

int connection_disappeared ( struct connection * conn,
unsigned int id )
inlinestatic

Check whether the pointer conn still points to a connection with the given id.

If the struct connection has already been freed, this returns 0. By comparing connection.id, this function can usually detect even the case where a different connection has been created at the same address. For that to work, the caller must save the connection.id before the connection can be deleted.

◆ connection_timeout()

void connection_timeout ( struct connection * conn)
static

◆ connection_timeout_1()

void connection_timeout_1 ( struct connection * conn)
static

◆ connection_timeout_xhr_1()

void connection_timeout_xhr_1 ( struct connection * conn)
static

◆ detach_connection()

void detach_connection ( struct download * download,
off_t pos )

◆ do_keepalive_connection_callback()

int do_keepalive_connection_callback ( struct keepalive_connection * keep_conn)
static

◆ done_connection()

void done_connection ( struct connection * conn)
static

◆ done_connection_socket()

void done_connection_socket ( struct socket * socket,
struct connection_state state )
static

◆ done_host_connection()

void done_host_connection ( struct connection * conn)
static

◆ done_keepalive_connection()

void done_keepalive_connection ( struct keepalive_connection * keep_conn)
inlinestatic

◆ free_connection_data()

void free_connection_data ( struct connection * conn)
static

◆ get_connections_connecting_count()

int get_connections_connecting_count ( void )

◆ get_connections_count()

int get_connections_count ( void )

◆ get_connections_transfering_count()

int get_connections_transfering_count ( void )

◆ get_host_connection()

struct host_connection * get_host_connection ( struct connection * conn)
static

◆ get_keepalive_connection()

struct keepalive_connection * get_keepalive_connection ( struct connection * conn)
static

◆ get_keepalive_connections_count()

int get_keepalive_connections_count ( void )

◆ get_priority()

connection_priority_T get_priority ( struct connection * conn)
static

◆ has_keepalive_connection()

int has_keepalive_connection ( struct connection * conn)

◆ init_connection()

struct connection * init_connection ( struct uri * uri,
struct uri * proxied_uri,
struct uri * referrer,
off_t start,
cache_mode_T cache_mode,
connection_priority_T priority )
static

◆ init_keepalive_connection()

struct keepalive_connection * init_keepalive_connection ( struct connection * conn,
long timeout_in_seconds,
void(* done )(struct connection *) )
static

◆ interrupt_connection()

void interrupt_connection ( struct connection * conn)
static

◆ is_entry_used()

int is_entry_used ( struct cache_entry * cached)

◆ keepalive_timer()

void keepalive_timer ( void * x)
static

◆ load_uri()

int load_uri ( struct uri * uri,
struct uri * referrer,
struct download * download,
connection_priority_T pri,
cache_mode_T cache_mode,
off_t start )

◆ move_download()

void move_download ( struct download * old,
struct download * new_,
connection_priority_T newpri )

◆ notify_connection_callbacks()

void notify_connection_callbacks ( struct connection * conn)
static

◆ register_check_queue()

int register_check_queue ( void )

◆ retry_connection()

void retry_connection ( struct connection * conn,
struct connection_state state )

◆ retry_connection_socket()

void retry_connection_socket ( struct socket * socket,
struct connection_state state )
static

◆ run_connection()

void run_connection ( struct connection * conn)
static

◆ set_connection_socket_state()

void set_connection_socket_state ( struct socket * socket,
struct connection_state state )
static

◆ set_connection_socket_timeout()

void set_connection_socket_timeout ( struct socket * socket,
struct connection_state state )
static

◆ set_connection_state()

void set_connection_state ( struct connection * conn,
struct connection_state state )

◆ set_connection_timeout()

void set_connection_timeout ( struct connection * conn)

◆ set_connection_timeout_xhr()

void set_connection_timeout_xhr ( struct connection * conn,
milliseconds_T timeout )

◆ shutdown_connection_stream()

void shutdown_connection_stream ( struct connection * conn)

◆ sort_queue()

void sort_queue ( void )
static

◆ stat_timer()

void stat_timer ( struct connection * conn)
static

Progress timer callback for conn->progress.

◆ suspend_connection()

void suspend_connection ( struct connection * conn)
inlinestatic

◆ try_connection()

int try_connection ( struct connection * conn,
int max_conns_to_host,
int max_conns )
inlinestatic

◆ try_to_suspend_connection()

int try_to_suspend_connection ( struct connection * conn,
struct uri * uri )
static

◆ update_connection_progress()

void update_connection_progress ( struct connection * conn)
static

◆ upload_stat_timer()

void upload_stat_timer ( struct connection * conn)
static

Progress timer callback for conn->upload_progress.

Variable Documentation

◆ active_connections

int active_connections = 0
static

◆ connection_id

unsigned int connection_id = 0
static

◆ connection_queue

struct connection list connection_queue = { D_LIST_HEAD_EL(connection_queue) }
static

◆ host_connections

struct host_connection list host_connections = { D_LIST_HEAD_EL(host_connections) }
static

◆ keepalive_connections

struct keepalive_connection list keepalive_connections = { D_LIST_HEAD_EL(keepalive_connections) }
static

◆ keepalive_timeout

timer_id_T keepalive_timeout = TIMER_ID_UNDEF
static