|
|
@ -36,31 +36,76 @@ |
|
|
|
#ifdef GPR_POSIX_SOCKET |
|
|
|
#ifdef GPR_POSIX_SOCKET |
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
|
|
|
#include <grpc/support/useful.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/iomgr/pollset_set.h" |
|
|
|
#include "src/core/iomgr/pollset_set.h" |
|
|
|
|
|
|
|
|
|
|
|
void grpc_pollset_set_init(grpc_pollset_set *pollset_set) { |
|
|
|
void grpc_pollset_set_init(grpc_pollset_set *pollset_set) { |
|
|
|
abort(); |
|
|
|
memset(pollset_set, 0, sizeof(*pollset_set)); |
|
|
|
|
|
|
|
gpr_mu_init(&pollset_set->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_pollset_set_destroy(grpc_pollset_set *pollset_set) { |
|
|
|
void grpc_pollset_set_destroy(grpc_pollset_set *pollset_set) { |
|
|
|
abort(); |
|
|
|
gpr_mu_destroy(&pollset_set->mu); |
|
|
|
|
|
|
|
gpr_free(pollset_set->pollsets); |
|
|
|
|
|
|
|
gpr_free(pollset_set->fds); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_pollset_set_add_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) { |
|
|
|
void grpc_pollset_set_add_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) { |
|
|
|
abort(); |
|
|
|
size_t i; |
|
|
|
|
|
|
|
gpr_mu_lock(&pollset_set->mu); |
|
|
|
|
|
|
|
if (pollset_set->pollset_count == pollset_set->pollset_capacity) { |
|
|
|
|
|
|
|
pollset_set->pollset_capacity = GPR_MAX(8, 2 * pollset_set->pollset_capacity); |
|
|
|
|
|
|
|
pollset_set->pollsets = gpr_realloc(pollset_set->pollsets, pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pollset_set->pollsets[pollset_set->pollset_count++] = pollset; |
|
|
|
|
|
|
|
for (i = 0; i < pollset_set->fd_count; i++) { |
|
|
|
|
|
|
|
grpc_pollset_add_fd(pollset, pollset_set->fds[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpr_mu_unlock(&pollset_set->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_pollset_set_del_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) { |
|
|
|
void grpc_pollset_set_del_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) { |
|
|
|
abort(); |
|
|
|
size_t i; |
|
|
|
|
|
|
|
gpr_mu_lock(&pollset_set->mu); |
|
|
|
|
|
|
|
for (i = 0; i < pollset_set->pollset_count; i++) { |
|
|
|
|
|
|
|
if (pollset_set->pollsets[i] == pollset) { |
|
|
|
|
|
|
|
pollset_set->pollset_count--; |
|
|
|
|
|
|
|
GPR_SWAP(grpc_pollset *, pollset_set->pollsets[i], pollset_set->pollsets[pollset_set->pollset_count]); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpr_mu_unlock(&pollset_set->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_pollset_set_add_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) { |
|
|
|
void grpc_pollset_set_add_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) { |
|
|
|
abort(); |
|
|
|
size_t i; |
|
|
|
|
|
|
|
gpr_mu_lock(&pollset_set->mu); |
|
|
|
|
|
|
|
if (pollset_set->fd_count == pollset_set->fd_capacity) { |
|
|
|
|
|
|
|
pollset_set->fd_capacity = GPR_MAX(8, 2 * pollset_set->fd_capacity); |
|
|
|
|
|
|
|
pollset_set->fds = gpr_realloc(pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pollset_set->fds[pollset_set->fd_count++] = fd; |
|
|
|
|
|
|
|
for (i = 0; i < pollset_set->pollset_count; i++) { |
|
|
|
|
|
|
|
grpc_pollset_add_fd(pollset_set->pollsets[i], fd); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpr_mu_unlock(&pollset_set->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_pollset_set_del_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) { |
|
|
|
void grpc_pollset_set_del_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) { |
|
|
|
abort(); |
|
|
|
size_t i; |
|
|
|
|
|
|
|
gpr_mu_lock(&pollset_set->mu); |
|
|
|
|
|
|
|
for (i = 0; i < pollset_set->fd_count; i++) { |
|
|
|
|
|
|
|
if (pollset_set->fds[i] == fd) { |
|
|
|
|
|
|
|
pollset_set->fd_count--; |
|
|
|
|
|
|
|
GPR_SWAP(grpc_fd *, pollset_set->fds[i], pollset_set->fds[pollset_set->pollset_count]); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpr_mu_unlock(&pollset_set->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif /* GPR_POSIX_SOCKET */ |
|
|
|
#endif /* GPR_POSIX_SOCKET */ |
|
|
|