Differences From Artifact [31817d3b24]:
- File
utils/ofhttp/OFHTTP.m
— part of check-in
[d16ad96cbd]
at
2018-12-07 01:33:47
on branch trunk
— OFStream: Use a delegate for async operations
The target / selector approach had several drawbacks:
* It was inconvenient to use, as for every read or write, a target,
selector and context would need to be specified.
* It lacked any kind of type-safety and would not even warn about using
a callback method with the wrong number of parameters.
* It encouraged using a different callback method for each read or
write call, which results in code that is hard to follow and also
slower (as it needs to recreate the async operation with a new
callback every time). (user: js, size: 26966) [annotate] [blame] [check-ins using]
To Artifact [c4c7ef8326]:
- File
utils/ofhttp/OFHTTP.m
— part of check-in
[064dbe5127]
at
2018-12-11 22:57:46
on branch trunk
— Include an exception in delegate methods
Otherwise, there would be two methods for every operation: One for
success and one for failure. It also makes it easy to forget about
handling failure, so it's better to always pass an optional exception. (user: js, size: 26963) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } - (bool)stream: (OF_KINDOF(OFStream *))response didReadIntoBuffer: (void *)buffer length: (size_t)length { _received += length; [_output writeBuffer: buffer length: length]; [_progressBar setReceived: _received]; | > > > > > > > > > > > > > > > > > > > > > > > > > > | 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 | [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } - (bool)stream: (OF_KINDOF(OFStream *))response didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { if (exception != nil) { OFString *URL; [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) [of_stdout writeString: @"\n Error!\n"]; URL = [_URLs objectAtIndex: _URLIndex - 1]; [of_stderr writeLine: OF_LOCALIZED( @"download_failed_exception", @"%[prog]: Failed to download <%[url]>: %[exception]", @"prog", [OFApplication programName], @"url", URL, @"exception", exception)]; _errorCode = 1; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; return false; } _received += length; [_output writeBuffer: buffer length: length]; [_progressBar setReceived: _received]; |
︙ | ︙ | |||
681 682 683 684 685 686 687 | afterDelay: 0]; return false; } return true; } | < < < < < < < < < < < < < < < < < < < < < < < < < < | 707 708 709 710 711 712 713 714 715 716 717 718 719 720 | afterDelay: 0]; return false; } return true; } - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers statusCode: (int)statusCode request: (OFHTTPRequest *)request context: (id)context { if (!_quiet) { |
︙ | ︙ |