Skip to content

Commit

Permalink
Merge branch 'release-1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Nov 6, 2017
2 parents 16eacd8 + d3da517 commit a54f38e
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 122 deletions.
4 changes: 1 addition & 3 deletions Core/Source/DTBonjourDataConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ - (BOOL)sendObject:(id)object error:(NSError **)error

if (queueWasEmpty && _outputStream.streamStatus == NSStreamStatusOpen)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self _startOutput];
});
[self _startOutput];
}

return YES;
Expand Down
190 changes: 96 additions & 94 deletions Core/Source/DTBonjourServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ - (void)dealloc
[[NSNotificationCenter defaultCenter] removeObserver:self];

_delegate = nil;

[self stop];
}

Expand Down Expand Up @@ -209,8 +209,8 @@ - (BOOL)start
}

assert(self.port > 0 && self.port < 65536);
_service = [[NSNetService alloc] initWithDomain:@"" type:_bonjourType name:@"" port:(int)_port];
_service.delegate = self;
NSString *name = [[NSUUID UUID] UUIDString];
_service = [[NSNetService alloc] initWithDomain:@"" type:_bonjourType name:name port:(int)_port]; _service.delegate = self;

if (_TXTRecord)
{
Expand All @@ -224,86 +224,86 @@ - (BOOL)start

/*
// this is the way to create the sockets on the Posix-level
- (BOOL)start
{
CFSocketContext context = {0, (__bridge void *)self, NULL, NULL, NULL};
// create IPv4 socket
int fd4 = socket(AF_INET, SOCK_STREAM, 0);
// allow for reuse of local address
static const int yes = 1;
int err = setsockopt(fd4, SOL_SOCKET, SO_REUSEADDR, (const void *) &yes, sizeof(yes));
// a structure for the socket address
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
sin.sin_port = htons(0); // asks kernel for arbitrary port number
err = bind(fd4, (const struct sockaddr *) &sin, sin.sin_len);
socklen_t addrLen = sizeof(sin);
err = getsockname(fd4, (struct sockaddr *)&sin, &addrLen);
err = listen(fd4, 5);
// should have a port number now
_port = sin.sin_port;
if (!_port)
{
return NO;
}
// create a CFSocket for the file descriptor
_ipv4socket = CFSocketCreateWithNative(NULL, fd4, kCFSocketAcceptCallBack, ListeningSocketCallback, &context);
// create IPv6 socket
int fd6 = socket(AF_INET6, SOCK_STREAM, 0);
int one = 1;
err = setsockopt(fd6, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one));
err = setsockopt(fd6, SOL_SOCKET, SO_REUSEADDR, (const void *) &yes, sizeof(yes));
struct sockaddr_in sin6;
memset(&sin6, 0, sizeof(sin6));
sin6.sin_family = AF_INET6;
sin6.sin_len = sizeof(sin6);
sin6.sin_port = sin.sin_port; // uses same port as IPv4
err = bind(fd6, (const struct sockaddr *) &sin6, sin6.sin_len);
err = listen(fd6, 5);
// create a CFSocket for the file descriptor
_ipv6socket = CFSocketCreateWithNative(NULL, fd6, kCFSocketAcceptCallBack, ListeningSocketCallback, &context);
// Set up the run loop sources for the sockets.
CFRunLoopSourceRef source4 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _ipv4socket, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source4, kCFRunLoopCommonModes);
CFRelease(source4);
CFRunLoopSourceRef source6 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _ipv6socket, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source6, kCFRunLoopCommonModes);
CFRelease(source6);
_service = [[NSNetService alloc] initWithDomain:@"" // use all available domains
type:_bonjourType
name:@"" // uses default name of system
port:ntohs(_port)];
[_service scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
_service.delegate = self;
[_service publish];
#if TARGET_OS_IPHONE
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
#endif
return YES;
}
- (BOOL)start
{
CFSocketContext context = {0, (__bridge void *)self, NULL, NULL, NULL};
// create IPv4 socket
int fd4 = socket(AF_INET, SOCK_STREAM, 0);
// allow for reuse of local address
static const int yes = 1;
int err = setsockopt(fd4, SOL_SOCKET, SO_REUSEADDR, (const void *) &yes, sizeof(yes));
// a structure for the socket address
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
sin.sin_port = htons(0); // asks kernel for arbitrary port number
err = bind(fd4, (const struct sockaddr *) &sin, sin.sin_len);
socklen_t addrLen = sizeof(sin);
err = getsockname(fd4, (struct sockaddr *)&sin, &addrLen);
err = listen(fd4, 5);
// should have a port number now
_port = sin.sin_port;
if (!_port)
{
return NO;
}
// create a CFSocket for the file descriptor
_ipv4socket = CFSocketCreateWithNative(NULL, fd4, kCFSocketAcceptCallBack, ListeningSocketCallback, &context);
// create IPv6 socket
int fd6 = socket(AF_INET6, SOCK_STREAM, 0);
int one = 1;
err = setsockopt(fd6, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one));
err = setsockopt(fd6, SOL_SOCKET, SO_REUSEADDR, (const void *) &yes, sizeof(yes));
struct sockaddr_in sin6;
memset(&sin6, 0, sizeof(sin6));
sin6.sin_family = AF_INET6;
sin6.sin_len = sizeof(sin6);
sin6.sin_port = sin.sin_port; // uses same port as IPv4
err = bind(fd6, (const struct sockaddr *) &sin6, sin6.sin_len);
err = listen(fd6, 5);
// create a CFSocket for the file descriptor
_ipv6socket = CFSocketCreateWithNative(NULL, fd6, kCFSocketAcceptCallBack, ListeningSocketCallback, &context);
// Set up the run loop sources for the sockets.
CFRunLoopSourceRef source4 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _ipv4socket, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source4, kCFRunLoopCommonModes);
CFRelease(source4);
CFRunLoopSourceRef source6 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _ipv6socket, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source6, kCFRunLoopCommonModes);
CFRelease(source6);
_service = [[NSNetService alloc] initWithDomain:@"" // use all available domains
type:_bonjourType
name:@"" // uses default name of system
port:ntohs(_port)];
[_service scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
_service.delegate = self;
[_service publish];
#if TARGET_OS_IPHONE
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
#endif
return YES;
}
*/

- (void)stop
Expand Down Expand Up @@ -355,12 +355,14 @@ - (void)broadcastObject:(id)object
{
for (DTBonjourDataConnection *connection in _connections)
{
NSError *error;

if (![connection sendObject:object error:&error])
{
NSLog(@"%@", [error localizedDescription]);
}
//MatthewCawley: move this call to a background thread to prevent UI Block and allow parallelization
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
NSError *error;
if (![connection sendObject:object error:&error])
{
NSLog(@"%@", [error localizedDescription]);
}
});
}
}

Expand Down Expand Up @@ -393,10 +395,10 @@ - (void)connection:(DTBonjourDataConnection *)connection didReceiveObject:(id)ob
- (void)connectionDidClose:(DTBonjourDataConnection *)connection
{
[_connections removeObject:connection];
if ([_delegate respondsToSelector:@selector(bonjourServer:didCloseConnection:)])
{
[_delegate bonjourServer:self didCloseConnection:connection];
}
if ([_delegate respondsToSelector:@selector(bonjourServer:didCloseConnection:)])
{
[_delegate bonjourServer:self didCloseConnection:connection];
}
}

#pragma mark - Notifications
Expand All @@ -422,7 +424,7 @@ - (NSSet *)connections
- (void)setTXTRecord:(NSDictionary *)TXTRecord
{
_TXTRecord = TXTRecord;

// update service if it is running
if (_service)
{
Expand Down
6 changes: 4 additions & 2 deletions DTBonjour.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Pod::Spec.new do |spec|
spec.name = 'DTBonjour'
spec.version = '1.1.2'
spec.version = '1.1.3'
spec.summary = "Client/Server Communication of NSObjects over WiFi."
spec.homepage = "https://github.com/Cocoanetics/DTBonjour"
spec.author = { "Oliver Drobnik" => "[email protected]" }
spec.source = { :git => "https://github.com/Cocoanetics/DTBonjour.git", :tag => spec.version.to_s }
spec.source_files = 'Core/Source/*.{h,m}'
spec.license = 'BSD'
spec.ios.deployment_target = '5.0'
spec.osx.deployment_target = '10.7'
spec.osx.deployment_target = '10.8'
spec.tvos.deployment_target = '9.1'
spec.ios.frameworks = ["CoreFoundation", "Foundation", "UIKit"]
spec.tvos.frameworks = ["CoreFoundation", "Foundation", "UIKit"]
spec.osx.frameworks = ["CoreFoundation", "Foundation"]
spec.requires_arc = true
end
42 changes: 29 additions & 13 deletions DTBonjour.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
A719021116A7F5E300C1EC52 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "Drobnik KG";
};
buildConfigurationList = A719021416A7F5E300C1EC52 /* Build configuration list for PBXProject "DTBonjour" */;
Expand Down Expand Up @@ -281,22 +281,32 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -311,15 +321,24 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
Expand All @@ -330,10 +349,6 @@
A719022816A7F5E300C1EC52 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
"$(ARCHS_STANDARD)",
armv7s,
);
DSTROOT = /tmp/DTBonjour.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Core/DTBonjour-Prefix.pch";
Expand All @@ -344,10 +359,6 @@
A719022916A7F5E300C1EC52 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
"$(ARCHS_STANDARD)",
armv7s,
);
DSTROOT = /tmp/DTBonjour.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Core/DTBonjour-Prefix.pch";
Expand Down Expand Up @@ -391,24 +402,33 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"COVERAGE=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -419,10 +439,6 @@
A73FC7271AB189C90052DC07 /* Coverage */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
"$(ARCHS_STANDARD)",
armv7s,
);
DSTROOT = /tmp/DTBonjour.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Core/DTBonjour-Prefix.pch";
Expand Down
Loading

0 comments on commit a54f38e

Please sign in to comment.