- /* TODO(RECLAYER): What happens if there is already a write pending? */
- if (RECORD_LAYER_write_pending(&sc->rlayer))
- return -1;
+ if (RECORD_LAYER_write_pending(&sc->rlayer)) {
+ if (sc->s3.alert_dispatch != SSL_ALERT_DISPATCH_RETRY) {
+ /*
+ * We have a write pending but it wasn't from a previous call to
+ * this function! Can we ever get here? Maybe via API misuse??
+ * Give up.
+ */
+ sc->s3.alert_dispatch = SSL_ALERT_DISPATCH_NONE;
+ return -1;
+ }
+ /* Retry what we've already got pending */
+ i = HANDLE_RLAYER_WRITE_RETURN(sc,
+ sc->rlayer.wrlmethod->retry_write_records(sc->rlayer.wrl));
+ if (i <= 0) {
+ /* Could be NBIO. Keep alert_dispatch as SSL_ALERT_DISPATCH_RETRY */
+ return -1;
+ }
+ sc->rlayer.wpend_tot = 0;
+ sc->s3.alert_dispatch = SSL_ALERT_DISPATCH_NONE;
+ return 1;
+ }