Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GCDWebServerConnection sub-class that can emulate different transfer speeds
//
// PANWebServerConnection.h
//
// Created by James Moore on 9/8/14.
//
#import "GCDWebServerConnection.h"
@interface PANWebServerConnection : GCDWebServerConnection
@end
//
// 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
You can’t perform that action at this time.