diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-01-10 15:43:00 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-01-10 15:43:00 +0100 |
commit | 953ff6dd861964db80a1142cdcccc7a9ec1d8efd (patch) | |
tree | 0bf16f3797ccc6e6c81b3c21bef22c39a61e2ef9 /src/inspsocket.cpp | |
parent | 38bc192dd6d289b8632349c67ef2cafdca3b4159 (diff) |
Store iovec array on the stack instead of heap allocating it for the lifetime of writev() in StreamSocket::DoWrite()
Diffstat (limited to 'src/inspsocket.cpp')
-rw-r--r-- | src/inspsocket.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 645947f56..ee5287e5f 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -339,15 +339,17 @@ void StreamSocket::DoWrite() } int rv_max = 0; - iovec* iovecs = new iovec[bufcount]; - for(int i=0; i < bufcount; i++) + int rv; { - iovecs[i].iov_base = const_cast<char*>(sendq[i].data()); - iovecs[i].iov_len = sendq[i].length(); - rv_max += sendq[i].length(); + iovec iovecs[MYIOV_MAX]; + for (int i = 0; i < bufcount; i++) + { + iovecs[i].iov_base = const_cast<char*>(sendq[i].data()); + iovecs[i].iov_len = sendq[i].length(); + rv_max += sendq[i].length(); + } + rv = writev(fd, iovecs, bufcount); } - int rv = writev(fd, iovecs, bufcount); - delete[] iovecs; if (rv == (int)sendq_len) { |