summaryrefslogtreecommitdiffstats
path: root/meta-rcar-gen3-adas/recipes-support/netevent/netevent/0004-Add-TCP-keep-alive-to-handle-peer-death-properly.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-rcar-gen3-adas/recipes-support/netevent/netevent/0004-Add-TCP-keep-alive-to-handle-peer-death-properly.patch')
-rw-r--r--meta-rcar-gen3-adas/recipes-support/netevent/netevent/0004-Add-TCP-keep-alive-to-handle-peer-death-properly.patch162
1 files changed, 162 insertions, 0 deletions
diff --git a/meta-rcar-gen3-adas/recipes-support/netevent/netevent/0004-Add-TCP-keep-alive-to-handle-peer-death-properly.patch b/meta-rcar-gen3-adas/recipes-support/netevent/netevent/0004-Add-TCP-keep-alive-to-handle-peer-death-properly.patch
new file mode 100644
index 0000000..f84f113
--- /dev/null
+++ b/meta-rcar-gen3-adas/recipes-support/netevent/netevent/0004-Add-TCP-keep-alive-to-handle-peer-death-properly.patch
@@ -0,0 +1,162 @@
+From 0d797dca82a714688657523a89a14c37ae7767cf Mon Sep 17 00:00:00 2001
+From: Grigory Kletsko <grigory.kletsko@cogentembedded.com>
+Date: Wed, 5 Oct 2016 22:15:25 +0300
+Subject: [PATCH] Add TCP keep alive to handle peer death properly
+
+---
+ reader.cpp | 32 +++++++++++++++++++++++++++++++-
+ write.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++--
+ 2 files changed, 75 insertions(+), 3 deletions(-)
+
+diff --git a/reader.cpp b/reader.cpp
+index 0b6de20..e1a26e3 100644
+--- a/reader.cpp
++++ b/reader.cpp
+@@ -11,6 +11,8 @@
+ #include <pthread.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
++#include <netinet/in.h>
++#include <netinet/tcp.h>
+
+ int64_t htonll(int64_t value){
+ int num = 42;
+@@ -131,6 +133,8 @@ int socket_open(const char *hostname, int port)
+ {
+ int ret;
+ int sockfd;
++ int val;
++
+ struct sockaddr_in serv_addr;
+ struct hostent *server;
+
+@@ -159,6 +163,32 @@ int socket_open(const char *hostname, int port)
+ fprintf(stderr, "ERROR connecting %d, %d\n", ret, errno);
+ return ret;
+ }
++
++ val = 5;
++ ret = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPCNT, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
++ val = 1;
++ ret = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
++ val = 1;
++ ret = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
++
+ return sockfd;
+ }
+
+@@ -344,4 +374,4 @@ int read_device(const char *devfile, const char *hostname, int port)
+ sleep(1);
+ }
+ return 0;
+-}
+\ No newline at end of file
++}
+diff --git a/write.cpp b/write.cpp
+index dc6c3bc..67ce412 100644
+--- a/write.cpp
++++ b/write.cpp
+@@ -8,6 +8,9 @@
+ #include <unistd.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
++#include <sys/socket.h>
++#include <netinet/in.h>
++#include <netinet/tcp.h>
+
+ int64_t ntohll(int64_t value){
+ int num = 42;
+@@ -30,6 +33,8 @@ int socket_start_listen(int port)
+ {
+ int ret;
+ int sockfd;
++ int val;
++
+ struct sockaddr_in serv_addr;
+
+ printf("starting on port %d\n", port);
+@@ -48,7 +53,41 @@ int socket_start_listen(int port)
+ fprintf(stderr, "ERROR on binding %d", ret);
+ return ret;
+ }
++
++ val = 1;
++ ret = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
++ val = 5;
++ ret = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPCNT, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
++ val = 1;
++ ret = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
++ val = 1;
++ ret = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL, &val,
++ sizeof(val));
++ if (ret < 0) {
++ fprintf(stderr, "ERROR on setsockopt %d", ret);
++ return ret;
++ }
++
+ listen(sockfd, 1);
++
+ return sockfd;
+ }
+
+@@ -174,10 +213,13 @@ int spawn_device_new(int sock_con)
+
+ fprintf(stderr, "Transferring input events.\n");
+ while (true) {
++ int ret;
+ input_event_t et;
+ int dummy;
+ waitpid(0, &dummy, WNOHANG);
+- if (!read(sock_con, (char*)&et, sizeof(et))) {
++ ret = read(sock_con, (char*)&et, sizeof(et));
++
++ if (ret <= 0) {
+ fprintf(stderr, "End of data\n");
+ break;
+ }
+@@ -233,4 +275,4 @@ int spawn_device(int port)
+ err_close:
+ close(sock_listen);
+ return -1;
+-}
+\ No newline at end of file
++}
+--
+2.7.4
+