Skip to content

Commit

Permalink
NBD client: nodelay
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed May 1, 2024
1 parent 4becb93 commit 95db008
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
#include <Arduino.h>
#include "rp2040.h"
#else
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <sys/socket.h>

#include <errno.h>
#include <pthread.h>
Expand All @@ -23,6 +27,8 @@
#include "win32.h"
#endif

#include "log.h"


void setBit(uint16_t & v, const int bit, const bool vb)
{
Expand Down Expand Up @@ -236,3 +242,14 @@ void update_word(uint16_t *const w, const bool msb, const uint8_t v)
(*w) |= v;
}
}

void set_nodelay(const int fd)
{
int flags = 1;
#if defined(__FreeBSD__) || defined(ESP32)
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) == -1)
#else
if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) == -1)
#endif
DOLOG(warning, true, "Cannot disable nagle algorithm");
}
2 changes: 2 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ ssize_t WRITE(int fd, const char *whereto, size_t len);
ssize_t READ(int fd, char *whereto, size_t len);

void update_word(uint16_t *const w, const bool msb, const uint8_t v);

void set_nodelay(const int fd);

0 comments on commit 95db008

Please sign in to comment.