diff --git a/.gitignore b/.gitignore index 4d68e6c..b68985f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ _*/ cmake-build-debug/ -.idea/ \ No newline at end of file +.idea/ +.vscode/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c64d498..e9c32b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ SET(CMAKE_CXX_STANDARD 20) SET(CMAKE_CXX_EXTENSIONS OFF) # For increased portability SET(CMAKE_POSITION_INDEPENDENT_CODE ON) -SET(INTERNAL_CLIENT_VERSION 1.1.2) +SET(INTERNAL_CLIENT_VERSION 1.1.3) OPTION(BRINGAUTO_SAMPLES OFF) OPTION(BRINGAUTO_TESTS "Enable tests" OFF) diff --git a/README.md b/README.md index f295b17..7cfc471 100644 --- a/README.md +++ b/README.md @@ -80,11 +80,15 @@ $ cpack ``` ## Include library -After the library is installed, it can be included to a project by using the following lines in CMakeLists.txt +After the library is installed, it can be included in a project by using the following lines in CMakeLists.txt. ([Fleet protocol](https://github.com/bringauto/fleet-protocol) headers are also required) ```cmake -FIND_PACKAGE(internal-client REQUIRED) -TARGET_LINK_LIBRARIES( PUBLIC internal_client_library-shared) +FIND_PACKAGE(internal-client-shared REQUIRED) +FIND_PACKAGE(fleet-protocol-interface REQUIRED) +TARGET_LINK_LIBRARIES( + PUBLIC + internal-client-shared::internal-client-shared + fleet-protocol-interface::internal-client-interface) ``` -And then including header file `internal_client.h` to the source code. +And then include the header file `internal_client.h` to the source code. diff --git a/source/Context.cpp b/source/Context.cpp index fad8196..9ab891a 100644 --- a/source/Context.cpp +++ b/source/Context.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,12 @@ int Context::createConnection(const char *ipv4_address, unsigned int port) { return NOT_OK; // Socket creation error } + int flag = 1; + // Set TCP_NODELAY to disable Nagle's algorithm + if (setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, (char8_t *)&flag, sizeof(int)) < 0) { + return NOT_OK; // Failed to set TCP_NODELAY + } + serverAddress_.sin_family = AF_INET; serverAddress_.sin_port = htons(port); @@ -34,6 +41,13 @@ int Context::reconnect() { if ((socket_ = socket(AF_INET, SOCK_STREAM, 0)) < 0) { return NOT_OK; // Socket creation error } + + int flag = 1; + // Set TCP_NODELAY to disable Nagle's algorithm + if (setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, (char8_t *)&flag, sizeof(int)) < 0) { + return NOT_OK; // Failed to set TCP_NODELAY + } + if (connect(socket_, (struct sockaddr*)&serverAddress_, sizeof(serverAddress_)) < 0) { return NOT_OK; // Connection error } @@ -87,8 +101,3 @@ void Context::saveCommand(const std::string &command) { Context::~Context() { close(socket_); } - - - - -