diff options
author | Yuchen Zeng <zyc@google.com> | 2016-11-08 14:28:03 -0800 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2016-11-08 14:28:03 -0800 |
commit | 7810898658353056bb6f6cd4c84bfa00ff7c7290 (patch) | |
tree | d5ce40e7757d011adc2f2796cfda7cc3aadf4d52 /src | |
parent | fdfe41fb036e5489b785db5e8ddeec231e6fdc5a (diff) |
Add grpc_socket_mutator_compare
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lib/iomgr/socket_mutator.c | 19 | ||||
-rw-r--r-- | src/core/lib/iomgr/socket_mutator.h | 5 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/core/lib/iomgr/socket_mutator.c b/src/core/lib/iomgr/socket_mutator.c index 3f66cb100d..8b1efb6bab 100644 --- a/src/core/lib/iomgr/socket_mutator.c +++ b/src/core/lib/iomgr/socket_mutator.c @@ -52,6 +52,20 @@ bool grpc_socket_mutator_mutate_fd(grpc_socket_mutator *mutator, int fd) { return mutator->vtable->mutate_fd(fd, mutator); } +int grpc_socket_mutator_compare(grpc_socket_mutator *a, + grpc_socket_mutator *b) { + int c = GPR_ICMP(a, b); + if (c != 0) { + grpc_socket_mutator *sma = a; + grpc_socket_mutator *smb = b; + c = GPR_ICMP(sma->vtable, smb->vtable); + if (c == 0) { + c = sma->vtable->compare(sma, smb); + } + } + return c; +} + void grpc_socket_mutator_unref(grpc_socket_mutator *mutator) { if (gpr_unref(&mutator->refcount)) { mutator->vtable->destory(mutator); @@ -66,7 +80,10 @@ static void socket_mutator_arg_destroy(void *p) { grpc_socket_mutator_unref(p); } -static int socket_mutator_cmp(void *a, void *b) { return GPR_ICMP(a, b); } +static int socket_mutator_cmp(void *a, void *b) { + return grpc_socket_mutator_compare((grpc_socket_mutator *)a, + (grpc_socket_mutator *)b); +} static const grpc_arg_pointer_vtable socket_mutator_arg_vtable = { socket_mutator_arg_copy, socket_mutator_arg_destroy, socket_mutator_cmp}; diff --git a/src/core/lib/iomgr/socket_mutator.h b/src/core/lib/iomgr/socket_mutator.h index 5200f52d3a..2f5b6c248e 100644 --- a/src/core/lib/iomgr/socket_mutator.h +++ b/src/core/lib/iomgr/socket_mutator.h @@ -45,6 +45,8 @@ extern "C" { typedef struct { /** Mutates the socket opitons of \a fd */ bool (*mutate_fd)(int fd, grpc_socket_mutator *mutator); + /** Compare socket mutator \a a and \a b */ + int (*compare)(grpc_socket_mutator *a, grpc_socket_mutator *b); /** Destroys the socket mutator instance */ void (*destory)(grpc_socket_mutator *mutator); } grpc_socket_mutator_vtable; @@ -65,6 +67,9 @@ grpc_arg grpc_socket_mutator_to_arg(grpc_socket_mutator *mutator); /** Perform the file descriptor mutation operation of \a mutator on \a fd */ bool grpc_socket_mutator_mutate_fd(grpc_socket_mutator *mutator, int fd); +/** Compare if \a a and \a b are the same mutator or have same settings */ +int grpc_socket_mutator_compare(grpc_socket_mutator *a, grpc_socket_mutator *b); + grpc_socket_mutator *grpc_socket_mutator_ref(grpc_socket_mutator *mutator); void grpc_socket_mutator_unref(grpc_socket_mutator *mutator); |