diff --git a/src/tunnel.c b/src/tunnel.c index 805af6db..acf699bf 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -473,10 +473,32 @@ remote_send_cb(EV_P_ ev_io *w, int revents) // has data to send ssize_t s = -1; if (remote->addr != NULL) { + +#ifdef MSG_FASTOPEN s = sendto(remote->fd, remote->buf->data + remote->buf->idx, - remote->buf->len, MSG_FASTOPEN, remote->addr, - get_sockaddr_len(remote->addr)); + remote->buf->len, MSG_FASTOPEN, remote->addr, + get_sockaddr_len(remote->addr)); +#endif + remote->addr = NULL; + + if (s == -1) { + if (errno == CONNECT_IN_PROGRESS) { + ev_io_start(EV_A_ & remote_send_ctx->io); + ev_timer_start(EV_A_ & remote_send_ctx->watcher); + } else { + if (errno == EOPNOTSUPP || errno == EPROTONOSUPPORT || + errno == ENOPROTOOPT) { + fast_open = 0; + LOGE("fast open is not supported on this platform"); + } else { + ERROR("fast_open_connect"); + } + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + } + return; + } } else { s = send(remote->fd, remote->buf->data + remote->buf->idx, remote->buf->len, 0);