Skip to content

Commit e46142a

Browse files
committed
[connection] use proper struct for li_connection_simple_tcp state
Change-Id: I8fc02df976a66367306f09404330ebf6621851db
1 parent 65578d8 commit e46142a

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

include/lighttpd/connection.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef enum {
3535

3636
typedef struct liConnectionSocketCallbacks liConnectionSocketCallbacks;
3737
typedef struct liConnectionSocket liConnectionSocket;
38+
typedef struct liConnectionSimpleTcpState liConnectionSimpleTcpState;
3839

3940
struct liConnectionSocketCallbacks {
4041
void (*finish)(liConnection *con, gboolean aborted);
@@ -84,6 +85,10 @@ struct liConnection {
8485
liJob job_reset;
8586
};
8687

88+
struct liConnectionSimpleTcpState {
89+
liBuffer *read_buffer;
90+
};
91+
8792
/* Internal functions */
8893
LI_API liConnection* li_connection_new(liWorker *wrk);
8994
/** Free dead connections */
@@ -106,9 +111,9 @@ LI_API gchar *li_connection_state_str(liConnectionState state);
106111
LI_API liConnection* li_connection_from_vrequest(liVRequest *vr);
107112

108113

109-
/******************************************************/
110-
/* IO backend stuff (simple tcp, tls implementations) */
111-
/******************************************************/
114+
/****************************************************************/
115+
/* IO backend stuff (simple tcp (or unix), tls implementations) */
116+
/****************************************************************/
112117

113118
/* call after IO send operations if con->out_has_all_data and out queues are empty */
114119
LI_API void li_connection_request_done(liConnection *con);
@@ -118,14 +123,26 @@ LI_API void li_connection_request_done(liConnection *con);
118123
*/
119124
LI_API void li_connection_update_io_timeout(liConnection *con);
120125

126+
INLINE void li_connection_simple_tcp_init(liConnectionSimpleTcpState *state);
127+
121128
/* handles IOStream events for a connection; updates transferred bytes and io timeouts;
122129
* *pcon is needed to handle cases then the connections gets reset while handling io stuff
123130
* NULL == *pcon is ok - it won't update transferred bytes and io timeouts then.
124131
* closes outgoing stream on reading EOF
132+
*
133+
* clear state by calling with LI_IOSTREAM_DESTROY (through li_iostream_release
134+
* and the liIOStreamCB forwarding to li_connection_simple_tcp).
125135
*/
126-
LI_API void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, gpointer *context, liIOStreamEvent event);
136+
LI_API void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, liConnectionSimpleTcpState *state, liIOStreamEvent event);
127137

128138
/******************************************************/
129139

140+
/********************
141+
* Inline functions *
142+
********************/
143+
144+
INLINE void li_connection_simple_tcp_init(liConnectionSimpleTcpState *state) {
145+
state->read_buffer = NULL;
146+
}
130147

131148
#endif

src/main/connection.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
#define LI_CONNECTION_DEFAULT_CHUNKQUEUE_LIMIT (256*1024)
77

