mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: stream: Add stream_generate_unique_id function
Currently unique IDs for a stream are generated using repetitive code in multiple locations, possibly allowing for inconsistent behavior.
This commit is contained in:
parent
5fcec84c58
commit
127a74dd48
@ -53,6 +53,7 @@ extern struct trace_source trace_strm;
|
||||
#define IS_HTX_STRM(strm) ((strm)->flags & SF_HTX)
|
||||
|
||||
extern struct pool_head *pool_head_stream;
|
||||
extern struct pool_head *pool_head_uniqueid;
|
||||
extern struct list streams;
|
||||
|
||||
extern struct data_cb sess_conn_cb;
|
||||
@ -65,6 +66,8 @@ void stream_shutdown(struct stream *stream, int why);
|
||||
void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx, char eol);
|
||||
void stream_dump_and_crash(enum obj_type *obj, int rate);
|
||||
|
||||
int stream_generate_unique_id(struct stream *strm, struct list *format);
|
||||
|
||||
void stream_process_counters(struct stream *s);
|
||||
void sess_change_server(struct stream *sess, struct server *newsrv);
|
||||
struct task *process_stream(struct task *t, void *context, unsigned short state);
|
||||
|
@ -5093,7 +5093,6 @@ void http_end_txn(struct stream *s)
|
||||
|
||||
|
||||
DECLARE_POOL(pool_head_http_txn, "http_txn", sizeof(struct http_txn));
|
||||
DECLARE_POOL(pool_head_uniqueid, "uniqueid", UNIQUEID_LEN);
|
||||
|
||||
__attribute__((constructor))
|
||||
static void __http_protocol_init(void)
|
||||
|
24
src/stream.c
24
src/stream.c
@ -66,6 +66,7 @@
|
||||
#include <proto/vars.h>
|
||||
|
||||
DECLARE_POOL(pool_head_stream, "stream", sizeof(struct stream));
|
||||
DECLARE_POOL(pool_head_uniqueid, "uniqueid", UNIQUEID_LEN);
|
||||
|
||||
struct list streams = LIST_HEAD_INIT(streams);
|
||||
__decl_spinlock(streams_lock);
|
||||
@ -2661,6 +2662,29 @@ void stream_dump_and_crash(enum obj_type *obj, int rate)
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Generates a unique ID based on the given <format>, stores it in the given <strm> and
|
||||
* returns the length of the ID. -1 is returned on memory allocation failure.
|
||||
*
|
||||
* If an ID is already stored within the stream nothing happens and length of the stored
|
||||
* ID is returned.
|
||||
*/
|
||||
int stream_generate_unique_id(struct stream *strm, struct list *format)
|
||||
{
|
||||
if (strm->unique_id != NULL) {
|
||||
return strlen(strm->unique_id);
|
||||
}
|
||||
else {
|
||||
char *unique_id;
|
||||
if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
|
||||
return -1;
|
||||
|
||||
strm->unique_id = unique_id;
|
||||
strm->unique_id[0] = 0;
|
||||
|
||||
return build_logline(strm, strm->unique_id, UNIQUEID_LEN, format);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* All supported ACL keywords must be declared here. */
|
||||
/************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user