Merge branch 'feature/buffer-increase' into develop

This commit is contained in:
Sergey Abramchuk 2017-05-10 14:58:14 +03:00
commit a128cf248f
2 changed files with 24 additions and 1 deletions

View File

@ -88,6 +88,11 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
return NO;
}
if (![self configureBufferSizeForSocket: sockets[0]] || ![self configureBufferSizeForSocket: sockets[1]]) {
NSLog(@"Failed to configure buffer size of the sockets");
return NO;
}
CFSocketContext socketCtxt = {0, (__bridge void *)self, NULL, NULL, NULL};
self.vpnSocket = CFSocketCreateWithNative(kCFAllocatorDefault, sockets[0], kCFSocketDataCallBack, &socketCallback, &socketCtxt);
@ -106,6 +111,23 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
return YES;
}
- (BOOL)configureBufferSizeForSocket:(int)socket {
int buf_value = 65536;
socklen_t buf_len = sizeof(buf_value);
if (setsockopt(socket, SOL_SOCKET, SO_RCVBUF, &buf_value, buf_len) == -1) {
NSLog(@"Failed to setup buffer size for input: %@", [NSString stringWithUTF8String:strerror(errno)]);
return NO;
}
if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, &buf_value, buf_len) == -1) {
NSLog(@"Failed to setup buffer size for output: %@", [NSString stringWithUTF8String:strerror(errno)]);
return NO;
}
return YES;
}
#pragma mark TUN Configuration
- (BOOL)setRemoteAddress:(NSString *)address isIPv6:(BOOL)isIPv6 {

View File

@ -57,7 +57,8 @@ NSString *const OpenVPNTLSCertProfileDefaultValue = @"default";
OpenVPNTransportProtocolDefaultValue: @(OpenVPNTransportProtocolDefault)
};
NSString *currentValue = [value length] == 0 ? OpenVPNTransportProtocolDefaultValue : value;
NSString *currentValue = [value length] == 0 ? OpenVPNTransportProtocolDefaultValue :
[[value componentsSeparatedByString:@"-"] firstObject];
NSNumber *transportProtocol = options[currentValue];
NSAssert(transportProtocol != nil, @"Incorrect protocol value: %@", currentValue);