From 5b4354a6f3ee1ded3dfba98d0204c55d60881967 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 14 Mar 2019 13:47:03 -0700 Subject: [PATCH] send optimization + ws file transfer test --- Dockerfile | 32 +++++++++++++++++++++++++++- docker/Dockerfile.debian | 30 -------------------------- ixwebsocket/IXWebSocketTransport.cpp | 6 +++++- makefile | 3 +++ ws/ws.cpp | 16 ++++++++++++++ ws/ws_receive.cpp | 9 ++++++-- 6 files changed, 62 insertions(+), 34 deletions(-) mode change 120000 => 100644 Dockerfile delete mode 100644 docker/Dockerfile.debian diff --git a/Dockerfile b/Dockerfile deleted file mode 120000 index e4ce2a81..00000000 --- a/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -docker/Dockerfile.debian \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..05937cd1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM debian:stretch + +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get update +RUN apt-get -y install g++ +RUN apt-get -y install libssl-dev +RUN apt-get -y install gdb +RUN apt-get -y install screen +RUN apt-get -y install procps +RUN apt-get -y install lsof +RUN apt-get -y install libz-dev +RUN apt-get -y install vim +RUN apt-get -y install make +RUN apt-get -y install cmake +RUN apt-get -y install curl +RUN apt-get -y install python +RUN apt-get -y install netcat + +# debian strech cmake is too old for building with Docker +COPY makefile . +RUN ["make", "install_cmake_for_linux"] + +COPY . . + +ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-rc4-Linux-x86_64/bin +ENV PATH="${CMAKE_BIN_PATH}:${PATH}" + +# RUN ["make"] + +EXPOSE 8765 +CMD ["/ws/ws", "transfer", "--port", "8765", "--host", "0.0.0.0"] diff --git a/docker/Dockerfile.debian b/docker/Dockerfile.debian deleted file mode 100644 index 56d2b75c..00000000 --- a/docker/Dockerfile.debian +++ /dev/null @@ -1,30 +0,0 @@ -FROM debian:stretch - -ENV DEBIAN_FRONTEND noninteractive -RUN apt-get update -RUN apt-get -y install g++ -RUN apt-get -y install libssl-dev -RUN apt-get -y install gdb -RUN apt-get -y install screen -RUN apt-get -y install procps -RUN apt-get -y install lsof -RUN apt-get -y install libz-dev -RUN apt-get -y install vim -RUN apt-get -y install make -RUN apt-get -y install cmake -RUN apt-get -y install curl -RUN apt-get -y install python - -# debian strech cmake is too old for building with Docker -COPY makefile . -RUN ["make", "install_cmake_for_linux"] - -COPY . . - -ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-rc4-Linux-x86_64/bin -ENV PATH="${CMAKE_BIN_PATH}:${PATH}" - -# RUN ["make"] - -EXPOSE 8765 -CMD ["/ws/ws", "transfer", "--port", "8765", "--host", "0.0.0.0"] diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 0029e803..adb0531c 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -605,7 +605,11 @@ namespace ix } } - _socket->wakeUpFromPoll(Socket::kSendRequest); + // Request to flush the send buffer on the background thread if it isn't empty + if (!isSendBufferEmpty()) + { + _socket->wakeUpFromPoll(Socket::kSendRequest); + } return WebSocketSendInfo(true, compressionError, payloadSize, wireSize); } diff --git a/makefile b/makefile index 094dc145..1853a600 100644 --- a/makefile +++ b/makefile @@ -36,6 +36,9 @@ test_server: test: python test/run.py +ws_test: + (cd ws ; sh test_ws.sh) + # For the fork that is configured with appveyor rebase_upstream: git fetch upstream diff --git a/ws/ws.cpp b/ws/ws.cpp index 4f90b8e9..dfaa6fc9 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include @@ -32,6 +34,7 @@ int main(int argc, char** argv) std::string headers; std::string output; std::string hostname("127.0.0.1"); + std::string pidfile; bool headersOnly = false; bool followRedirects = false; bool verbose = false; @@ -52,6 +55,7 @@ int main(int argc, char** argv) CLI::App* transferApp = app.add_subcommand("transfer", "Broadcasting server"); transferApp->add_option("--port", port, "Connection url"); transferApp->add_option("--host", hostname, "Hostname"); + transferApp->add_option("--pidfile", pidfile, "Pid file"); CLI::App* connectApp = app.add_subcommand("connect", "Connect to a remote server"); connectApp->add_option("url", url, "Connection url")->required(); @@ -90,8 +94,20 @@ int main(int argc, char** argv) ix::Socket::init(); + // pid file handling + if (app.got_subcommand("transfer")) { + if (!pidfile.empty()) + { + unlink(pidfile.c_str()); + + std::ofstream f; + f.open(pidfile); + f << getpid(); + f.close(); + } + return ix::ws_transfer_main(port, hostname); } else if (app.got_subcommand("send")) diff --git a/ws/ws_receive.cpp b/ws/ws_receive.cpp index ee2941e3..0bfaf1c3 100644 --- a/ws/ws_receive.cpp +++ b/ws/ws_receive.cpp @@ -146,11 +146,16 @@ namespace ix std::string filename = data["filename"].string_value(); filename = extractFilename(filename); - std::cout << "Writing to disk: " << filename << std::endl; - std::ofstream out(filename); + std::string filenameTmp = filename + ".tmp"; + + std::cout << "Writing to disk: " << filenameTmp << std::endl; + std::ofstream out(filenameTmp); out.write((char*)&content.front(), content.size()); out.close(); + std::cout << "Renaming " << filenameTmp << " to " << filename << std::endl; + rename(filenameTmp.c_str(), filename.c_str()); + std::map pdu; pdu["ack"] = true; pdu["id"] = data["id"];