Created
September 8, 2014 22:17
-
-
Save foozmeat/d0a1fe8f7beceef139b0 to your computer and use it in GitHub Desktop.
GCDWebServerConnection sub-class that can emulate different transfer speeds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PANWebServerConnection.h | |
// | |
// Created by James Moore on 9/8/14. | |
// | |
#import "GCDWebServerConnection.h" | |
@interface PANWebServerConnection : GCDWebServerConnection | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PANWebServerConnection.m | |
// | |
// Created by James Moore on 9/8/14. | |
// | |
#import "PANWebServerConnection.h" | |
@interface PANWebServerConnection() | |
@end | |
const NSUInteger throughput = 14400; | |
const NSUInteger minimumDelay = 1000000; | |
@implementation PANWebServerConnection | |
- (void)didReadBytes:(const void *)bytes length:(NSUInteger)length | |
{ | |
[self delayForLength:length]; | |
[super didReadBytes:bytes length:length]; | |
} | |
- (void)didWriteBytes:(const void *)bytes length:(NSUInteger)length | |
{ | |
[self delayForLength:length]; | |
[super didReadBytes:bytes length:length]; | |
} | |
- (void)delayForLength:(NSUInteger)length | |
{ | |
NSUInteger delay = ((length / throughput) * 1000000); | |
if (delay < minimumDelay) { | |
delay = minimumDelay; | |
} | |
usleep((unsigned int)delay); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment