|
|
@ -1,6 +1,7 @@
|
|
|
|
#import "Constraints.h"
|
|
|
|
#import "Constraints.h"
|
|
|
|
#import "ThreadManager.h"
|
|
|
|
#import "ThreadManager.h"
|
|
|
|
#import "UdpSocket.h"
|
|
|
|
#import "UdpSocket.h"
|
|
|
|
|
|
|
|
#import "IPAddress.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation UdpSocket
|
|
|
|
@implementation UdpSocket
|
|
|
|
|
|
|
|
|
|
|
@ -131,8 +132,14 @@ void onReceivedData(CFSocketRef socket, CFSocketCallBackType type, CFDataRef add
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void) setupLocalEndPoint {
|
|
|
|
-(void) setupLocalEndPoint {
|
|
|
|
IpEndPoint* specifiedLocalEndPoint = [IpEndPoint ipEndPointAtUnspecifiedAddressOnPort:specifiedLocalPort];
|
|
|
|
IpEndPoint *specifiedLocalEndPoint;
|
|
|
|
|
|
|
|
if (self.isRemoteEndPointKnown) {
|
|
|
|
|
|
|
|
specifiedLocalEndPoint = [specifiedRemoteEndPoint correspondingLocalEndpointWithPort:specifiedLocalPort];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
DDLogWarn(@"%@ no remote end point. This is only used in unit tests.", self.tag);
|
|
|
|
|
|
|
|
specifiedLocalEndPoint = [IpEndPoint ipv4EndPointAtUnspecifiedAddressOnPort:specifiedLocalPort];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CFSocketError setAddressResult = CFSocketSetAddress(socket, (__bridge CFDataRef)[specifiedLocalEndPoint sockaddrData]);
|
|
|
|
CFSocketError setAddressResult = CFSocketSetAddress(socket, (__bridge CFDataRef)[specifiedLocalEndPoint sockaddrData]);
|
|
|
|
checkOperationDescribe(setAddressResult == kCFSocketSuccess,
|
|
|
|
checkOperationDescribe(setAddressResult == kCFSocketSuccess,
|
|
|
|
([NSString stringWithFormat:@"CFSocketSetAddress failed with error code: %ld", setAddressResult]));
|
|
|
|
([NSString stringWithFormat:@"CFSocketSetAddress failed with error code: %ld", setAddressResult]));
|
|
|
@ -165,9 +172,16 @@ void onReceivedData(CFSocketRef socket, CFSocketCallBackType type, CFDataRef add
|
|
|
|
|
|
|
|
|
|
|
|
@try {
|
|
|
|
@try {
|
|
|
|
CFSocketContext socketContext = { 0, (__bridge void *)self, CFRetain, CFRelease, CFCopyDescription };
|
|
|
|
CFSocketContext socketContext = { 0, (__bridge void *)self, CFRetain, CFRelease, CFCopyDescription };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SInt32 protocolFamily;
|
|
|
|
|
|
|
|
if (self.isRemoteEndPointKnown) {
|
|
|
|
|
|
|
|
protocolFamily = specifiedRemoteEndPoint.address.isIpv4 ? PF_INET : PF_INET6;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
DDLogWarn(@"Uknown remote endpoint. This is only used in testing.");
|
|
|
|
|
|
|
|
protocolFamily = PF_INET;
|
|
|
|
|
|
|
|
}
|
|
|
|
socket = CFSocketCreate(kCFAllocatorDefault,
|
|
|
|
socket = CFSocketCreate(kCFAllocatorDefault,
|
|
|
|
PF_INET,
|
|
|
|
protocolFamily,
|
|
|
|
SOCK_DGRAM,
|
|
|
|
SOCK_DGRAM,
|
|
|
|
IPPROTO_UDP,
|
|
|
|
IPPROTO_UDP,
|
|
|
|
kCFSocketDataCallBack,
|
|
|
|
kCFSocketDataCallBack,
|
|
|
@ -194,4 +208,16 @@ void onReceivedData(CFSocketRef socket, CFSocketCallBackType type, CFDataRef add
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return self.class.tag;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|