8-
void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, gpointer *context, liIOStreamEvent event) {
8+
void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, liConnectionSimpleTcpState *state, liIOStreamEvent event) {
99
liConnection *con;
1010
goffset transfer_in = 0, transfer_out = 0;
1111

1212
transfer_in = (NULL != stream->stream_in.out) ? stream->stream_in.out->bytes_in : 0;
1313
transfer_out = (NULL != stream->stream_out.out) ? stream->stream_out.out->bytes_out : 0;
1414

15-
li_stream_simple_socket_io_cb_with_buffer(stream, event, (liBuffer**) context);
15+
li_stream_simple_socket_io_cb_with_buffer(stream, event, &state->read_buffer);
1616

1717
/* li_stream_simple_socket_io_cb_with_buffer might lead to *pcon == NULL */
1818
con = *pcon;
@@ -64,7 +64,7 @@ void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, gpointer
6464
typedef struct simple_tcp_connection simple_tcp_connection;
6565
struct simple_tcp_connection {
6666
liIOStream *sock_stream;
67-
gpointer simple_tcp_context;
67+
liConnectionSimpleTcpState simple_tcp_state;
6868
liConnection *con;
6969
};
7070

@@ -74,7 +74,7 @@ static void simple_tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
7474
LI_FORCE_ASSERT(NULL == data->con || data == data->con->con_sock.data);
7575
LI_FORCE_ASSERT(NULL == data->sock_stream || stream == data->sock_stream);
7676

77-
li_connection_simple_tcp(&data->con, stream, &data->simple_tcp_context, event);
77+
li_connection_simple_tcp(&data->con, stream, &data->simple_tcp_state, event);
7878

7979
if (NULL != data->con && data->con->out_has_all_data
8080
&& (NULL == stream->stream_out.out || 0 == stream->stream_out.out->length)) {
@@ -140,7 +140,7 @@ static const liConnectionSocketCallbacks simple_tcp_cbs = {
140140
static gboolean simple_tcp_new(liConnection *con, int fd) {
141141
simple_tcp_connection *data = g_slice_new0(simple_tcp_connection);
142142
data->sock_stream = li_iostream_new(con->wrk, fd, simple_tcp_io_cb, data);
143-
data->simple_tcp_context = NULL;
143+
li_connection_simple_tcp_init(&data->simple_tcp_state);
144144
data->con = con;
145145
con->con_sock.data = data;
146146
con->con_sock.callbacks = &simple_tcp_cbs;

src/modules/mod_gnutls.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct mod_connection_ctx {
4646
liGnuTLSFilter *tls_filter;
4747

4848
liIOStream *sock_stream;
49-
gpointer simple_socket_data;
49+
liConnectionSimpleTcpState simple_socket_state;
5050

5151
liStream *client_hello_stream;
5252
#ifdef USE_SNI
@@ -344,7 +344,7 @@ static void tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
344344
li_stream_simple_socket_close(stream, TRUE); /* kill it, ssl sent an close alert message */
345345
}
346346

347-
li_connection_simple_tcp(&conctx->con, stream, &conctx->simple_socket_data, event);
347+
li_connection_simple_tcp(&conctx->con, stream, &conctx->simple_socket_state, event);
348348

349349
if (NULL != conctx->con && conctx->con->out_has_all_data
350350
&& (NULL == stream->stream_out.out || 0 == stream->stream_out.out->length)
@@ -602,6 +602,7 @@ static gboolean mod_gnutls_con_new(liConnection *con, int fd) {
602602
conctx = g_slice_new0(mod_connection_ctx);
603603
conctx->session = session;
604604
conctx->sock_stream = li_iostream_new(con->wrk, fd, tcp_io_cb, conctx);
605+
li_connection_simple_tcp_init(&conctx->simple_socket_state);
605606

606607
conctx->client_hello_stream = li_ssl_client_hello_stream(&con->wrk->loop, gnutls_client_hello_cb, conctx);
607608
#ifdef USE_SNI

src/modules/mod_openssl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct openssl_connection_ctx {
4242
liOpenSSLFilter *ssl_filter;
4343

4444
liIOStream *sock_stream;
45-
gpointer simple_socket_data;
45+
liConnectionSimpleTcpState simple_socket_state;
4646
};
4747

4848
struct openssl_context {
@@ -92,7 +92,7 @@ static void tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
9292
li_stream_simple_socket_close(stream, TRUE); /* kill it, ssl sent an close alert message */
9393
}
9494

95-
li_connection_simple_tcp(&conctx->con, stream, &conctx->simple_socket_data, event);
95+
li_connection_simple_tcp(&conctx->con, stream, &conctx->simple_socket_state, event);
9696

9797
if (NULL != conctx->con && conctx->con->out_has_all_data
9898
&& (NULL == stream->stream_out.out || 0 == stream->stream_out.out->length)
@@ -206,6 +206,7 @@ static gboolean openssl_con_new(liConnection *con, int fd) {
206206
openssl_connection_ctx *conctx = g_slice_new0(openssl_connection_ctx);
207207

208208
conctx->sock_stream = li_iostream_new(con->wrk, fd, tcp_io_cb, conctx);
209+
li_connection_simple_tcp_init(&conctx->simple_socket_state);
209210

210211
conctx->ssl_filter = li_openssl_filter_new(srv, con->wrk, &filter_callbacks, conctx, ctx->ssl_ctx,
211212
&conctx->sock_stream->stream_in, &conctx->sock_stream->stream_out);

0 commit comments

Comments
 (0)