Skip to content

Commit 36d1a10

Browse files
committed
Moving some advanced methods to the 'pragma Advanced' section.
1 parent d378d47 commit 36d1a10

File tree

2 files changed

+78
-71
lines changed

2 files changed

+78
-71
lines changed

GCD/GCDAsyncSocket.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,39 +128,6 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
128128
- (void)setDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
129129
- (void)synchronouslySetDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
130130

131-
/**
132-
* Traditionally sockets are not closed until the conversation is over.
133-
* However, it is technically possible for the remote enpoint to close its write stream.
134-
* Our socket would then be notified that there is no more data to be read,
135-
* but our socket would still be writeable and the remote endpoint could continue to receive our data.
136-
*
137-
* The argument for this confusing functionality stems from the idea that a client could shut down its
138-
* write stream after sending a request to the server, thus notifying the server there are to be no further requests.
139-
* In practice, however, this technique did little to help server developers.
140-
*
141-
* To make matters worse, from a TCP perspective there is no way to tell the difference from a read stream close
142-
* and a full socket close. They both result in the TCP stack receiving a FIN packet. The only way to tell
143-
* is by continuing to write to the socket. If it was only a read stream close, then writes will continue to work.
144-
* Otherwise an error will be occur shortly (when the remote end sends us a RST packet).
145-
*
146-
* In addition to the technical challenges and confusion, many high level socket/stream API's provide
147-
* no support for dealing with the problem. If the read stream is closed, the API immediately declares the
148-
* socket to be closed, and shuts down the write stream as well. In fact, this is what Apple's CFStream API does.
149-
* It might sound like poor design at first, but in fact it simplifies development.
150-
*
151-
* The vast majority of the time if the read stream is closed it's because the remote endpoint closed its socket.
152-
* Thus it actually makes sense to close the socket at this point.
153-
* And in fact this is what most networking developers want and expect to happen.
154-
* However, if you are writing a server that interacts with a plethora of clients,
155-
* you might encounter a client that uses the discouraged technique of shutting down its write stream.
156-
* If this is the case, you can set this property to NO,
157-
* and make use of the socketDidCloseReadStream delegate method.
158-
*
159-
* The default value is YES.
160-
**/
161-
- (BOOL)autoDisconnectOnClosedReadStream;
162-
- (void)setAutoDisconnectOnClosedReadStream:(BOOL)flag;
163-
164131
/**
165132
* By default, both IPv4 and IPv6 are enabled.
166133
*
@@ -744,6 +711,39 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
744711

745712
#pragma mark Advanced
746713

714+
/**
715+
* Traditionally sockets are not closed until the conversation is over.
716+
* However, it is technically possible for the remote enpoint to close its write stream.
717+
* Our socket would then be notified that there is no more data to be read,
718+
* but our socket would still be writeable and the remote endpoint could continue to receive our data.
719+
*
720+
* The argument for this confusing functionality stems from the idea that a client could shut down its
721+
* write stream after sending a request to the server, thus notifying the server there are to be no further requests.
722+
* In practice, however, this technique did little to help server developers.
723+
*
724+
* To make matters worse, from a TCP perspective there is no way to tell the difference from a read stream close
725+
* and a full socket close. They both result in the TCP stack receiving a FIN packet. The only way to tell
726+
* is by continuing to write to the socket. If it was only a read stream close, then writes will continue to work.
727+
* Otherwise an error will be occur shortly (when the remote end sends us a RST packet).
728+
*
729+
* In addition to the technical challenges and confusion, many high level socket/stream API's provide
730+
* no support for dealing with the problem. If the read stream is closed, the API immediately declares the
731+
* socket to be closed, and shuts down the write stream as well. In fact, this is what Apple's CFStream API does.
732+
* It might sound like poor design at first, but in fact it simplifies development.
733+
*
734+
* The vast majority of the time if the read stream is closed it's because the remote endpoint closed its socket.
735+
* Thus it actually makes sense to close the socket at this point.
736+
* And in fact this is what most networking developers want and expect to happen.
737+
* However, if you are writing a server that interacts with a plethora of clients,
738+
* you might encounter a client that uses the discouraged technique of shutting down its write stream.
739+
* If this is the case, you can set this property to NO,
740+
* and make use of the socketDidCloseReadStream delegate method.
741+
*
742+
* The default value is YES.
743+
**/
744+
- (BOOL)autoDisconnectOnClosedReadStream;
745+
- (void)setAutoDisconnectOnClosedReadStream:(BOOL)flag;
746+
747747
/**
748748
* It's not thread-safe to access certain variables from outside the socket's internal queue.
749749
*

GCD/GCDAsyncSocket.m

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,44 +1275,6 @@ - (void)synchronouslySetDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t
12751275
[self setDelegate:newDelegate delegateQueue:newDelegateQueue synchronously:YES];
12761276
}
12771277

1278-
- (BOOL)autoDisconnectOnClosedReadStream
1279-
{
1280-
// Note: YES means kAllowHalfDuplexConnection is OFF
1281-
1282-
if (dispatch_get_current_queue() == socketQueue)
1283-
{
1284-
return ((config & kAllowHalfDuplexConnection) == 0);
1285-
}
1286-
else
1287-
{
1288-
__block BOOL result;
1289-
1290-
dispatch_sync(socketQueue, ^{
1291-
result = ((config & kAllowHalfDuplexConnection) == 0);
1292-
});
1293-
1294-
return result;
1295-
}
1296-
}
1297-
1298-
- (void)setAutoDisconnectOnClosedReadStream:(BOOL)flag
1299-
{
1300-
// Note: YES means kAllowHalfDuplexConnection is OFF
1301-
1302-
dispatch_block_t block = ^{
1303-
1304-
if (flag)
1305-
config &= ~kAllowHalfDuplexConnection;
1306-
else
1307-
config |= kAllowHalfDuplexConnection;
1308-
};
1309-
1310-
if (dispatch_get_current_queue() == socketQueue)
1311-
block();
1312-
else
1313-
dispatch_async(socketQueue, block);
1314-
}
1315-
13161278
- (BOOL)isIPv4Enabled
13171279
{
13181280
// Note: YES means kIPv4Disabled is OFF
@@ -7092,6 +7054,51 @@ - (BOOL)openStreams
70927054
#pragma mark Advanced
70937055
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
70947056

7057+
/**
7058+
* See header file for big discussion of this method.
7059+
**/
7060+
- (BOOL)autoDisconnectOnClosedReadStream
7061+
{
7062+
// Note: YES means kAllowHalfDuplexConnection is OFF
7063+
7064+
if (dispatch_get_current_queue() == socketQueue)
7065+
{
7066+
return ((config & kAllowHalfDuplexConnection) == 0);
7067+
}
7068+
else
7069+
{
7070+
__block BOOL result;
7071+
7072+
dispatch_sync(socketQueue, ^{
7073+
result = ((config & kAllowHalfDuplexConnection) == 0);
7074+
});
7075+
7076+
return result;
7077+
}
7078+
}
7079+
7080+
/**
7081+
* See header file for big discussion of this method.
7082+
**/
7083+
- (void)setAutoDisconnectOnClosedReadStream:(BOOL)flag
7084+
{
7085+
// Note: YES means kAllowHalfDuplexConnection is OFF
7086+
7087+
dispatch_block_t block = ^{
7088+
7089+
if (flag)
7090+
config &= ~kAllowHalfDuplexConnection;
7091+
else
7092+
config |= kAllowHalfDuplexConnection;
7093+
};
7094+
7095+
if (dispatch_get_current_queue() == socketQueue)
7096+
block();
7097+
else
7098+
dispatch_async(socketQueue, block);
7099+
}
7100+
7101+
70957102
/**
70967103
* See header file for big discussion of this method.
70977104
**/

0 commit comments

Comments
 (0)