mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
stream-ssl: Avoid unnecessary memory copies on send.
ssl_send() clones the data before sending, but if SSL_write() succeeds at the first attempt, this is only a waste of CPU cycles. Trying to send the original buffer instead and only copying remaining data if it's not possible to send it all right away. This should save a few cycles on every send. Note: It's probably possible to avoid the copy even if we can't send everything at once, but will, likely, require some major change of the stream-sll module in order to take into account all the corner cases related to SSL connection. So, not trying to do that for now. Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
@@ -762,18 +762,22 @@ ssl_send(struct stream *stream, const void *buffer, size_t n)
|
||||
if (sslv->txbuf) {
|
||||
return -EAGAIN;
|
||||
} else {
|
||||
struct ofpbuf buf;
|
||||
int error;
|
||||
|
||||
sslv->txbuf = ofpbuf_clone_data(buffer, n);
|
||||
ofpbuf_use_const(&buf, buffer, n);
|
||||
sslv->txbuf = &buf;
|
||||
error = ssl_do_tx(stream);
|
||||
switch (error) {
|
||||
case 0:
|
||||
ssl_clear_txbuf(sslv);
|
||||
sslv->txbuf = NULL;
|
||||
return n;
|
||||
case EAGAIN:
|
||||
/* Copy remaining data. */
|
||||
sslv->txbuf = ofpbuf_clone_data(buf.data, buf.size);
|
||||
return n;
|
||||
default:
|
||||
ssl_clear_txbuf(sslv);
|
||||
sslv->txbuf = NULL;
|
||||
return -error;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user