diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-03-09 16:11:08 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-03-09 16:11:08 +0100 |
commit | 1c9f43b247b446a95613adf2eb0a81ded44cfa88 (patch) | |
tree | 6e9cb3de3e108a2eb83183d9c5d0abd8b5929983 /src/dabOutput | |
parent | 44732939bca8ba767d6ce5ea45085cf421d76595 (diff) | |
download | dabmux-1c9f43b247b446a95613adf2eb0a81ded44cfa88.tar.gz dabmux-1c9f43b247b446a95613adf2eb0a81ded44cfa88.tar.bz2 dabmux-1c9f43b247b446a95613adf2eb0a81ded44cfa88.zip |
Avoid doing useless copies in RAW output
Diffstat (limited to 'src/dabOutput')
-rw-r--r-- | src/dabOutput/dabOutputRaw.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/dabOutput/dabOutputRaw.cpp b/src/dabOutput/dabOutputRaw.cpp index edc3cc6..201a7a6 100644 --- a/src/dabOutput/dabOutputRaw.cpp +++ b/src/dabOutput/dabOutputRaw.cpp @@ -46,7 +46,7 @@ # include <linux/if_packet.h> # include <linux/netdevice.h> # include <net/if_arp.h> -# include <farsync.h> +# include "farsync.h" #endif const unsigned char revTable[] = { @@ -388,15 +388,17 @@ int DabOutputRaw::Write(void* buffer, int size) if ((size_t)size > buffer_.size()) { throw std::logic_error("DabOutputRaw::Write size exceeded"); } - memcpy(buffer_.data(), buffer, size); - memset(buffer_.data() + size, 0x55, 6144 - size); - // Encoding data - for (int i = 0; i < 6144; ++i) { - buffer_[i] = revTable[buffer_[i]]; + // Encode data, extend our frame with 0x55 padding + int i = 0; + for (; i < size; i++) { + buffer_[i] = revTable[reinterpret_cast<uint8_t*>(buffer)[i]]; + } + for (; i < 6144; i++) { + buffer_[i] = revTable[0x55]; } - // Writing data + // Write data #ifdef _WIN32 DWORD result; if(!DeviceIoControl(socket_, IoctlCodeTxFrame, buffer_.data(), 6144, @@ -404,20 +406,16 @@ int DabOutputRaw::Write(void* buffer, int size) goto RAW_WRITE_ERROR; } #else - /* - if (write(socket_, buffer_.data()+ 1, 6143) != 6143) { - goto RAW_WRITE_ERROR; - } - */ if (isCyclades_) { if (write(socket_, buffer_.data() + 1, 6143) != 6143) { goto RAW_WRITE_ERROR; } - } else { + } + else { int ret = send(socket_, buffer_.data(), 6144, 0); if (ret != 6144) { - etiLog.log(info, "%i/6144 bytes written", ret); - goto RAW_WRITE_ERROR; + etiLog.log(error, "%i/6144 bytes written", ret); + return -1; } } #endif @@ -442,7 +440,8 @@ RAW_WRITE_ERROR: LocalFree(errMsg); } #else - perror("Error while writing to raw socket"); + etiLog.level(error) << "Error while writing to raw socket: " << + strerror(errno); #endif return -1; |