On Friday, March 26, 2010, <[email protected]> wrote:
> +
> + if (n < 0) {
> + if (errno == EINTR) {
> + n = 1;
> + continue;
Why set n=1 here? Also, if you continue here..
> + } else {
you don't need else here.
Looks good otherwise. I'm surprised by the amount of bugs found in
this method I just ripped from somewhere :)
- Pieter
> + free(buffer);
> + NSString *reason = [NSString
> stringWithFormat:@"%s:%d: read() error: %s", __PRETTY_FUNCTION__, __LINE__,
> strerror(errno)];
> + [[NSException exceptionWithName:@"Socket
> error" reason:reason userInfo:nil] raise];
> + }
> + }
> +
> + bytesReceived++;
>
> if (bytesReceived >= bufferSize) {
> // Make buffer bigger
> bufferSize += BUFFER_SIZE;
> - buffer = (char*)realloc(buffer, bufferSize + 1);
> + buffer = (char *)reallocf(buffer, bufferSize + 1);
> if (buffer == NULL)
> [[NSException exceptionWithName:@"No memory
> left" reason:@"No more memory for allocating buffer" userInfo:nil] raise];
> }
> @@ -50,13 +64,14 @@ -(NSString*)readLine {
> NSString* s = [NSString stringWithCString:
> buffer encoding: NSUTF8StringEncoding];
> if ([s length] == 0)
> s = [NSString stringWithCString:
> buffer encoding: NSISOLatin1StringEncoding];
> + free(buffer);
> return s;
> case '\r':
> bytesReceived--;
> }
> }
>
> - buffer[bytesReceived-1] = '\0';
> + buffer[bytesReceived] = '\0';
> NSString *retVal = [NSString stringWithCString: buffer encoding:
> NSUTF8StringEncoding];
> if ([retVal length] == 0)
> retVal = [NSString stringWithCString: buffer encoding:
> NSISOLatin1StringEncoding];
> --
> 1.7.0
>
> To unsubscribe from this group, send email to
> gitx+unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE ME" as the subject.
>
To unsubscribe from this group, send email to gitx+unsubscribegooglegroups.com
or reply to this email with the words "REMOVE ME" as the subject.