Skip to content

Commit 65578d8

Browse files
committed
[stream] simple_socket_io: convert opaque context type to buffer
Change-Id: I9106315018ff0ca8d5f1db3fdceba4221c0d7794
1 parent d74fc7c commit 65578d8

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

include/lighttpd/stream.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ LI_API void li_iostream_attach(liIOStream *iostream, liWorker *wrk);
100100

101101
/* handles basic tcp/unix socket connections, writing and reading data, supports throttling */
102102
LI_API void li_stream_simple_socket_close(liIOStream *stream, gboolean aborted);
103+
/* li_stream_simple_socket_io_cb can be used with li_iostream_new and uses stream->data as buffer */
103104
LI_API void li_stream_simple_socket_io_cb(liIOStream *stream, liIOStreamEvent event);
104-
LI_API void li_stream_simple_socket_io_cb_with_context(liIOStream *stream, liIOStreamEvent event, gpointer *data);
105+
/* read buffer probably should be (indirectly) stored in stream->data; LI_IOSTREAM_DESTROY frees the buffer and clears the pointer */
106+
LI_API void li_stream_simple_socket_io_cb_with_buffer(liIOStream *stream, liIOStreamEvent event, liBuffer **buffer);
105107
/* tries to flush TCP sockets by disabling nagle */
106108
LI_API void li_stream_simple_socket_flush(liIOStream *stream);
107109

src/main/connection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, gpointer
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_context(stream, event, context);
15+
li_stream_simple_socket_io_cb_with_buffer(stream, event, (liBuffer**) context);
1616

17-
/* li_stream_simple_socket_io_cb_with_context might lead to *pcon == NULL */
17+
/* li_stream_simple_socket_io_cb_with_buffer might lead to *pcon == NULL */
1818
con = *pcon;
1919
if (NULL != con) {
2020
if (NULL != stream->stream_in.out) {

src/main/stream_simple_socket.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void stream_simple_socket_read_throttle_notify(liThrottleState *state, gp
4242
stream->can_read = TRUE;
4343
li_stream_again(&stream->stream_out);
4444
}
45-
static void stream_simple_socket_read(liIOStream *stream, gpointer *data) {
45+
static void stream_simple_socket_read(liIOStream *stream, liBuffer **buffer) {
4646
liNetworkStatus res;
4747
GError *err = NULL;
4848
liWorker *wrk = li_worker_from_iostream(stream);
@@ -58,27 +58,25 @@ static void stream_simple_socket_read(liIOStream *stream, gpointer *data) {
5858
}
5959
}
6060

61-
if (NULL == *data && NULL != wrk->network_read_buf) {
61+
if (NULL == *buffer && NULL != wrk->network_read_buf) {
6262
/* reuse worker buf if needed */
63-
*data = wrk->network_read_buf;
63+
*buffer = wrk->network_read_buf;
6464
wrk->network_read_buf = NULL;
6565
}
6666

6767
{
6868
goffset current_in_bytes = raw_in->bytes_in;
69-
liBuffer *raw_in_buffer = *data;
70-
res = li_network_read(fd, raw_in, max_read, &raw_in_buffer, &err);
71-
*data = raw_in_buffer;
69+
res = li_network_read(fd, raw_in, max_read, buffer, &err);
7270
if (NULL != stream->throttle_in) {
7371
li_throttle_update(stream->throttle_in, raw_in->bytes_in - current_in_bytes);
7472
}
7573
}
7674

77-
if (NULL == wrk->network_read_buf && NULL != *data
78-
&& 1 == g_atomic_int_get(&((liBuffer*)*data)->refcount)) {
75+
if (NULL == wrk->network_read_buf && NULL != *buffer
76+
&& 1 == g_atomic_int_get(&((liBuffer*)*buffer)->refcount)) {
7977
/* move buffer back to worker if we didn't use it */
80-
wrk->network_read_buf = *data;
81-
*data = NULL;
78+
wrk->network_read_buf = *buffer;
79+
*buffer = NULL;
8280
}
8381

8482
switch (res) {
@@ -165,21 +163,21 @@ static void stream_simple_socket_write(liIOStream *stream) {
165163
}
166164

167165
void li_stream_simple_socket_io_cb(liIOStream *stream, liIOStreamEvent event) {
168-
li_stream_simple_socket_io_cb_with_context(stream, event, &stream->data);
166+
li_stream_simple_socket_io_cb_with_buffer(stream, event, (liBuffer**) &stream->data);
169167
}
170168

171-
void li_stream_simple_socket_io_cb_with_context(liIOStream *stream, liIOStreamEvent event, gpointer *data) {
169+
void li_stream_simple_socket_io_cb_with_buffer(liIOStream *stream, liIOStreamEvent event, liBuffer **buffer) {
172170
switch (event) {
173171
case LI_IOSTREAM_READ:
174-
stream_simple_socket_read(stream, data);
172+
stream_simple_socket_read(stream, buffer);
175173
break;
176174
case LI_IOSTREAM_WRITE:
177175
stream_simple_socket_write(stream);
178176
break;
179177
case LI_IOSTREAM_DESTROY:
180-
if (NULL != *data) {
181-
li_buffer_release(*data);
182-
*data = NULL;
178+
if (NULL != *buffer) {
179+
li_buffer_release(*buffer);
180+
*buffer = NULL;
183181
}
184182
default:
185183
break;

src/modules/mod_proxy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct proxy_context {
3333
struct proxy_connection {
3434
proxy_context *ctx;
3535
liBackendConnection *bcon;
36-
gpointer simple_socket_data;
36+
liBuffer *simple_socket_buffer;
3737
};
3838

3939
/**********************************************************************************/
@@ -169,7 +169,7 @@ static void proxy_io_cb(liIOStream *stream, liIOStreamEvent event) {
169169
proxy_connection *con = stream->data;
170170
liWorker *wrk = li_worker_from_iostream(stream);
171171

172-
li_stream_simple_socket_io_cb_with_context(stream, event, &con->simple_socket_data);
172+
li_stream_simple_socket_io_cb_with_buffer(stream, event, &con->simple_socket_buffer);
173173

174174
switch (event) {
175175
case LI_IOSTREAM_DESTROY:

src/modules/mod_scgi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct scgi_context {
3030
struct scgi_connection {
3131
scgi_context *ctx;
3232
liBackendConnection *bcon;
33-
gpointer simple_socket_data;
33+
liBuffer *simple_socket_buffer;
3434
};
3535

3636
/**********************************************************************************/
@@ -143,7 +143,7 @@ static void scgi_io_cb(liIOStream *stream, liIOStreamEvent event) {
143143
scgi_connection *con = stream->data;
144144
liWorker *wrk = li_worker_from_iostream(stream);
145145

146-
li_stream_simple_socket_io_cb_with_context(stream, event, &con->simple_socket_data);
146+
li_stream_simple_socket_io_cb_with_buffer(stream, event, &con->simple_socket_buffer);
147147

148148
switch (event) {
149149
case LI_IOSTREAM_DESTROY:

0 commit comments

Comments
 (0)