Skip to content

Commit 2c0f2d1

Browse files
committed
Workaround for apple bug.
1 parent f59872c commit 2c0f2d1

File tree

6 files changed

+43
-69
lines changed

6 files changed

+43
-69
lines changed

GCD/GCDAsyncSocket.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6119,7 +6119,26 @@ - (void)maybeStartTLS
61196119
BOOL r1 = CFReadStreamSetProperty(readStream, kCFStreamPropertySSLSettings, (CFDictionaryRef)tlsSettings);
61206120
BOOL r2 = CFWriteStreamSetProperty(writeStream, kCFStreamPropertySSLSettings, (CFDictionaryRef)tlsSettings);
61216121

6122-
if (!r1 || !r2)
6122+
// For some reason, starting around the time of iOS 4.3,
6123+
// the first call to set the kCFStreamPropertySSLSettings will return true,
6124+
// but the second will return false.
6125+
//
6126+
// Order doesn't seem to matter.
6127+
// So you could call CFReadStreamSetProperty and then CFWriteStreamSetProperty, or you could reverse the order.
6128+
// Either way, the first call will return true, and the second returns false.
6129+
//
6130+
// Interestingly, this doesn't seem to affect anything.
6131+
// Which is not altogether unusual, as the documentation seems to suggest that (for many settings)
6132+
// setting it on one side of the stream automatically sets it for the other side of the stream.
6133+
//
6134+
// Although there isn't anything in the documentation to suggest that the second attempt would fail.
6135+
//
6136+
// Furthermore, this only seems to affect streams that are negotiating a security upgrade.
6137+
// In other words, the socket gets connected, there is some back-and-forth communication over the unsecure
6138+
// connection, and then a startTLS is issued.
6139+
// So this mostly affects newer protocols (XMPP, IMAP) as opposed to older protocols (HTTPS).
6140+
6141+
if (!r1 && !r2) // Yes, the && is correct - workaround for apple bug.
61236142
{
61246143
[self closeWithError:[self otherError:@"Error in CFStreamSetProperty"]];
61256144
return;

GCD/Xcode/EchoServer/EchoServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GCD/Xcode/IPhoneConnectTest/Classes/IPhoneConnectTestAppDelegate.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ - (void)normalConnect
2424
{
2525
DDLogError(@"Error connecting: %@", error);
2626
}
27+
28+
// You can also specify an optional connect timeout.
2729

28-
// if (![asyncSocket connectToHost:host onPort:80 viaInterface:@":12345" withTimeout:-1 error:&error])
30+
// if (![asyncSocket connectToHost:host onPort:80 withTimeout:5.0 error:&error])
2931
// {
3032
// DDLogError(@"Error connecting: %@", error);
3133
// }
@@ -75,7 +77,7 @@ - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UI
7577
{
7678
DDLogInfo(@"socket:%p didConnectToHost:%@ port:%hu", sock, host, port);
7779

78-
// DDLogInfo(@"localHost:%@ port:%hu", [sock localHost], [sock localPort]);
80+
// DDLogInfo(@"localHost :%@ port:%hu", [sock localHost], [sock localPort]);
7981

8082
if (port == 443)
8183
{

GCD/Xcode/IPhoneConnectTest/Classes/IPhoneConnectTestViewController.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
//
2-
// IPhoneConnectTestViewController.h
3-
// IPhoneConnectTest
4-
//
5-
// Created by Robbie Hanson on 11/17/10.
6-
// Copyright 2010 __MyCompanyName__. All rights reserved.
7-
//
8-
91
#import <UIKit/UIKit.h>
102

3+
114
@interface IPhoneConnectTestViewController : UIViewController {
125

136
}
Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,11 @@
1-
//
2-
// IPhoneConnectTestViewController.m
3-
// IPhoneConnectTest
4-
//
5-
// Created by Robbie Hanson on 11/17/10.
6-
// Copyright 2010 __MyCompanyName__. All rights reserved.
7-
//
8-
91
#import "IPhoneConnectTestViewController.h"
102

11-
@implementation IPhoneConnectTestViewController
12-
13-
14-
15-
/*
16-
// The designated initializer. Override to perform setup that is required before the view is loaded.
17-
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
18-
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
19-
// Custom initialization
20-
}
21-
return self;
22-
}
23-
*/
24-
25-
/*
26-
// Implement loadView to create a view hierarchy programmatically, without using a nib.
27-
- (void)loadView {
28-
}
29-
*/
30-
31-
32-
/*
33-
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
34-
- (void)viewDidLoad {
35-
[super viewDidLoad];
36-
}
37-
*/
38-
39-
40-
/*
41-
// Override to allow orientations other than the default portrait orientation.
42-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
43-
// Return YES for supported orientations
44-
return (interfaceOrientation == UIInterfaceOrientationPortrait);
45-
}
46-
*/
47-
48-
- (void)didReceiveMemoryWarning {
49-
// Releases the view if it doesn't have a superview.
50-
[super didReceiveMemoryWarning];
51-
52-
// Release any cached data, images, etc that aren't in use.
53-
}
54-
55-
- (void)viewDidUnload {
56-
// Release any retained subviews of the main view.
57-
// e.g. self.myOutlet = nil;
58-
}
593

4+
@implementation IPhoneConnectTestViewController
605

61-
- (void)dealloc {
62-
[super dealloc];
6+
- (void)dealloc
7+
{
8+
[super dealloc];
639
}
6410

6511
@end

GCD/Xcode/IPhoneConnectTest/IPhoneConnectTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)