the error queue */
openssl_iostream_clear_errors();
}
- (void)openssl_iostream_more(ssl_io, OPENSSL_IOSTREAM_SYNC_TYPE_WRITE);
+ if (ssl_io->handshaked) {
+ (void)openssl_iostream_bio_sync(ssl_io,
+ OPENSSL_IOSTREAM_SYNC_TYPE_WRITE);
+ }
(void)o_stream_flush(ssl_io->plain_output);
/* close the plain i/o streams, because their fd may be closed soon,
but we may still keep this ssl-iostream referenced until later. */
return ret;
}
-int openssl_iostream_more(struct ssl_iostream *ssl_io,
- enum openssl_iostream_sync_type type)
-{
- int ret;
-
- if (!ssl_io->handshaked) {
- if ((ret = ssl_iostream_handshake(ssl_io)) <= 0)
- return ret;
- }
- if (openssl_iostream_bio_sync(ssl_io, type) < 0)
- return -1;
- return 1;
-}
-
static void openssl_iostream_closed(struct ssl_iostream *ssl_io)
{
if (ssl_io->plain_stream_errno != 0) {
occurred. */
int openssl_iostream_bio_sync(struct ssl_iostream *ssl_io,
enum openssl_iostream_sync_type type);
-/* Call when there's more data available in plain_input/plain_output.
- Returns 1 if it's ok to continue with SSL_read/SSL_write, 0 if not
- (still handshaking), -1 if error occurred. */
-int openssl_iostream_more(struct ssl_iostream *ssl_io,
- enum openssl_iostream_sync_type type);
/* Returns 1 if the operation should be retried (we read/wrote more data),
0 if the operation should retried later once more data has been
return -1;
}
- ret = openssl_iostream_more(ssl_io,
- OPENSSL_IOSTREAM_SYNC_TYPE_HANDSHAKE);
- if (ret <= 0) {
- if (ret < 0) {
- /* handshake failed */
- i_assert(errno != 0);
- io_stream_set_error(&stream->iostream,
- "%s", ssl_io->last_error);
- stream->istream.stream_errno = errno;
+ if (!ssl_io->handshaked) {
+ if ((ret = ssl_iostream_handshake(ssl_io)) <= 0) {
+ if (ret < 0) {
+ /* handshake failed */
+ i_assert(errno != 0);
+ io_stream_set_error(&stream->iostream,
+ "%s", ssl_io->last_error);
+ stream->istream.stream_errno = errno;
+ }
+ return ret;
}
- return ret;
+ }
+ if (openssl_iostream_bio_sync(ssl_io,
+ OPENSSL_IOSTREAM_SYNC_TYPE_HANDSHAKE) < 0) {
+ i_assert(ssl_io->plain_stream_errno != 0 &&
+ ssl_io->plain_stream_errstr != NULL);
+ io_stream_set_error(&stream->iostream,
+ "%s", ssl_io->plain_stream_errstr);
+ stream->istream.stream_errno = ssl_io->plain_stream_errno;
+ return -1;
}
if (!i_stream_try_alloc(stream, 1, &size))
return -2;
struct ssl_ostream *sstream = (struct ssl_ostream *)stream;
struct ssl_iostream *ssl_io = sstream->ssl_io;
struct ostream *plain_output = ssl_io->plain_output;
- int ret;
-
- if ((ret = openssl_iostream_more(ssl_io,
- OPENSSL_IOSTREAM_SYNC_TYPE_HANDSHAKE)) < 0) {
- /* handshake failed */
- io_stream_set_error(&stream->iostream, "%s",
- ssl_io->last_error);
- stream->ostream.stream_errno = errno;
- } else if (ret > 0 && sstream->buffer != NULL &&
- sstream->buffer->used > 0) {
+ int ret = 1;
+
+ if (!ssl_io->handshaked) {
+ if ((ret = ssl_iostream_handshake(ssl_io)) < 0) {
+ /* handshake failed */
+ i_assert(errno != 0);
+ io_stream_set_error(&stream->iostream,
+ "%s", ssl_io->last_error);
+ stream->ostream.stream_errno = errno;
+ return ret;
+ }
+ }
+ if (ret > 0 &&
+ openssl_iostream_bio_sync(
+ ssl_io, OPENSSL_IOSTREAM_SYNC_TYPE_HANDSHAKE) < 0) {
+ i_assert(ssl_io->plain_stream_errno != 0 &&
+ ssl_io->plain_stream_errstr != NULL);
+ io_stream_set_error(&stream->iostream,
+ "%s", ssl_io->plain_stream_errstr);
+ stream->ostream.stream_errno = ssl_io->plain_stream_errno;
+ return -1;
+ }
+
+ if (ret > 0 && sstream->buffer != NULL && sstream->buffer->used > 0) {
/* we can try to send some of our buffered data */
ret = o_stream_ssl_flush_buffer(sstream);
}