Add grpc_endpoint_get_socket and GRPC_SOCKET

pull/8486/head
Yuchen Zeng 8 years ago
parent 5ab4ca5ed8
commit e5ec9ac9e2
  1. 6
      src/core/lib/iomgr/endpoint.h
  2. 2
      src/core/lib/iomgr/sockaddr_posix.h
  3. 2
      src/core/lib/iomgr/sockaddr_windows.h
  4. 8
      src/core/lib/iomgr/tcp_posix.c
  5. 8
      src/core/lib/security/transport/secure_endpoint.c
  6. 3
      test/core/internal_api_canaries/iomgr.c
  7. 22
      test/core/util/mock_endpoint.c
  8. 22
      test/core/util/passthru_endpoint.c

@ -39,6 +39,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/iomgr/sockaddr.h"
/* An endpoint caps a streaming channel between two communicating processes.
Examples may be: a tcp socket, <stdin+stdout>, or some shared memory. */
@ -59,6 +60,7 @@ struct grpc_endpoint_vtable {
void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep);
void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep);
char *(*get_peer)(grpc_endpoint *ep);
GRPC_SOCKET *(*get_socket)(grpc_endpoint *ep);
};
/* When data is available on the connection, calls the callback with slices.
@ -71,6 +73,10 @@ void grpc_endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
char *grpc_endpoint_get_peer(grpc_endpoint *ep);
/* Get the socket (file descriptor or SOCKET) used by \a ep. Return NULL if
\a ep is not using a socket. */
GRPC_SOCKET *grpc_endpoint_get_socket(grpc_endpoint *ep);
/* Retrieve a reference to the workqueue associated with this endpoint */
grpc_workqueue *grpc_endpoint_get_workqueue(grpc_endpoint *ep);

@ -41,4 +41,6 @@
#include <sys/types.h>
#include <unistd.h>
typedef int GRPC_SOCKET;
#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_POSIX_H */

@ -40,4 +40,6 @@
// must be included after the above
#include <mswsock.h>
typedef SOCKET GRPC_SOCKET;
#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H */

@ -464,6 +464,11 @@ static char *tcp_get_peer(grpc_endpoint *ep) {
return gpr_strdup(tcp->peer_string);
}
static int *tcp_get_socket(grpc_endpoint *ep) {
grpc_tcp *tcp = (grpc_tcp *)ep;
return &tcp->fd;
}
static grpc_workqueue *tcp_get_workqueue(grpc_endpoint *ep) {
grpc_tcp *tcp = (grpc_tcp *)ep;
return grpc_fd_get_workqueue(tcp->em_fd);
@ -476,7 +481,8 @@ static const grpc_endpoint_vtable vtable = {tcp_read,
tcp_add_to_pollset_set,
tcp_shutdown,
tcp_destroy,
tcp_get_peer};
tcp_get_peer,
tcp_get_socket};
grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd, size_t slice_size,
const char *peer_string) {

@ -38,6 +38,7 @@
#include <grpc/support/slice_buffer.h>
#include <grpc/support/sync.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/security/transport/tsi_error.h"
#include "src/core/lib/support/string.h"
@ -365,6 +366,10 @@ static char *endpoint_get_peer(grpc_endpoint *secure_ep) {
return grpc_endpoint_get_peer(ep->wrapped_ep);
}
static GRPC_SOCKET *endpoint_get_socket(grpc_endpoint *secure_ep) {
return NULL;
}
static grpc_workqueue *endpoint_get_workqueue(grpc_endpoint *secure_ep) {
secure_endpoint *ep = (secure_endpoint *)secure_ep;
return grpc_endpoint_get_workqueue(ep->wrapped_ep);
@ -377,7 +382,8 @@ static const grpc_endpoint_vtable vtable = {endpoint_read,
endpoint_add_to_pollset_set,
endpoint_shutdown,
endpoint_destroy,
endpoint_get_peer};
endpoint_get_peer,
endpoint_get_socket};
grpc_endpoint *grpc_secure_endpoint_create(
struct tsi_frame_protector *protector, grpc_endpoint *transport,

@ -84,7 +84,8 @@ static void test_code(void) {
grpc_endpoint_add_to_pollset_set,
grpc_endpoint_shutdown,
grpc_endpoint_destroy,
grpc_endpoint_get_peer};
grpc_endpoint_get_peer,
grpc_endpoint_get_socket};
endpoint.vtable = &vtable;
grpc_endpoint_read(&exec_ctx, &endpoint, NULL, NULL);

@ -35,6 +35,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/iomgr/sockaddr.h"
typedef struct grpc_mock_endpoint {
grpc_endpoint base;
@ -95,18 +96,19 @@ static char *me_get_peer(grpc_endpoint *ep) {
return gpr_strdup("fake:mock_endpoint");
}
static GRPC_SOCKET *me_get_socket(grpc_endpoint *ep) { return NULL; }
static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; }
static const grpc_endpoint_vtable vtable = {
me_read,
me_write,
me_get_workqueue,
me_add_to_pollset,
me_add_to_pollset_set,
me_shutdown,
me_destroy,
me_get_peer,
};
static const grpc_endpoint_vtable vtable = {me_read,
me_write,
me_get_workqueue,
me_add_to_pollset,
me_add_to_pollset_set,
me_shutdown,
me_destroy,
me_get_peer,
me_get_socket};
grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(gpr_slice slice)) {
grpc_mock_endpoint *m = gpr_malloc(sizeof(*m));

@ -35,6 +35,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/iomgr/sockaddr.h"
typedef struct passthru_endpoint passthru_endpoint;
@ -140,18 +141,19 @@ static char *me_get_peer(grpc_endpoint *ep) {
return gpr_strdup("fake:mock_endpoint");
}
static GRPC_SOCKET *me_get_socket(grpc_endpoint *ep) { return NULL; }
static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; }
static const grpc_endpoint_vtable vtable = {
me_read,
me_write,
me_get_workqueue,
me_add_to_pollset,
me_add_to_pollset_set,
me_shutdown,
me_destroy,
me_get_peer,
};
static const grpc_endpoint_vtable vtable = {me_read,
me_write,
me_get_workqueue,
me_add_to_pollset,
me_add_to_pollset_set,
me_shutdown,
me_destroy,
me_get_peer,
me_get_socket};
static void half_init(half *m, passthru_endpoint *parent) {
m->base.vtable = &vtable;

Loading…
Cancel
Save