-
Notifications
You must be signed in to change notification settings - Fork 39
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
Showing
46 changed files
with
2,029 additions
and
897 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
DarkLightning.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
This file was deleted.
Oops, something went wrong.
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
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,55 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Jens Meder | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import "JMSocket.h" | ||
|
||
/** | ||
* Represents a socket to a given host. | ||
*/ | ||
@interface JMHostSocket : NSObject<JMSocket> | ||
|
||
/** | ||
* The port to which the socket is bound to. | ||
*/ | ||
@property (readonly) uint32_t port; | ||
|
||
/** | ||
* The host to which the socket is bound to. | ||
*/ | ||
@property (nonnull, nonatomic, strong, readonly) NSString* host; | ||
|
||
///--------------------- | ||
/// @name Initialization | ||
///--------------------- | ||
|
||
/** | ||
* Initializes and returns a newly | ||
* | ||
* @param host The host to which the socket should be bound to. | ||
* @param port The port to which the socket should be bound to. | ||
* | ||
* @return A newly initialized socket if the given host and port are valid, nil otherwise. | ||
*/ | ||
-(nullable instancetype)initWithHost:(nonnull NSString*)host andPort:(uint32_t)port; | ||
|
||
@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,102 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Jens Meder | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import "JMHostSocket.h" | ||
|
||
@implementation JMHostSocket | ||
|
||
@synthesize inputStream = _inputStream; | ||
@synthesize outputStream = _outputStream; | ||
@synthesize state = _state; | ||
|
||
-(instancetype)initWithHost:(NSString *)host andPort:(uint32_t)port | ||
{ | ||
if (!host || !host.length) | ||
{ | ||
return nil; | ||
} | ||
|
||
self = [super init]; | ||
|
||
if (self) | ||
{ | ||
_host = host; | ||
_port = port; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
-(BOOL)connect | ||
{ | ||
if (self.state != JMSocketStateDisconnected) | ||
{ | ||
return NO; | ||
} | ||
|
||
self.state = JMSocketStateConnecting; | ||
|
||
CFReadStreamRef readStream; | ||
CFWriteStreamRef writeStream; | ||
|
||
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef) self.host, self.port, &readStream, &writeStream); | ||
|
||
_inputStream = (__bridge NSInputStream *)(readStream); | ||
_outputStream = (__bridge NSOutputStream *)(writeStream); | ||
|
||
self.state = JMSocketStateConnected; | ||
|
||
return YES; | ||
} | ||
|
||
-(BOOL)disconnect | ||
{ | ||
if (self.state == JMSocketStateDisconnected) | ||
{ | ||
return YES; | ||
} | ||
|
||
self.state = JMSocketStateDisconnected; | ||
|
||
[_inputStream close]; | ||
[_outputStream close]; | ||
|
||
_inputStream = nil; | ||
_outputStream = nil; | ||
|
||
return YES; | ||
} | ||
|
||
#pragma mark - Properties | ||
|
||
-(void) setState:(JMSocketState)state | ||
{ | ||
if (state == _state) | ||
{ | ||
return; | ||
} | ||
|
||
_state = state; | ||
} | ||
|
||
@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,52 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Jens Meder | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <CoreFoundation/CoreFoundation.h> | ||
#import "JMSocket.h" | ||
|
||
|
||
/** | ||
* Represents a socket to a native socket. | ||
*/ | ||
@interface JMNativeSocket : NSObject<JMSocket> | ||
|
||
/** | ||
* The native socket to which the socket is bound to. | ||
*/ | ||
@property (readonly) CFSocketNativeHandle nativeSocket; | ||
|
||
///--------------------- | ||
/// @name Initialization | ||
///--------------------- | ||
|
||
/** | ||
* Initializes a socket with the given native socket. | ||
* | ||
* @param nativeSocket The native socket to which the socket is bound to. | ||
* | ||
* @return A newly initialized socket if the given native socket is valid, nil otherwise. | ||
*/ | ||
-(instancetype)initWithNativeSocket:(CFSocketNativeHandle)nativeSocket; | ||
|
||
@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,105 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Jens Meder | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import "JMNativeSocket.h" | ||
|
||
@implementation JMNativeSocket | ||
|
||
@synthesize inputStream = _inputStream; | ||
@synthesize outputStream = _outputStream; | ||
@synthesize state = _state; | ||
|
||
-(instancetype)initWithNativeSocket:(CFSocketNativeHandle)nativeSocket | ||
{ | ||
if (nativeSocket < 0) | ||
{ | ||
return nil; | ||
} | ||
|
||
self = [super init]; | ||
|
||
if (self) | ||
{ | ||
_nativeSocket = nativeSocket; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
-(BOOL)connect | ||
{ | ||
if (self.state != JMSocketStateDisconnected) | ||
{ | ||
return NO; | ||
} | ||
|
||
self.state = JMSocketStateConnecting; | ||
|
||
CFReadStreamRef readStream; | ||
CFWriteStreamRef writeStream; | ||
|
||
CFStreamCreatePairWithSocket(kCFAllocatorDefault, _nativeSocket, &readStream, &writeStream); | ||
|
||
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); | ||
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); | ||
|
||
_inputStream = (__bridge NSInputStream *)(readStream); | ||
_outputStream = (__bridge NSOutputStream *)(writeStream); | ||
|
||
self.state = JMSocketStateConnected; | ||
|
||
return YES; | ||
} | ||
|
||
-(BOOL)disconnect | ||
{ | ||
if (self.state == JMSocketStateDisconnected) | ||
{ | ||
return YES; | ||
} | ||
|
||
self.state = JMSocketStateDisconnected; | ||
|
||
[_inputStream close]; | ||
[_outputStream close]; | ||
|
||
_inputStream = nil; | ||
_outputStream = nil; | ||
|
||
return YES; | ||
} | ||
|
||
#pragma mark - Properties | ||
|
||
-(void) setState:(JMSocketState)state | ||
{ | ||
if (state == _state) | ||
{ | ||
return; | ||
} | ||
|
||
_state = state; | ||
} | ||
|
||
|
||
@end |
Oops, something went wrong.