Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Grechuhin <i.grechuhin@gmail.com>2016-10-12 17:44:29 +0300
committerIlya Grechuhin <i.grechuhin@gmail.com>2016-10-12 17:44:29 +0300
commitef436ecaaec064848ec48da25de4d64e3f1dee6e (patch)
tree12819913efa5f837e3bb2db9ace3235d583fdaa6 /platform
parent262a0bb70c677b0675276e4a891fd35c4e15005b (diff)
Review fixes.
Diffstat (limited to 'platform')
-rw-r--r--platform/socket_apple.mm84
1 files changed, 52 insertions, 32 deletions
diff --git a/platform/socket_apple.mm b/platform/socket_apple.mm
index f9f2565d92..670f8a4692 100644
--- a/platform/socket_apple.mm
+++ b/platform/socket_apple.mm
@@ -50,7 +50,7 @@
NSStreamStatus const outputStreamStatus = self.outputStream.streamStatus;
if (inputStreamStatus == NSStreamStatusError || outputStreamStatus == NSStreamStatusError)
return NO;
- else if (inputStreamStatus == NSStreamStatusOpen && outputStreamStatus == NSStreamStatusOpen)
+ if (inputStreamStatus == NSStreamStatusOpen && outputStreamStatus == NSStreamStatusOpen)
return YES;
}
@@ -77,27 +77,35 @@
if (!self.inputStream || self.inputStream.streamStatus != NSStreamStatusOpen)
return NO;
- NSInteger const readCount = [self.inputStream read:data maxLength:count];
-
- if (readCount > 0)
- {
- LOG(LDEBUG, ("Stream has read ", readCount, " bytes."));
- }
- else if (readCount == 0)
+ NSDate * readStart = [NSDate date];
+ uint8_t * readPtr = data;
+ while (count != 0 && [[NSDate date] timeIntervalSinceDate:readStart] < self.timeout)
{
- LOG(LDEBUG, ("The end of the read buffer was reached."));
- }
- else
- {
- LOG(LERROR, ("An error has occurred on the read stream."));
+ NSInteger const readCount = [self.inputStream read:readPtr maxLength:count];
+
+ if (readCount > 0)
+ {
+ LOG(LDEBUG, ("Stream has read ", readCount, " bytes."));
+ count -= readCount;
+ readPtr += readCount;
+ }
+ else if (readCount == 0)
+ {
+ LOG(LDEBUG, ("The end of the read buffer was reached."));
+ }
+ else
+ {
+ LOG(LERROR, ("An error has occurred on the read stream."));
#ifdef OMIN_PRODUCTION
- LOG(LERROR, (self.inputStream.streamError));
+ LOG(LERROR, (self.inputStream.streamError));
#else
- NSLog(@"%@", self.inputStream.streamError);
+ NSLog(@"%@", self.inputStream.streamError);
#endif
+ return NO;
+ }
}
- return readCount == count;
+ return count == 0;
}
- (BOOL)write:(uint8_t const *)data count:(NSUInteger)count
@@ -105,27 +113,35 @@
if (!self.outputStream || self.outputStream.streamStatus != NSStreamStatusOpen)
return NO;
- NSInteger const writeCount = [self.outputStream write:data maxLength:count];
-
- if (writeCount > 0)
+ NSDate * writeStart = [NSDate date];
+ uint8_t const * writePtr = data;
+ while (count != 0 && [[NSDate date] timeIntervalSinceDate:writeStart] < self.timeout)
{
- LOG(LDEBUG, ("Stream has written ", writeCount, " bytes."));
- }
- else if (writeCount == 0)
- {
- LOG(LDEBUG, ("The end of the write stream has been reached."));
- }
- else
- {
- LOG(LERROR, ("An error has occurred on the write stream."));
+ NSInteger const writeCount = [self.outputStream write:writePtr maxLength:count];
+
+ if (writeCount > 0)
+ {
+ LOG(LDEBUG, ("Stream has written ", writeCount, " bytes."));
+ count -= writeCount;
+ writePtr += writeCount;
+ }
+ else if (writeCount == 0)
+ {
+ LOG(LDEBUG, ("The end of the write stream has been reached."));
+ }
+ else
+ {
+ LOG(LERROR, ("An error has occurred on the write stream."));
#ifdef OMIN_PRODUCTION
- LOG(LERROR, (self.outputStream.streamError));
+ LOG(LERROR, (self.outputStream.streamError));
#else
- NSLog(@"%@", self.outputStream.streamError);
+ NSLog(@"%@", self.outputStream.streamError);
#endif
+ return NO;
+ }
}
- return writeCount == count;
+ return count == 0;
}
@end
@@ -155,7 +171,11 @@ unique_ptr<Socket> createSocket()
PlatformSocket::PlatformSocket() { m_socketImpl = [[SocketImpl alloc] init]; }
-PlatformSocket::~PlatformSocket() { Close(); }
+PlatformSocket::~PlatformSocket()
+{
+ Close();
+ m_socketImpl = nullptr;
+}
bool PlatformSocket::Open(string const & host, uint16_t port)
{