connection.h 2.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2004, Jack Moffitt <jack@xiph.org, 
 *                      Michael Smith <msmith@xiph.org>,
 *                      oddsock <oddsock@xiph.org>,
 *                      Karl Heyes <karl@xiph.org>
 *                      and others (see AUTHORS for details).
Philipp Schafft's avatar
Philipp Schafft committed
11
 * Copyright 2014,      Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
12 13
 */

Jack Moffitt's avatar
Jack Moffitt committed
14 15 16
#ifndef __CONNECTION_H__
#define __CONNECTION_H__

17
#include <sys/types.h>
18
#include <time.h>
19 20

#include "tls.h"
21

22
#include "icecasttypes.h"
23
#include "compat.h"
24 25
#include "common/thread/thread.h"
#include "common/net/sock.h"
26

27 28
typedef unsigned long connection_id_t;

29
struct connection_tag {
30
    connection_id_t id;
Jack Moffitt's avatar
Jack Moffitt committed
31

32
    time_t con_time;
33
    time_t discon_time;
34
    uint64_t sent_bytes;
Jack Moffitt's avatar
Jack Moffitt committed
35

36
    sock_t sock;
37 38
    listensocket_t *listensocket_real;
    listensocket_t *listensocket_effective;
39
    int error;
Jack Moffitt's avatar
Jack Moffitt committed
40

41
    tlsmode_t tlsmode;
42
    tls_t *tls;
43 44
    int (*send)(connection_t *handle, const void *buf, size_t len);
    int (*read)(connection_t *handle, void *buf, size_t len);
45

46 47 48
    void *readbuffer;
    size_t readbufferlen;

49
    char *ip;
50
};
Jack Moffitt's avatar
Jack Moffitt committed
51 52 53

void connection_initialize(void);
void connection_shutdown(void);
54
void connection_reread_config(ice_config_t *config);
Jack Moffitt's avatar
Jack Moffitt committed
55
void connection_accept_loop(void);
56
void connection_setup_sockets(ice_config_t *config);
Jack Moffitt's avatar
Jack Moffitt committed
57
void connection_close(connection_t *con);
58
connection_t *connection_create(sock_t sock, listensocket_t *listensocket_real, listensocket_t* listensocket_effective, char *ip);
59
int connection_complete_source(source_t *source, int response);
60
void connection_queue(connection_t *con);
61
void connection_uses_tls(connection_t *con);
62

63
ssize_t connection_send_bytes(connection_t *con, const void *buf, size_t len);
64
ssize_t connection_read_bytes(connection_t *con, void *buf, size_t len);
65
int connection_read_put_back(connection_t *con, const void *buf, size_t len);
66

67
extern rwlock_t _source_shutdown_rwlock;
Jack Moffitt's avatar
Jack Moffitt committed
68 69

#endif  /* __CONNECTION_H__ */