Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RealReachability/Ping/PingHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ extern NSString *const kPingResultNotification;
// Ping timeout. Default is 2 seconds
@property (nonatomic, assign) NSTimeInterval timeout;

@property (readonly) NSTimeInterval previousSuccessDuration;
@property (readonly) int numberOfFailedPings;

+ (instancetype)sharedInstance;

/**
Expand Down
15 changes: 15 additions & 0 deletions RealReachability/Ping/PingHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @interface PingHelper() <PingFoundationDelegate>
@property (nonatomic, strong) NSMutableArray *completionBlocks;
@property(nonatomic, strong) PingFoundation *pingFoundation;
@property (nonatomic, assign) BOOL isPinging;
@property (nonatomic) NSDate *pingStartTime;

@end

Expand Down Expand Up @@ -107,6 +108,7 @@ - (void)clearPingFoundation
- (void)startPing
{
//NSLog(@"startPing");
_pingStartTime = [NSDate date];
[self clearPingFoundation];

self.isPinging = YES;
Expand Down Expand Up @@ -135,6 +137,15 @@ - (void)setHost:(NSString *)host

- (void)endWithFlag:(BOOL)isSuccess
{
if (isSuccess) {

NSTimeInterval duration = [_pingStartTime timeIntervalSinceNow];
_previousSuccessDuration = fabs(duration*100);

}else{
_numberOfFailedPings ++;
}

// TODO(optimization):
//somewhere around here we should introduce a double check after 3 seconds on another host,
// if maybe not truely failed.
Expand Down Expand Up @@ -188,6 +199,10 @@ - (void)pingFoundation:(PingFoundation *)pinger didFailToSendPacket:(NSData *)pa
- (void)pingFoundation:(PingFoundation *)pinger didReceivePingResponsePacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber
{
//NSLog(@"didReceivePingResponsePacket, sequenceNumber = %@", @(sequenceNumber));

NSTimeInterval duration = [_pingStartTime timeIntervalSinceNow];
_previousSuccessDuration = duration/1000;

[self endWithFlag:YES];
}

Expand Down