1.1 --- a/BLIP/BLIPTest.m Wed Jun 04 17:11:20 2008 -0700
1.2 +++ b/BLIP/BLIPTest.m Thu Jun 19 16:22:05 2008 -0700
1.3 @@ -35,6 +35,7 @@
1.4 #define kClientUsesSSLCert NO
1.5 #define kListenerRequiresSSL NO
1.6 #define kListenerRequiresClientCert NO
1.7 +#define kListenerCloseAfter 50
1.8
1.9
1.10 static SecIdentityRef GetClientIdentity(void) {
1.11 @@ -100,36 +101,38 @@
1.12
1.13 - (void) sendAMessage
1.14 {
1.15 - if(_pending.count<100) {
1.16 - Log(@"** Sending another %i messages...", kNBatchedMessages);
1.17 - for( int i=0; i<kNBatchedMessages; i++ ) {
1.18 - size_t size = random() % 32768;
1.19 - NSMutableData *body = [NSMutableData dataWithLength: size];
1.20 - UInt8 *bytes = body.mutableBytes;
1.21 - for( size_t i=0; i<size; i++ )
1.22 - bytes[i] = i % 256;
1.23 -
1.24 - BLIPRequest *q = [_conn requestWithBody: body
1.25 - properties: $dict({@"Content-Type", @"application/octet-stream"},
1.26 - {@"User-Agent", @"BLIPConnectionTester"},
1.27 - {@"Date", [[NSDate date] description]},
1.28 - {@"Size",$sprintf(@"%u",size)})];
1.29 - Assert(q);
1.30 - if( kUseCompression && (random()%2==1) )
1.31 - q.compressed = YES;
1.32 - if( random()%16 > 12 )
1.33 - q.urgent = YES;
1.34 - BLIPResponse *response = [q send];
1.35 - Assert(response);
1.36 - Assert(q.number>0);
1.37 - Assert(response.number==q.number);
1.38 - [_pending setObject: $object(size) forKey: $object(q.number)];
1.39 - response.onComplete = $target(self,responseArrived:);
1.40 + if( _conn.status==kTCP_Open || _conn.status==kTCP_Opening ) {
1.41 + if(_pending.count<100) {
1.42 + Log(@"** Sending another %i messages...", kNBatchedMessages);
1.43 + for( int i=0; i<kNBatchedMessages; i++ ) {
1.44 + size_t size = random() % 32768;
1.45 + NSMutableData *body = [NSMutableData dataWithLength: size];
1.46 + UInt8 *bytes = body.mutableBytes;
1.47 + for( size_t i=0; i<size; i++ )
1.48 + bytes[i] = i % 256;
1.49 +
1.50 + BLIPRequest *q = [_conn requestWithBody: body
1.51 + properties: $dict({@"Content-Type", @"application/octet-stream"},
1.52 + {@"User-Agent", @"BLIPConnectionTester"},
1.53 + {@"Date", [[NSDate date] description]},
1.54 + {@"Size",$sprintf(@"%u",size)})];
1.55 + Assert(q);
1.56 + if( kUseCompression && (random()%2==1) )
1.57 + q.compressed = YES;
1.58 + if( random()%16 > 12 )
1.59 + q.urgent = YES;
1.60 + BLIPResponse *response = [q send];
1.61 + Assert(response);
1.62 + Assert(q.number>0);
1.63 + Assert(response.number==q.number);
1.64 + [_pending setObject: $object(size) forKey: $object(q.number)];
1.65 + response.onComplete = $target(self,responseArrived:);
1.66 + }
1.67 + } else {
1.68 + Warn(@"There are %u pending messages; waiting for the listener to catch up...",_pending.count);
1.69 }
1.70 - } else {
1.71 - Warn(@"There are %u pending messages; waiting for the listener to catch up...",_pending.count);
1.72 + [self performSelector: @selector(sendAMessage) withObject: nil afterDelay: kSendInterval];
1.73 }
1.74 - [self performSelector: @selector(sendAMessage) withObject: nil afterDelay: kSendInterval];
1.75 }
1.76
1.77 - (void) responseArrived: (BLIPResponse*)response
1.78 @@ -217,6 +220,7 @@
1.79 @interface BLIPTestListener : NSObject <TCPListenerDelegate, BLIPConnectionDelegate>
1.80 {
1.81 BLIPListener *_listener;
1.82 + int _nReceived;
1.83 }
1.84
1.85 @end
1.86 @@ -277,6 +281,7 @@
1.87 - (void) connectionDidOpen: (TCPConnection*)connection
1.88 {
1.89 Log(@"** %@ didOpen [SSL=%@]",connection,connection.actualSecurityLevel);
1.90 + _nReceived = 0;
1.91 }
1.92 - (BOOL) connection: (TCPConnection*)connection authorizeSSLPeer: (SecCertificateRef)peerCert
1.93 {
1.94 @@ -312,6 +317,11 @@
1.95 AssertEq([[request valueOfProperty: @"Size"] intValue], size);
1.96
1.97 [request respondWithData: body contentType: request.contentType];
1.98 +
1.99 + if( ++ _nReceived == kListenerCloseAfter ) {
1.100 + Log(@"********** Closing BLIPTestListener after %i requests",_nReceived);
1.101 + [connection close];
1.102 + }
1.103 }
1.104
1.105