Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_*/
cmake-build-debug/
.idea/
.idea/
.vscode/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(<target> PUBLIC internal_client_library-shared)
FIND_PACKAGE(internal-client-shared REQUIRED)
FIND_PACKAGE(fleet-protocol-interface REQUIRED)
TARGET_LINK_LIBRARIES(<target>
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.

19 changes: 14 additions & 5 deletions source/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/socket.h>
#include <iostream>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>

Expand All @@ -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);

Expand All @@ -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
}
Expand Down Expand Up @@ -87,8 +101,3 @@ void Context::saveCommand(const std::string &command) {
Context::~Context() {
close(socket_);
}