]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Block TLS read when sending data, but have to wait for the handshake data first
authorMartin Willi <martin@revosec.ch>
Mon, 14 Jan 2013 14:32:12 +0000 (15:32 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 15 Jan 2013 16:43:05 +0000 (17:43 +0100)
src/libtls/tls_socket.c

index 131bada9641d7335a78111f7850d183087f346b3..db12d1d8b70c43aa65a318734afe8b1822145221 100644 (file)
@@ -111,7 +111,6 @@ METHOD(tls_application_t, process, status_t,
                {
                        return FAILED;
                }
-
                memcpy(this->in.ptr + this->in_done, data.ptr, data.len);
                this->in_done += data.len;
        }
@@ -145,7 +144,7 @@ static bool exchange(private_tls_socket_t *this, bool wr, bool block)
 {
        char buf[CRYPTO_BUF_SIZE], *pos;
        ssize_t len, out;
-       int round = 0;
+       int round = 0, flags;
 
        for (round = 0; TRUE; round++)
        {
@@ -191,8 +190,16 @@ static bool exchange(private_tls_socket_t *this, bool wr, bool block)
                                return TRUE;
                        }
                }
-               len = recv(this->fd, buf, sizeof(buf),
-                                  !block || this->app.in_done || round ? MSG_DONTWAIT : 0);
+
+               flags = 0;
+               if (this->app.out_done == this->app.out.len)
+               {
+                       if (!block || this->app.in_done)
+                       {
+                               flags |= MSG_DONTWAIT;
+                       }
+               }
+               len = recv(this->fd, buf, sizeof(buf), flags);
                if (len < 0)
                {
                        if (errno == EAGAIN || errno == EWOULDBLOCK)