I have been toying with the TCP Echo example using TI-RTOS to continuously send packets of 1024 bytes (would like to increase to 1460 when working). What is happening though is I'm getting 2 smaller packets sent instead of just the one 1024 byte packet.
Setting a breakpoint on the send function and looping a send at a time seems to work most of the time however.
From Wireshark:
72428 22.591278000 192.168.0.2 192.168.0.1 TCP 490 1234→50914 [PSH, ACK] Seq=24717901 Ack=1 Win=1024 Len=436
72429 22.592141000 192.168.0.2 192.168.0.1 TCP 642 1234→50914 [PSH, ACK] Seq=24718337 Ack=1 Win=1024 Len=588
72430 22.592196000 192.168.0.1 192.168.0.2 TCP 54 50914→1234 [ACK] Seq=1 Ack=24718925 Win=63216 Len=0
My code is as follows:
I have tried to add TCP_NODELAY by adding the following:
setsockopt(server, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
Anyone have any ideas why the 1024 Byte packets is being split?
Regards,
Lee.
/* * ======== tcpEcho.c ======== * Contains BSD sockets code. */ #include <string.h> #include <xdc/std.h> #include <xdc/cfg/global.h> #include <xdc/runtime/Error.h> #include <xdc/runtime/System.h> #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> #include <ti/drivers/GPIO.h> /* NDK BSD support */ #include <sys/socket.h> /* Example/Board Header file */ #include "Board.h" #define TCPPACKETSIZE 1024 #define NUMTCPWORKERS 1 const static char buffer[1024] = { '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9', '0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9' }; /* * ======== tcpWorker ======== * Task to handle TCP connection. Can be multiple Tasks running * this function. */ Void tcpWorker(UArg arg0, UArg arg1) { int clientfd = (int)arg0; //int bytesRcvd; int bytesSent; // char buffer[TCPPACKETSIZE]; System_printf("tcpWorker: start clientfd = 0x%x\n", clientfd); System_flush(); // while ((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0) { while(1){ bytesSent = send(clientfd, buffer,TCPPACKETSIZE, 0); if (bytesSent < 0 ) { System_printf("Error: send failed.\n"); System_flush(); break; } } System_printf("tcpWorker stop clientfd = 0x%x\n", clientfd); System_flush(); close(clientfd); } /* Void tcpWorker(UArg arg0, UArg arg1) { int clientfd = (int)arg0; int bytesRcvd; int bytesSent; char buffer[TCPPACKETSIZE]; System_printf("tcpWorker: start clientfd = 0x%x\n", clientfd); while ((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0) { bytesSent = send(clientfd, buffer, bytesRcvd, 0); if (bytesSent < 0 || bytesSent != bytesRcvd) { System_printf("Error: send failed.\n"); break; } } System_printf("tcpWorker stop clientfd = 0x%x\n", clientfd); close(clientfd); } */ /* * ======== tcpHandler ======== * Creates new Task to handle new TCP connections. */ Void tcpHandler(UArg arg0, UArg arg1) { int status; int clientfd; int server; struct sockaddr_in localAddr; struct sockaddr_in clientAddr; int optval; int optlen = sizeof(optval); socklen_t addrlen = sizeof(clientAddr); Task_Handle taskHandle; Task_Params taskParams; Error_Block eb; int i = 1; server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (server == -1) { System_printf("Error: socket not created.\n"); goto shutdown; } memset(&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; localAddr.sin_addr.s_addr = htonl(INADDR_ANY); localAddr.sin_port = htons(arg0); status = bind(server, (struct sockaddr *)&localAddr, sizeof(localAddr)); if (status == -1) { System_printf("Error: bind failed.\n"); goto shutdown; } status = listen(server, NUMTCPWORKERS); if (status == -1) { System_printf("Error: listen failed.\n"); goto shutdown; } if (setsockopt(server, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) { System_printf("Error: setsockopt failed\n"); goto shutdown; } setsockopt(server, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i)); while ((clientfd = accept(server, (struct sockaddr *)&clientAddr, &addrlen)) != -1) { System_printf("tcpHandler: Creating thread clientfd = %d\n", clientfd); /* Init the Error_Block */ Error_init(&eb); /* Initialize the defaults and set the parameters. */ Task_Params_init(&taskParams); taskParams.arg0 = (UArg)clientfd; taskParams.stackSize = 2560; taskHandle = Task_create((Task_FuncPtr)tcpWorker, &taskParams, &eb); if (taskHandle == NULL) { System_printf("Error: Failed to create new Task\n"); close(clientfd); } /* addrlen is a value-result param, must reset for next accept call */ addrlen = sizeof(clientAddr); } System_printf("Error: accept failed.\n"); shutdown: if (server > 0) { close(server); } } /* * ======== main ======== */ int main(void) { /* Call board init functions */ Board_initGeneral(); Board_initGPIO(); Board_initEMAC(); System_printf("Starting the TCP Echo example\nSystem provider is set to " "SysMin. Halt the target to view any SysMin contents in" " ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ BIOS_start(); return (0); }
/* * ======== tcpEcho.cfg ======== */ /* ================ General configuration ================ */ var Defaults = xdc.useModule('xdc.runtime.Defaults'); var Diags = xdc.useModule('xdc.runtime.Diags'); var Error = xdc.useModule('xdc.runtime.Error'); var Log = xdc.useModule('xdc.runtime.Log'); var Main = xdc.useModule('xdc.runtime.Main'); var Memory = xdc.useModule('xdc.runtime.Memory'); var System = xdc.useModule('xdc.runtime.System'); var Text = xdc.useModule('xdc.runtime.Text'); var BIOS = xdc.useModule('ti.sysbios.BIOS'); var Clock = xdc.useModule('ti.sysbios.knl.Clock'); var Task = xdc.useModule('ti.sysbios.knl.Task'); var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore'); var Hwi = xdc.useModule('ti.sysbios.hal.Hwi'); var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem'); var LoggingSetup = xdc.useModule('ti.uia.sysbios.LoggingSetup'); BIOS.heapSize = 20480; Task.idleTaskStackSize = 768; /* * Program.stack is ignored with IAR. Use the project options in * IAR Embedded Workbench to alter the system stack size. */ if (!Program.build.target.$name.match(/iar/)) { /* * Reducing the system stack size (used by ISRs and Swis) to reduce * RAM usage. */ Program.stack = 2048; } /* ================ System configuration ================ */ var SysMin = xdc.useModule('xdc.runtime.SysMin'); SysMin.bufSize = 128; System.SupportProxy = SysMin; /* Enable Semihosting for GNU targets to print to CCS console */ if (Program.build.target.$name.match(/gnu/)) { var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport'); } /* ================ NDK configuration ================ */ var Ndk = xdc.loadPackage('ti.ndk.config'); var Global = xdc.useModule('ti.ndk.config.Global'); var Ip = xdc.useModule('ti.ndk.config.Ip'); var Udp = xdc.useModule('ti.ndk.config.Udp'); var Tcp = xdc.useModule('ti.ndk.config.Tcp'); Global.IPv6 = false; Global.stackLibType = Global.MIN; Global.networkOpenHook = "&netOpenHook"; /* automatically call fdOpen/CloseSession for our sockets Task */ Global.autoOpenCloseFD = true; Global.pktNumFrameBufs = 10; Global.memRawPageCount = 6; Global.ndkThreadStackSize = 1536; Global.lowTaskStackSize = 2048; Global.normTaskStackSize = 2048; Global.highTaskStackSize = 2048; Tcp.transmitBufSize = 1460; Tcp.receiveBufSize = 1024; /* ================ Driver configuration ================ */ var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS'); TIRTOS.useEMAC = true; TIRTOS.useGPIO = true; Ip.autoIp = false; Ip.address = "192.168.0.2"; Tcp.maxNumReasmPkts = 1; LoggingSetup.loadTaskLogging = true; LoggingSetup.enableTaskProfiler = true; Ip.socketBufMinRxSize = 100;