Skip to content

Commit

Permalink
updates for feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schore <mike.schore@gmail.com>
  • Loading branch information
goaway committed Aug 5, 2019
1 parent 1e3d981 commit 234bb9e
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion library/common/http/header_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static inline std::string convertString(envoy_data s) {

HeaderMapPtr transformHeaders(envoy_headers headers) {
Http::HeaderMapPtr transformed_headers = std::make_unique<HeaderMapImpl>();
for (int i = 0; i < headers.length; i++) {
for (envoy_header_size_t i = 0; i < headers.length; i++) {
transformed_headers->addCopy(LowerCaseString(convertString(headers.headers[i].key)),
convertString(headers.headers[i].value));
}
Expand Down
13 changes: 8 additions & 5 deletions library/common/include/c_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ typedef enum { ENVOY_SUCCESS, ENVOY_FAILURE } envoy_status_t;
*/
typedef enum { ENVOY_STREAM_RESET } envoy_error_code_t;

/**
* Callback indicating Envoy has drained the associated buffer.
*/
#ifdef __cplusplus
extern "C" { // release function
#endif
/**
* Callback indicating Envoy has drained the associated buffer.
*/
typedef void (*envoy_release_f)(void* context);

/**
Expand Down Expand Up @@ -76,12 +76,15 @@ typedef struct {
envoy_data value;
} envoy_header;

// Consistent type for dealing with encodable/processable header counts.
typedef int envoy_header_size_t;

/**
* Holds an HTTP header map as an array of envoy_header structs.
*/
typedef struct {
// Number of header elements in the array.
int length;
envoy_header_size_t length;
// Array of headers.
envoy_header* headers;
} envoy_headers;
Expand All @@ -90,7 +93,7 @@ typedef struct {
* Helper function to free/release memory associated with underlying headers.
*/
void release_envoy_headers(envoy_headers headers) {
for (int i = 0; i < headers.length; i++) {
for (envoy_header_size_t i = 0; i < headers.length; i++) {
envoy_header header = headers.headers[i];
header.key.release(header.key.context);
header.value.release(header.value.context);
Expand Down
4 changes: 3 additions & 1 deletion library/objective-c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ exports_files([
objc_library(
name = "envoy_engine_objc_lib",
srcs = [
"EnvoyEngine.m",
"EnvoyEngineImpl.h",
"EnvoyEngineImpl.m",
"EnvoyHttpStream.m",
],
hdrs = [
"EnvoyEngine.h",
"EnvoyHttpStream.h",
"EnvoyTypes.h",
],
visibility = ["//visibility:public"],
deps = ["//library/common:envoy_main_interface_lib"],
Expand Down
6 changes: 1 addition & 5 deletions library/objective-c/EnvoyEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
NS_ASSUME_NONNULL_BEGIN

/// Wrapper layer for calling into Envoy's C/++ API.
@interface EnvoyEngine : NSObject
@protocol EnvoyEngine

/**
Run the Envoy engine with the provided config and log level.
Expand All @@ -24,10 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (EnvoyStatus)runWithConfig:(NSString *)config logLevel:(NSString *)logLevel;

/// Performs necessary setup after Envoy has initialized and started running.
/// TODO: create a post-initialization callback from Envoy to handle this automatically.
+ (void)setupEnvoy;

@end

NS_ASSUME_NONNULL_END
33 changes: 33 additions & 0 deletions library/objective-c/EnvoyEngineImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#import "EnvoyEngine.h"

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/// Wrapper layer for calling into Envoy's C/++ API.
@interface EnvoyEngineImpl : NSObject <EnvoyEngine>

/**
Run the Envoy engine with the provided config and log level.
@param config The configuration file with which to start Envoy.
@return A status indicating if the action was successful.
*/
+ (EnvoyStatus)runWithConfig:(NSString *)config;

/**
Run the Envoy engine with the provided config and log level.
@param config The configuration file with which to start Envoy.
@param logLevel The log level to use when starting Envoy.
@return A status indicating if the action was successful.
*/
+ (EnvoyStatus)runWithConfig:(NSString *)config logLevel:(NSString *)logLevel;

/// Performs necessary setup after Envoy has initialized and started running.
/// TODO: create a post-initialization callback from Envoy to handle this automatically.
+ (void)setupEnvoy;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "library/objective-c/EnvoyEngine.h"
#import "library/objective-c/EnvoyEngineImpl.h"

#import "library/common/main_interface.h"

@implementation EnvoyEngine
@implementation EnvoyEngineImpl

#pragma mark - class methods
+ (EnvoyStatus)runWithConfig:(NSString *)config {
Expand Down
4 changes: 2 additions & 2 deletions library/objective-c/EnvoyHttpStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ NS_ASSUME_NONNULL_BEGIN
/**
Send headers over the provided stream.
@param metadata Headers to send over the stream.
@param headers Headers to send over the stream.
@param close True if the stream should be closed after sending.
*/
- (void)sendHeaders:(EnvoyHeaders *)headers close:(BOOL)close;

/**
Send data over the provided stream.
@param metadata Data to send over the stream.
@param data Data to send over the stream.
@param close True if the stream should be closed after sending.
*/
- (void)sendData:(NSData *)data close:(BOOL)close;
Expand Down
6 changes: 3 additions & 3 deletions library/objective-c/EnvoyHttpStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ static envoy_data toManagedNativeString(NSString *s) {
}

static envoy_headers toNativeHeaders(EnvoyHeaders *headers) {
int length = 0;
envoy_header_size_t length = 0;
for (id headerList in headers) {
length += [headerList count];
}
envoy_header *header_array = (envoy_header *)malloc(sizeof(envoy_header) * length);
int header_index = 0;
envoy_header_size_t header_index = 0;
for (id headerKey in headers) {
NSArray *headerList = headers[headerKey];
for (id headerValue in headerList) {
Expand All @@ -62,7 +62,7 @@ static envoy_headers toNativeHeaders(EnvoyHeaders *headers) {

static EnvoyHeaders * to_ios_headers(envoy_headers headers) {
NSMutableDictionary *headerDict = [NSMutableDictionary new];
for (uint_fast32_t i = 0; i < headers.length; i++) {
for (envoy_header_size_t i = 0; i < headers.length; i++) {
envoy_header header = headers.headers[i];
NSString *headerKey = [[NSString alloc] initWithBytes:header.key.bytes
length:header.key.length
Expand Down
2 changes: 1 addition & 1 deletion library/objective-c/EnvoyTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NS_ASSUME_NONNULL_BEGIN
// MARK: - Aliases

/// Handle to an outstanding Envoy HTTP stream. Valid only for the duration of the stream and not
/// intended for any exter/nal interpretation or use.
/// intended for any external interpretation or use.
typedef UInt64 EnvoyStreamID;

/// A set of headers that may be passed to/from an Envoy stream.
Expand Down
2 changes: 1 addition & 1 deletion library/swift/src/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public protocol Client {
/// - parameter handler: Handler for receiving stream events.
///
/// - returns: Emitter for sending streaming data outward.
func startStream(request: Request, handler: ResponseHandler, handlerQueue: DispatchQueue)
func startStream(request: Request, handler: ResponseHandler)
-> StreamEmitter
}
4 changes: 2 additions & 2 deletions library/swift/src/Envoy.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

@objcMembers
public final class Envoy: NSObject {
public final class Envoy<Engine: EnvoyEngine>: NSObject {
private let runner: RunnerThread

/// Indicates whether this Envoy instance is currently active and running.
Expand Down Expand Up @@ -33,7 +33,7 @@ public final class Envoy: NSObject {
}

override func main() {
EnvoyEngine.run(withConfig: self.config, logLevel: self.logLevel.stringValue)
Engine.run(withConfig: self.config, logLevel: self.logLevel.stringValue)
}
}
}
3 changes: 3 additions & 0 deletions library/swift/src/ResponseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Foundation
/// Callback interface for receiving stream events.
@objc
public protocol ResponseHandler {
/// Dispatch queue upon which callbacks will be called.
var dispatchQueue: DispatchQueue { get }

/// Called when response headers are received by the stream.
///
/// - parameter headers: The headers of the response.
Expand Down

0 comments on commit 234bb9e

Please sign in to comment.