-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dev2
committed
Oct 22, 2012
1 parent
30f3d2d
commit 6b629c6
Showing
12 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionOperation/DXHTTPConnectionOperation.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// DXHTTPConnectionOperation.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "DXHTTPConnectionThread.h" | ||
|
||
@interface DXHTTPConnectionOperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate> | ||
|
||
- (id)initWithURLRequest:(NSURLRequest *)aURLRequest; | ||
|
||
@end |
65 changes: 65 additions & 0 deletions
65
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionOperation/DXHTTPConnectionOperation.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// DXHTTPConnectionOperation.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionOperation.h" | ||
|
||
@interface DXHTTPConnectionOperation() { | ||
NSURLRequest *_urlRequest; | ||
NSURLConnection *_urlConnection; | ||
NSMutableData *_connectionData; | ||
NSMutableDictionary *_connectionResponseHeaders; | ||
BOOL _executing; | ||
} | ||
|
||
@end | ||
|
||
@implementation DXHTTPConnectionOperation | ||
|
||
- (id)initWithURLRequest:(NSURLRequest *)aURLRequest { | ||
self = [super init]; | ||
if (self) { | ||
_urlRequest = aURLRequest; | ||
_connectionData = [NSMutableData new]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)start { | ||
[self performSelector:@selector(connectionOpeartionDidStart) onThread:[DXHTTPConnectionThread requestConnectionThread] withObject:nil waitUntilDone:NO]; | ||
|
||
} | ||
|
||
- (void)connectionOpeartionDidStart { | ||
_executing = YES; | ||
_urlConnection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self]; | ||
NSRunLoop *connectionRunLoop = [NSRunLoop currentRunLoop]; | ||
[_urlConnection scheduleInRunLoop:connectionRunLoop forMode:NSRunLoopCommonModes]; | ||
[_urlConnection start]; | ||
} | ||
|
||
- (BOOL)isExecuting { | ||
return _executing; | ||
} | ||
|
||
- (BOOL)isConcurrent { | ||
return YES; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { | ||
[_connectionData setLength:0]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { | ||
[_connectionData appendData:data]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { | ||
_executing = NO; | ||
} | ||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionThread/DXHTTPConnectionThread.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// DXHTTPConnectionThread.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnectionThread : NSObject | ||
|
||
+ (NSThread *)requestConnectionThread; | ||
|
||
@end |
37 changes: 37 additions & 0 deletions
37
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionThread/DXHTTPConnectionThread.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// DXHTTPConnectionThread.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionThread.h" | ||
|
||
@interface DXHTTPConnectionThread() | ||
|
||
@end | ||
|
||
@implementation DXHTTPConnectionThread | ||
|
||
static NSThread *_connectionThread; | ||
|
||
+ (void)connectionThreadEntry:(id)object { | ||
do { | ||
@autoreleasepool { | ||
[[NSRunLoop currentRunLoop] run]; | ||
} | ||
} while (YES); | ||
} | ||
|
||
+ (NSThread *)requestConnectionThread { | ||
static dispatch_once_t allocThreadOnce; | ||
|
||
dispatch_once(&allocThreadOnce, ^{ | ||
_connectionThread = [[NSThread alloc] initWithTarget:self selector:@selector(connectionThreadEntry:) object:nil]; | ||
[_connectionThread start]; | ||
}); | ||
return _connectionThread; | ||
} | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionOperation.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnectionOperation : NSOperation | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionOperation.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionOperation.h" | ||
|
||
@implementation DXHTTPConnectionOperation | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
DXHTTPKit/Code/Base/DXHTTPConnectionThread/DXHTTPConnectionThread.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionThread.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnectionThread : NSObject | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
DXHTTPKit/Code/Base/DXHTTPConnectionThread/DXHTTPConnectionThread.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionThread.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionThread.h" | ||
|
||
@implementation DXHTTPConnectionThread | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnection.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnection : NSObject | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#import "Kiwi.h" | ||
#import "DXHTTPConnectionOperation.h" | ||
|
||
SPEC_BEGIN(DXHTTPConnectionSpec) | ||
|
||
describe(@"DXHTTPConnection", ^{ | ||
it(@"Should start NSURLConnection in DXHTTPConnectionOperation", ^{ | ||
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://localhost"]]; | ||
DXHTTPConnectionOperation *connectionOperation = [[DXHTTPConnectionOperation alloc] initWithURLRequest:urlRequest]; | ||
[connectionOperation start]; | ||
}); | ||
}); | ||
|
||
SPEC_END |
Empty file.