Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a non-blocking gen_sctp:connect
This patch extends the functionality of gen_sctp:connect by providing a non-blocking connect call when Timeout = 0. Especially when using multi-homed connections, the current implementation has a race-condition that can cause the wrong sctp_association_change record to be returned to the application. With this patch, when an application calls connect with Timeout = 0 then the application is responsible for receiving the #sctp_assoc_change{} message and correctly determining the connect it originated from (for example, by examining the remote host and/or port). The application should have at least {active, once} or be prepared to gen_sctp:recv the connect result. The behaviour is unchanged if Timeout /= 0. Example application code: try_connect(A) -> cancel_timer(A), case gen_sctp:connect(A#assoc.sock, A#assoc.remote_addr_order, A#assoc.remote_port, [{active, once}], 0) of ok -> Timer = erlang:send_after(?ASSOC_RETRY_TIME,self(), ?TimerMsg(A, assoc_retry_expiry)), %% these results indicate connection in progress {connecting, A#assoc{timer = Timer}}; Err -> {Err, A} end.
- Loading branch information