From 97a4bf6d10aa038110e68b5a22e9a5f5bf9ffc35 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周一, 16 1月 2023 16:36:17 +0800 Subject: [PATCH] Merge pull request #133 from folkertvanheusden/tcp --- examples/test-tcp/main.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/test-tcp/main.c b/examples/test-tcp/main.c index 3853e01..814dbf5 100644 --- a/examples/test-tcp/main.c +++ b/examples/test-tcp/main.c @@ -45,22 +45,30 @@ #include <errno.h> #include <arpa/inet.h> #include <unistd.h> +#include <netinet/tcp.h> #include "scpi/scpi.h" #include "../common/scpi-def.h" size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { - (void) context; - if (context->user_context != NULL) { int fd = *(int *) (context->user_context); + + int state = 1; + setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)); + return write(fd, data, len); } return 0; } scpi_result_t SCPI_Flush(scpi_t * context) { - (void) context; + if (context->user_context != NULL) { + int fd = *(int *) (context->user_context); + + int state = 0; + setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)); + } return SCPI_RES_OK; } @@ -193,7 +201,7 @@ listenfd = createServer(5025); while (1) { - int clifd; + int clifd, flag = 1; struct sockaddr_in cliaddr; socklen_t clilen; @@ -202,6 +210,8 @@ if (clifd < 0) continue; + setsockopt(clifd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); + printf("Connection established %s\r\n", inet_ntoa(cliaddr.sin_addr)); scpi_context.user_context = &clifd; -- Gitblit v1.9.1