Skip to content

Commit

Permalink
Revert "Use original tcp_info struct"
Browse files Browse the repository at this point in the history
This reverts commit af5ad73.
  • Loading branch information
ruti committed Jul 25, 2024
1 parent 3911a9e commit e96aeff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 9 additions & 10 deletions desync.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>

#ifdef __linux__
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <fcntl.h>
#include <linux/tcp.h>

#include <desync.h>

#ifdef MFD_CLOEXEC
#include <sys/syscall.h>
#define memfd_create(name, flags) syscall(__NR_memfd_create, name, flags);
#else
#define memfd_create(name, flags) fileno(tmpfile())
#endif
#else
#include <netinet/tcp.h>
#endif
#else
#include <winsock2.h>
Expand Down Expand Up @@ -86,25 +86,24 @@ static inline void delay(long ms)
void wait_send(int sfd)
{
for (int i = 0; params.wait_send && i < 500; i++) {
struct tcp_info tcpi = {};
struct tcpi tcpi = {};
socklen_t ts = sizeof(tcpi);

if (getsockopt(sfd, IPPROTO_TCP,
TCP_INFO, (char *)&tcpi, &ts) < 0) {
perror("getsockopt TCP_INFO");
uniperror("getsockopt TCP_INFO");
break;
}
if (tcpi.tcpi_state != 1) {
LOG(LOG_E, "state: %d\n", tcpi.tcpi_state);
if (tcpi.state != 1) {
LOG(LOG_E, "state: %d\n", tcpi.state);
return;
}
size_t s = (char *)&tcpi.tcpi_notsent_bytes - (char *)&tcpi.tcpi_state;
if (ts < s) {
if (ts < sizeof(tcpi)) {
LOG(LOG_E, "tcpi_notsent_bytes not provided\n");
params.wait_send = 0;
break;
}
if (tcpi.tcpi_notsent_bytes == 0) {
if (tcpi.notsent_bytes == 0) {
return;
}
LOG(LOG_S, "not sent after %d ms\n", i);
Expand Down
9 changes: 9 additions & 0 deletions desync.h
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
ssize_t desync(int sfd, char *buffer, size_t bfsize, ssize_t n, ssize_t offset, struct sockaddr *dst, int dp_c);

struct tcpi {
uint8_t state;
uint8_t r[3];
uint32_t rr[5];
uint32_t unacked;
uint32_t rrr[29];
uint32_t notsent_bytes;
};

0 comments on commit e96aeff

Please sign in to comment.