Skip to content

Instantly share code, notes, and snippets.

@foozmeat
Created September 8, 2014 22:17
Show Gist options
  • Select an option

  • Save foozmeat/d0a1fe8f7beceef139b0 to your computer and use it in GitHub Desktop.

Select an option

Save foozmeat/d0a1fe8f7beceef139b0 to your computer and use it in GitHub Desktop.

Revisions

  1. foozmeat created this gist Sep 8, 2014.
    11 changes: 11 additions & 0 deletions PANWebServerConnection.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    //
    // PANWebServerConnection.h
    //
    // Created by James Moore on 9/8/14.
    //

    #import "GCDWebServerConnection.h"

    @interface PANWebServerConnection : GCDWebServerConnection

    @end
    49 changes: 49 additions & 0 deletions PANWebServerConnection.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    //
    // 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