mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-09 16:47:18 +02:00
MEDIUM: protocol: use a family array to index the protocol handlers
Instead of walking over a list, we now have a direct mapping between protocol families and their respective handlers. This will allow fast lookups.
This commit is contained in:
parent
2e05a8c742
commit
b550d009ca
@ -22,8 +22,11 @@
|
|||||||
#ifndef _PROTO_PROTOCOL_H
|
#ifndef _PROTO_PROTOCOL_H
|
||||||
#define _PROTO_PROTOCOL_H
|
#define _PROTO_PROTOCOL_H
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <types/protocol.h>
|
#include <types/protocol.h>
|
||||||
|
|
||||||
|
extern struct protocol *__protocol_by_family[AF_MAX];
|
||||||
|
|
||||||
/* Registers the protocol <proto> */
|
/* Registers the protocol <proto> */
|
||||||
void protocol_register(struct protocol *proto);
|
void protocol_register(struct protocol *proto);
|
||||||
|
|
||||||
@ -51,7 +54,12 @@ int protocol_unbind_all(void);
|
|||||||
int protocol_enable_all(void);
|
int protocol_enable_all(void);
|
||||||
|
|
||||||
/* returns the protocol associated to family <family> or NULL if not found */
|
/* returns the protocol associated to family <family> or NULL if not found */
|
||||||
struct protocol *protocol_by_family(int family);
|
static inline struct protocol *protocol_by_family(int family)
|
||||||
|
{
|
||||||
|
if (family >= 0 && family < AF_MAX)
|
||||||
|
return __protocol_by_family[family];
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _PROTO_PROTOCOL_H */
|
#endif /* _PROTO_PROTOCOL_H */
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/errors.h>
|
#include <common/errors.h>
|
||||||
#include <common/mini-clist.h>
|
#include <common/mini-clist.h>
|
||||||
@ -19,11 +21,14 @@
|
|||||||
|
|
||||||
/* List head of all registered protocols */
|
/* List head of all registered protocols */
|
||||||
static struct list protocols = LIST_HEAD_INIT(protocols);
|
static struct list protocols = LIST_HEAD_INIT(protocols);
|
||||||
|
struct protocol *__protocol_by_family[AF_MAX] = { };
|
||||||
|
|
||||||
/* Registers the protocol <proto> */
|
/* Registers the protocol <proto> */
|
||||||
void protocol_register(struct protocol *proto)
|
void protocol_register(struct protocol *proto)
|
||||||
{
|
{
|
||||||
LIST_ADDQ(&protocols, &proto->list);
|
LIST_ADDQ(&protocols, &proto->list);
|
||||||
|
if (proto->sock_domain >= 0 && proto->sock_domain < AF_MAX)
|
||||||
|
__protocol_by_family[proto->sock_domain] = proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregisters the protocol <proto>. Note that all listeners must have
|
/* Unregisters the protocol <proto>. Note that all listeners must have
|
||||||
@ -109,18 +114,6 @@ int protocol_disable_all(void)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the protocol handler for socket family <family> or NULL if not found */
|
|
||||||
struct protocol *protocol_by_family(int family)
|
|
||||||
{
|
|
||||||
struct protocol *proto;
|
|
||||||
|
|
||||||
list_for_each_entry(proto, &protocols, list) {
|
|
||||||
if (proto->sock_domain == family)
|
|
||||||
return proto;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-indent-level: 8
|
* c-indent-level: 8
|
||||||
|
Loading…
Reference in New Issue
Block a user