Skip to content

Commit

Permalink
Merge pull request j123b567#133 from folkertvanheusden/tcp
Browse files Browse the repository at this point in the history
see issue j123b567#131 (problem talking to sigrok over tcp)
  • Loading branch information
j123b567 authored Jan 16, 2023
2 parents 3c575a2 + c2da7b7 commit 97a4bf6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/test-tcp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -193,7 +201,7 @@ int main(int argc, char** argv) {
listenfd = createServer(5025);

while (1) {
int clifd;
int clifd, flag = 1;
struct sockaddr_in cliaddr;
socklen_t clilen;

Expand All @@ -202,6 +210,8 @@ int main(int argc, char** argv) {

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;
Expand Down

0 comments on commit 97a4bf6

Please sign in to comment.