Skip to content

Commit

Permalink
Apple SSL (re #2482): Fixed possible incorrect scheduling of next rec…
Browse files Browse the repository at this point in the history
…eive if dispatch_data_apply() is called multiple times
  • Loading branch information
sauwming committed Mar 10, 2021
1 parent dd2827f commit 2d6dd96
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pjlib/src/pj/ssl_sock_apple.m
Expand Up @@ -763,12 +763,13 @@ static pj_status_t network_start_read(pj_ssl_sock_t *ssock,
};

if (content) {
schedule_next_receive = Block_copy(schedule_next_receive);

dispatch_data_apply(content,
^(dispatch_data_t region, size_t offset,
const void *buffer, size_t inSize)
{
/* This block can be invoked multiple times,
* each for every contiguous memory region in the content.
*/
event_t event;

memcpy(ssock->asock_rbuf[i], buffer, inSize);
Expand All @@ -781,11 +782,11 @@ static pj_status_t network_start_read(pj_ssl_sock_t *ssock,

event_manager_post_event(ssock, &event, PJ_FALSE);

schedule_next_receive();
Block_release(schedule_next_receive);

return (bool)true;
});

schedule_next_receive();

} else {
if (status != PJ_SUCCESS) {
event_t event;
Expand Down

0 comments on commit 2d6dd96

Please sign in to comment.