@@ -59,6 +59,10 @@ typedef struct _LogProtoFramedServer
59
59
guint32 frame_len ;
60
60
gboolean half_message_in_buffer ;
61
61
guint32 fetch_counter ;
62
+
63
+ /* auxiliary data (e.g. GSockAddr, other transport related meta
64
+ * data) associated with the already buffered data */
65
+ LogTransportAuxData buffer_aux ;
62
66
} LogProtoFramedServer ;
63
67
64
68
static LogProtoPrepareAction
@@ -90,7 +94,7 @@ log_proto_framed_server_prepare(LogProtoServer *s, GIOCondition *cond, gint *tim
90
94
*/
91
95
static gboolean
92
96
log_proto_framed_server_fetch_data (LogProtoFramedServer * self , gboolean * may_read ,
93
- LogTransportAuxData * aux , LogProtoStatus * status )
97
+ LogProtoStatus * status )
94
98
{
95
99
gint rc ;
96
100
* status = LPS_SUCCESS ;
@@ -104,8 +108,9 @@ log_proto_framed_server_fetch_data(LogProtoFramedServer *self, gboolean *may_rea
104
108
if (self -> fetch_counter ++ >= MAX_FETCH_COUNT )
105
109
return FALSE;
106
110
111
+ log_transport_aux_data_reinit (& self -> buffer_aux );
107
112
rc = log_transport_read (self -> super .transport , & self -> buffer [self -> buffer_end ], self -> buffer_size - self -> buffer_end ,
108
- aux );
113
+ & self -> buffer_aux );
109
114
110
115
if (rc < 0 )
111
116
{
@@ -114,7 +119,6 @@ log_proto_framed_server_fetch_data(LogProtoFramedServer *self, gboolean *may_rea
114
119
msg_error ("Error reading RFC6587 style framed data" ,
115
120
evt_tag_int ("fd" , self -> super .transport -> fd ),
116
121
evt_tag_error ("error" ));
117
- log_transport_aux_data_reinit (aux );
118
122
* status = LPS_ERROR ;
119
123
}
120
124
else
@@ -129,7 +133,6 @@ log_proto_framed_server_fetch_data(LogProtoFramedServer *self, gboolean *may_rea
129
133
{
130
134
msg_trace ("EOF occurred while reading" ,
131
135
evt_tag_int (EVT_TAG_FD , self -> super .transport -> fd ));
132
- log_transport_aux_data_reinit (aux );
133
136
* status = LPS_EOF ;
134
137
return FALSE;
135
138
}
@@ -190,8 +193,7 @@ _is_trimmed_part_completely_fetched(LogProtoFramedServer *self)
190
193
/* Returns TRUE if successfully finished consuming the data. Otherwise it is not finished, but
191
194
* there is nothing left to read (or there was a read error) and expects to be called again. */
192
195
static gboolean
193
- _consume_trimmed_part (LogProtoFramedServer * self , gboolean * may_read ,
194
- LogTransportAuxData * aux , LogProtoStatus * status )
196
+ _consume_trimmed_part (LogProtoFramedServer * self , gboolean * may_read , LogProtoStatus * status )
195
197
{
196
198
/* Since trimming requires a full (buffer sized) message, the consuming
197
199
* always starts at the beginning of the buffer, with a new read. */
@@ -200,7 +202,7 @@ _consume_trimmed_part(LogProtoFramedServer *self, gboolean *may_read,
200
202
201
203
while (1 )
202
204
{
203
- if (!log_proto_framed_server_fetch_data (self , may_read , aux , status ))
205
+ if (!log_proto_framed_server_fetch_data (self , may_read , status ))
204
206
return FALSE;
205
207
206
208
if (_is_trimmed_part_completely_fetched (self ))
@@ -225,24 +227,23 @@ _ensure_buffer(LogProtoFramedServer *self)
225
227
}
226
228
227
229
static LogProtoFramedServerStateControl
228
- _on_frame_read (LogProtoFramedServer * self , gboolean * may_read , LogTransportAuxData * aux , LogProtoStatus * status )
230
+ _on_frame_read (LogProtoFramedServer * self , gboolean * may_read , LogProtoStatus * status )
229
231
{
230
- if (!log_proto_framed_server_fetch_data (self , may_read , aux , status ))
232
+ if (!log_proto_framed_server_fetch_data (self , may_read , status ))
231
233
return LPFSSCTRL_RETURN_WITH_STATUS ;
232
234
233
235
self -> state = LPFSS_FRAME_EXTRACT ;
234
236
return LPFSSCTRL_NEXT_STATE ;
235
237
}
236
238
237
239
static LogProtoFramedServerStateControl
238
- _on_frame_extract (LogProtoFramedServer * self , LogTransportAuxData * aux , LogProtoStatus * status )
240
+ _on_frame_extract (LogProtoFramedServer * self , LogProtoStatus * status )
239
241
{
240
242
gboolean need_more_data = FALSE;
241
243
242
244
if (!log_proto_framed_server_extract_frame_length (self , & need_more_data ))
243
245
{
244
246
/* invalid frame header */
245
- log_transport_aux_data_reinit (aux );
246
247
* status = LPS_ERROR ;
247
248
return LPFSSCTRL_RETURN_WITH_STATUS ;
248
249
}
@@ -270,7 +271,6 @@ _on_frame_extract(LogProtoFramedServer *self, LogTransportAuxData *aux, LogProto
270
271
msg_error ("Incoming frame larger than log_msg_size()" ,
271
272
evt_tag_int ("log_msg_size" , self -> super .options -> max_msg_size ),
272
273
evt_tag_int ("frame_length" , self -> frame_len ));
273
- log_transport_aux_data_reinit (aux );
274
274
* status = LPS_ERROR ;
275
275
return LPFSSCTRL_RETURN_WITH_STATUS ;
276
276
}
@@ -281,9 +281,9 @@ _on_frame_extract(LogProtoFramedServer *self, LogTransportAuxData *aux, LogProto
281
281
}
282
282
283
283
static LogProtoFramedServerStateControl
284
- _on_trim_message_read (LogProtoFramedServer * self , gboolean * may_read , LogTransportAuxData * aux , LogProtoStatus * status )
284
+ _on_trim_message_read (LogProtoFramedServer * self , gboolean * may_read , LogProtoStatus * status )
285
285
{
286
- if (!log_proto_framed_server_fetch_data (self , may_read , aux , status ))
286
+ if (!log_proto_framed_server_fetch_data (self , may_read , status ))
287
287
return LPFSSCTRL_RETURN_WITH_STATUS ;
288
288
self -> state = LPFSS_TRIM_MESSAGE ;
289
289
@@ -312,9 +312,9 @@ _on_trim_message(LogProtoFramedServer *self, const guchar **msg, gsize *msg_len,
312
312
}
313
313
314
314
static LogProtoFramedServerStateControl
315
- _on_consume_trimmed (LogProtoFramedServer * self , gboolean * may_read , LogTransportAuxData * aux , LogProtoStatus * status )
315
+ _on_consume_trimmed (LogProtoFramedServer * self , gboolean * may_read , LogProtoStatus * status )
316
316
{
317
- if (_consume_trimmed_part (self , may_read , aux , status ))
317
+ if (_consume_trimmed_part (self , may_read , status ))
318
318
{
319
319
self -> state = LPFSS_FRAME_EXTRACT ;
320
320
/* If there is data in the buffer, try to process it immediately.
@@ -330,9 +330,9 @@ _on_consume_trimmed(LogProtoFramedServer *self, gboolean *may_read, LogTransport
330
330
}
331
331
332
332
static LogProtoFramedServerStateControl
333
- _on_message_read (LogProtoFramedServer * self , gboolean * may_read , LogTransportAuxData * aux , LogProtoStatus * status )
333
+ _on_message_read (LogProtoFramedServer * self , gboolean * may_read , LogProtoStatus * status )
334
334
{
335
- if (!log_proto_framed_server_fetch_data (self , may_read , aux , status ))
335
+ if (!log_proto_framed_server_fetch_data (self , may_read , status ))
336
336
return LPFSSCTRL_RETURN_WITH_STATUS ;
337
337
338
338
self -> state = LPFSS_MESSAGE_EXTRACT ;
@@ -364,27 +364,27 @@ _on_message_extract(LogProtoFramedServer *self, const guchar **msg, gsize *msg_l
364
364
365
365
static LogProtoFramedServerStateControl
366
366
_step_state_machine (LogProtoFramedServer * self , const guchar * * msg , gsize * msg_len , gboolean * may_read ,
367
- LogTransportAuxData * aux , LogProtoStatus * status )
367
+ LogProtoStatus * status )
368
368
{
369
369
switch (self -> state )
370
370
{
371
371
case LPFSS_FRAME_READ :
372
- return _on_frame_read (self , may_read , aux , status );
372
+ return _on_frame_read (self , may_read , status );
373
373
374
374
case LPFSS_FRAME_EXTRACT :
375
- return _on_frame_extract (self , aux , status );
375
+ return _on_frame_extract (self , status );
376
376
377
377
case LPFSS_TRIM_MESSAGE_READ :
378
- return _on_trim_message_read (self , may_read , aux , status );
378
+ return _on_trim_message_read (self , may_read , status );
379
379
380
380
case LPFSS_TRIM_MESSAGE :
381
381
return _on_trim_message (self , msg , msg_len , status );
382
382
383
383
case LPFSS_CONSUME_TRIMMED :
384
- return _on_consume_trimmed (self , may_read , aux , status );
384
+ return _on_consume_trimmed (self , may_read , status );
385
385
386
386
case LPFSS_MESSAGE_READ :
387
- return _on_message_read (self , may_read , aux , status );
387
+ return _on_message_read (self , may_read , status );
388
388
389
389
case LPFSS_MESSAGE_EXTRACT :
390
390
return _on_message_extract (self , msg , msg_len , status );
@@ -404,8 +404,11 @@ log_proto_framed_server_fetch(LogProtoServer *s, const guchar **msg, gsize *msg_
404
404
_ensure_buffer (self );
405
405
406
406
self -> fetch_counter = 0 ;
407
- while (_step_state_machine (self , msg , msg_len , may_read , aux , & status ) != LPFSSCTRL_RETURN_WITH_STATUS ) ;
407
+ while (_step_state_machine (self , msg , msg_len , may_read , & status ) != LPFSSCTRL_RETURN_WITH_STATUS )
408
+ ;
408
409
410
+ if (status == LPS_SUCCESS && aux )
411
+ log_transport_aux_data_copy (aux , & self -> buffer_aux );
409
412
return status ;
410
413
}
411
414
@@ -415,6 +418,7 @@ log_proto_framed_server_free(LogProtoServer *s)
415
418
LogProtoFramedServer * self = (LogProtoFramedServer * ) s ;
416
419
g_free (self -> buffer );
417
420
421
+ log_transport_aux_data_destroy (& self -> buffer_aux );
418
422
log_proto_server_free_method (s );
419
423
}
420
424
0 commit comments