File: io.h

package info (click to toggle)
mongrel2 1.9.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 5,956 kB
  • sloc: ansic: 43,228; python: 2,827; sql: 1,555; makefile: 347; sh: 307; asm: 234; yacc: 145; php: 73; sed: 5
file content (105 lines) | stat: -rw-r--r-- 2,442 bytes parent folder | download | duplicates (2)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef _io_h
#define _io_h

#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif

#include <stdlib.h>
#include <polarssl/x509.h>
#include <polarssl/ssl.h>
#include <polarssl/havege.h>

#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include "bsd_specific.h"
#else
#include <sys/sendfile.h>
#endif

extern int MAX_SEND_BUFFER;
extern int IO_SSL_VERIFY_METHOD;

struct IOBuf;

typedef ssize_t (*io_cb)(struct IOBuf *, char *data, int len);
typedef ssize_t (*io_stream_file_cb)(struct IOBuf *, int fd, off_t len);

typedef enum IOBufType {
    IOBUF_SSL, IOBUF_SOCKET, IOBUF_FILE, IOBUF_NULL
} IOBufType;

typedef struct IOBuf {

    // len is how much space is in the buffer total
    int len;

    // avail is how much data is in the buffer to read
    int avail;

    // cur is where the next read will come from
    int cur;

    // lets us mark a point in the buffer that 
    int mark;

    int closed;
    io_cb recv;
    io_cb send;
    io_stream_file_cb stream_file;
    char *buf;

    int type;

    int fd;
    int use_ssl;
    int handshake_performed;
    ssl_context ssl;
    ssl_session ssn;
    havege_state hs;
} IOBuf;

IOBuf *IOBuf_create(size_t len, int fd, IOBufType type);

void IOBuf_resize(IOBuf *buf, size_t new_size);

void IOBuf_destroy(IOBuf *buf);
int IOBuf_close(IOBuf *buf);
int IOBuf_register_disconnect(IOBuf *buf);

char *IOBuf_read(IOBuf *buf, int need, int *out_len);
int IOBuf_read_commit(IOBuf *buf, int need);

int IOBuf_send(IOBuf *buf, char *data, int len);

int IOBuf_send_all(IOBuf *buf, char *data, int len);

char *IOBuf_read_all(IOBuf *buf, int len, int retries);

int IOBuf_stream(IOBuf *from, IOBuf *to, int total);

int IOBuf_stream_file(IOBuf *buf, int fd, off_t len);

#define IOBuf_read_some(I,A) IOBuf_read((I), (I)->len, A)

#define IOBuf_closed(I) ((I)->closed)

#define IOBuf_compact_needed(I,N) ((I)->cur + (N) > (I)->len)

#define IOBuf_remaining(I) ((I)->len - (I)->avail - (I)->cur)
#define IOBuf_read_point(I) ((I)->buf + (I)->cur + (I)->avail)
#define IOBuf_start(I) ((I)->buf + (I)->cur)

#define IOBuf_set_mark(I, N) ((I)->mark = (N))
#define IOBuf_mark(I) ((I)->mark)

#define IOBuf_avail(I) ((I)->avail)

#define IOBuf_fd(I) ((I)->fd)

#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define IOBuf_sendfile my_bsd_sendfile
#else
#define IOBuf_sendfile sendfile
#endif

#endif