BLIP/BLIPTest.m
changeset 11 29e8b03c05d4
parent 8 6f539dd9921c
child 13 84c2d38f924c
     1.1 --- a/BLIP/BLIPTest.m	Thu May 29 16:40:36 2008 -0700
     1.2 +++ b/BLIP/BLIPTest.m	Tue Jun 03 16:56:33 2008 -0700
     1.3 @@ -25,6 +25,7 @@
     1.4  #endif
     1.5  
     1.6  
     1.7 +#define kListenerHost               @"localhost"
     1.8  #define kListenerPort               46353
     1.9  #define kSendInterval               0.5
    1.10  #define kNBatchedMessages           20
    1.11 @@ -66,7 +67,7 @@
    1.12      if (self != nil) {
    1.13          Log(@"** INIT %@",self);
    1.14          _pending = [[NSMutableDictionary alloc] init];
    1.15 -        IPAddress *addr = [[IPAddress alloc] initWithHostname: @"localhost" port: kListenerPort];
    1.16 +        IPAddress *addr = [[IPAddress alloc] initWithHostname: kListenerHost port: kListenerPort];
    1.17          _conn = [[BLIPConnection alloc] initToAddress: addr];
    1.18          if( ! _conn ) {
    1.19              [self release];
    1.20 @@ -99,30 +100,34 @@
    1.21  
    1.22  - (void) sendAMessage
    1.23  {
    1.24 -    Log(@"** Sending another %i messages...", kNBatchedMessages);
    1.25 -    for( int i=0; i<kNBatchedMessages; i++ ) {
    1.26 -        size_t size = random() % 32768;
    1.27 -        NSMutableData *body = [NSMutableData dataWithLength: size];
    1.28 -        UInt8 *bytes = body.mutableBytes;
    1.29 -        for( size_t i=0; i<size; i++ )
    1.30 -            bytes[i] = i % 256;
    1.31 -        
    1.32 -        BLIPRequest *q = [_conn requestWithBody: body
    1.33 -                                     properties: $dict({@"Content-Type", @"application/octet-stream"},
    1.34 -                                                       {@"User-Agent", @"BLIPConnectionTester"},
    1.35 -                                                       {@"Date", [[NSDate date] description]},
    1.36 -                                                       {@"Size",$sprintf(@"%u",size)})];
    1.37 -        Assert(q);
    1.38 -        if( kUseCompression && (random()%2==1) )
    1.39 -            q.compressed = YES;
    1.40 -        if( random()%16 > 12 )
    1.41 -            q.urgent = YES;
    1.42 -        BLIPResponse *response = [q send];
    1.43 -        Assert(response);
    1.44 -        Assert(q.number>0);
    1.45 -        Assert(response.number==q.number);
    1.46 -        [_pending setObject: $object(size) forKey: $object(q.number)];
    1.47 -        response.onComplete = $target(self,responseArrived:);
    1.48 +    if(_pending.count<100) {
    1.49 +        Log(@"** Sending another %i messages...", kNBatchedMessages);
    1.50 +        for( int i=0; i<kNBatchedMessages; i++ ) {
    1.51 +            size_t size = random() % 32768;
    1.52 +            NSMutableData *body = [NSMutableData dataWithLength: size];
    1.53 +            UInt8 *bytes = body.mutableBytes;
    1.54 +            for( size_t i=0; i<size; i++ )
    1.55 +                bytes[i] = i % 256;
    1.56 +            
    1.57 +            BLIPRequest *q = [_conn requestWithBody: body
    1.58 +                                         properties: $dict({@"Content-Type", @"application/octet-stream"},
    1.59 +                                                           {@"User-Agent", @"BLIPConnectionTester"},
    1.60 +                                                           {@"Date", [[NSDate date] description]},
    1.61 +                                                           {@"Size",$sprintf(@"%u",size)})];
    1.62 +            Assert(q);
    1.63 +            if( kUseCompression && (random()%2==1) )
    1.64 +                q.compressed = YES;
    1.65 +            if( random()%16 > 12 )
    1.66 +                q.urgent = YES;
    1.67 +            BLIPResponse *response = [q send];
    1.68 +            Assert(response);
    1.69 +            Assert(q.number>0);
    1.70 +            Assert(response.number==q.number);
    1.71 +            [_pending setObject: $object(size) forKey: $object(q.number)];
    1.72 +            response.onComplete = $target(self,responseArrived:);
    1.73 +        }
    1.74 +    } else {
    1.75 +        Warn(@"There are %u pending messages; waiting for the listener to catch up...",_pending.count);
    1.76      }
    1.77      [self performSelector: @selector(sendAMessage) withObject: nil afterDelay: kSendInterval];
    1.78  }
    1.79 @@ -184,7 +189,6 @@
    1.80      Assert(sizeObj);
    1.81      [_pending removeObjectForKey: $object(response.number)];
    1.82      Log(@"Now %u replies pending", _pending.count);
    1.83 -    Assert(_pending.count<100);
    1.84  }
    1.85  
    1.86