Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 3 files changed
  • 1 commit comment
  • 2 contributors
Showing with 51 additions and 1 deletion.
  1. +21 −1 include/ispdy.h
  2. +3 −0  src/common.h
  3. +27 −0 src/ispdy.m
View
22 include/ispdy.h
@@ -85,6 +85,15 @@ typedef enum {
} ISpdyCheckStatus;
/**
+ * Log levels
+ */
+typedef enum {
+ kISpdyLogInfo,
+ kISpdyLogWarning,
+ kISpdyLogError
+} ISpdyLogLevel;
+
+/**
* Callback for ping method.
*/
typedef void (^ISpdyPingCallback)(ISpdyPingStatus status, NSTimeInterval rtt);
@@ -287,6 +296,17 @@ typedef void (^ISpdyPingCallback)(ISpdyPingStatus status, NSTimeInterval rtt);
@end
+/**
+ * Delegate for handling connection-level log events
+ */
+@protocol ISpdyLogDelegate
+
+- (void) logSpdyEvents: (ISpdy*) conn
+ level: (ISpdyLogLevel) level
+ message: (NSString*) message;
+
+@end
+
/** ISpdy connection class
*
* Connects to server and holds underlying socket, parsing incoming data and
@@ -298,7 +318,7 @@ typedef void (^ISpdyPingCallback)(ISpdyPingStatus status, NSTimeInterval rtt);
/**
* Connection-level delegate, should be provided to handle global errors.
*/
-@property (weak) id <ISpdyDelegate> delegate;
+@property (weak) id <ISpdyDelegate, ISpdyLogDelegate> delegate;
/**
* Host passed to `init:host:port:secure:`
View
3  src/common.h
@@ -132,6 +132,9 @@ typedef enum {
ISpdyParserDelegate,
ISpdySchedulerDelegate>
+// Invoke delegate logging if present
+- (void) _log: (ISpdyLogLevel) level format: (NSString*) msg, ...;
+
// Get fd out of streams
- (void) _fdWithBlock: (void(^)(CFSocketNativeHandle)) block;
View
27 src/ispdy.m
@@ -25,6 +25,7 @@
#import <dispatch/dispatch.h> // dispatch_queue_t
#import <netinet/in.h> // IPPROTO_TCP
#import <netinet/tcp.h> // TCP_NODELAY
+#import <stdarg.h> // va_start, va_end
#import <string.h> // memmove
#import <sys/socket.h> // setsockopt
#import <errno.h> // errno
@@ -503,6 +504,25 @@ - (void) _connectionDispatchSync: (void (^)()) block {
}
+- (void) _log: (ISpdyLogLevel) level format: (NSString*) format, ... {
+ if (self.delegate == nil)
+ return;
+
+ NSObject* d = (NSObject*) self.delegate;
+ if (![d respondsToSelector: @selector(logSpdyEvents:level:message:)])
+ return;
+
+ va_list args;
+ va_start(args, format);
+ NSString* str = [[NSString alloc] initWithFormat: format arguments: args];
+ va_end(args);
+
+ [self _delegateDispatch: ^{
+ [self.delegate logSpdyEvents: self level: level message: str];
+ }];
+}
+
+
- (void) _fdWithBlock: (void(^)(CFSocketNativeHandle)) block {
CFDataRef data =
CFWriteStreamCopyProperty((__bridge CFWriteStreamRef) out_stream_,
@@ -985,6 +1005,13 @@ - (BOOL) _checkPinnedCertificates: (NSStream*) stream {
// NSSocket delegate methods
- (void) stream: (NSStream*) stream handleEvent: (NSStreamEvent) event {
+ if (event == NSStreamEventOpenCompleted) {
+ [self _log: kISpdyLogInfo format: @"NSStream open"];
+ } else if (event == NSStreamEventEndEncountered) {
+ [self _log: kISpdyLogInfo format: @"NSStream end"];
+ } else if (event == NSStreamEventErrorOccurred) {
+ [self _log: kISpdyLogWarning format: @"NSStream error"];
+ }
[self _connectionDispatchSync: ^{
// Already closed, just return
if (in_stream_ == nil || out_stream_ == nil)

Showing you all comments on commits in this comparison.

@georgekola
Owner

Looks Good!

Something went wrong with that request. Please try again.