Pass peer string to ChannelData ctor when available.

pull/6915/head
Mark D. Roth 9 years ago
parent 9fe5ef5f9d
commit 035cb3a3d4
  1. 13
      include/grpc++/channel_filter.h
  2. 8
      src/core/lib/transport/transport.h

@ -62,8 +62,13 @@ class ChannelData {
grpc_channel_element *elem,
grpc_transport_op *op);
const char* peer() const { return peer_; }
protected:
explicit ChannelData(const grpc_channel_args &) {}
ChannelData(const grpc_channel_args &args, const char *peer) : peer_(peer) {}
private:
const char *peer_; // Do not own.
};
// Represents call data.
@ -96,8 +101,12 @@ class ChannelFilter {
static void InitChannelElement(grpc_exec_ctx *exec_ctx,
grpc_channel_element *elem,
grpc_channel_element_args *args) {
const char* peer = args->optional_transport
? grpc_transport_get_peer(exec_ctx,
args->optional_transport)
: nullptr;
// Construct the object in the already-allocated memory.
new (elem->channel_data) ChannelDataType(*args->channel_args);
new (elem->channel_data) ChannelDataType(*args->channel_args, peer);
}
static void DestroyChannelElement(grpc_exec_ctx *exec_ctx,

@ -43,6 +43,10 @@
#include "src/core/lib/transport/byte_stream.h"
#include "src/core/lib/transport/metadata_batch.h"
#ifdef __cplusplus
extern "C" {
#endif
/* forward declarations */
typedef struct grpc_transport grpc_transport;
@ -264,4 +268,8 @@ void grpc_transport_destroy(grpc_exec_ctx *exec_ctx, grpc_transport *transport);
char *grpc_transport_get_peer(grpc_exec_ctx *exec_ctx,
grpc_transport *transport);
#ifdef __cplusplus
}
#endif
#endif /* GRPC_CORE_LIB_TRANSPORT_TRANSPORT_H */

Loading…
Cancel
Save