Skip to content

Commit

Permalink
Manually respond to remote side of socket closing read stream
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Aug 19, 2016
1 parent 94a7aee commit 02b13f6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions Classes/Headers/IRCConnection.h
Expand Up @@ -65,6 +65,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)ircConnectionDidConnect:(IRCConnection *)sender;
- (void)ircConnection:(IRCConnection *)sender willConnectToProxy:(NSString *)proxyHost port:(uint16_t)proxyPort;
- (void)ircConnection:(IRCConnection *)sender didDisconnectWithError:(nullable NSError *)disconnectError;
- (void)ircConnectionDidCloseReadStream:(IRCConnection *)sender;
- (void)ircConnection:(IRCConnection *)sender didError:(NSString *)error;
- (void)ircConnection:(IRCConnection *)sender didReceiveData:(NSString *)data;
- (void)ircConnection:(IRCConnection *)sender willSendData:(NSString *)data;
Expand Down
1 change: 1 addition & 0 deletions Classes/Headers/Private/IRCConnectionPrivate.h
Expand Up @@ -45,6 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tpcClientWillConnectToProxy:(NSString *)proxyHost port:(uint16_t)proxyPort;
- (void)tcpClientDidError:(NSString *)error;
- (void)tcpClientDidDisconnect:(nullable NSError *)disconnectError;
- (void)tcpClientDidCloseReadStream;
- (void)tcpClientDidReceiveData:(NSString *)data;
- (void)tcpClientDidSecureConnection;
- (void)tcpClientDidReceivedAnInsecureCertificate;
Expand Down
13 changes: 13 additions & 0 deletions Classes/IRC/IRCClient.m
Expand Up @@ -4558,6 +4558,19 @@ - (void)ircConnection:(IRCConnection *)sender didError:(NSString *)error
[self printError:error asCommand:TVCLogLineDefaultCommandValue];
}

- (void)ircConnectionDidCloseReadStream:(IRCConnection *)sender
{
NSParameterAssert(sender == self.socket);

if (self.isTerminating) {
return;
}

[self printDebugInformationToConsole:TXTLS(@"IRC[1120]")];

[self disconnect];
}

- (void)ircConnection:(IRCConnection *)sender didReceiveData:(NSString *)data
{
NSParameterAssert(sender == self.socket);
Expand Down
5 changes: 5 additions & 0 deletions Classes/IRC/IRCConnection.m
Expand Up @@ -268,6 +268,11 @@ - (void)tcpClientDidDisconnect:(nullable NSError *)disconnectError
[self.client ircConnection:self didDisconnectWithError:disconnectError];
}

- (void)tcpClientDidCloseReadStream
{
[self.client ircConnectionDidCloseReadStream:self];
}

- (void)tcpClientDidReceiveData:(NSString *)data
{
[self.client ircConnection:self didReceiveData:data];
Expand Down
7 changes: 7 additions & 0 deletions Classes/IRC/IRCConnectionSocket.m
Expand Up @@ -112,6 +112,8 @@ - (void)openSocket
delegateQueue:self.dispatchQueue
socketQueue:self.socketQueue];

self.socketConnection.autoDisconnectOnClosedReadStream = NO;

self.socketConnection.IPv4PreferredOverIPv6 = self.config.connectionPrefersIPv4;

/* Attempt to connect using a configured proxy */
Expand Down Expand Up @@ -358,6 +360,11 @@ - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(ui
[self onSocketConnectedToHost];
}

- (void)socketDidCloseReadStream:(GCDAsyncSocket *)sock
{
[self tcpClientDidCloseReadStream];
}

- (void)_socketDidDisconnect:(GCDAsyncSocket *)sock withError:(nullable NSError *)error
{
[self closeSocket];
Expand Down
3 changes: 2 additions & 1 deletion Resources/Language Files/English.lproj/IRC.strings
Expand Up @@ -35,7 +35,7 @@

*********************************************************************** */

/* Next unusued key: 1120 */
/* Next unusued key: 1121 */

/* Script errors */
"IRC[1001]" = "Error: The command %@ is defined by a plugin and a script. Sending to server because of inability to determine priority.";
Expand Down Expand Up @@ -169,6 +169,7 @@
"IRC[1088]" = "You cannot send private messages to %@. Anything that you send to them will be ignored until you are added to their list of recognized users.";
"IRC[1089]" = "%1$@ (%2$@) tried to send you a private message, but it was ignored due to \002umode +g\002. Perform “/accept %1$@” to allow this user to communicate with you.";
"IRC[1114]" = "Reconnecting to proxy to rebuild internal state…"; // irssi proxy
"IRC[1120]" = "Server closed read stream";

/* /timer/ command */
"IRC[1090]" = "Timer command requires a whole number for interval. Syntax: “/timer <seconds> <command>”";
Expand Down

0 comments on commit 02b13f6

Please sign in to comment.