Part Number: F28M36P63C2
Tool/software: TI-RTOS
I am evaluating TI-RTOS/NDK on F28M36P63C2 and have problems using recvnc. I have started with the tcp echo example, which works, and then modified the tcpWorker() task as follows to use recvnc() instead of recv():
/*
* ======== tcpWorker ========
* Task to handle TCP connection. Can be multiple Tasks running
* this function.
*/
Void tcpWorker(UArg arg0, UArg arg1)
{
SOCKET clientfd = (SOCKET)arg0;
Int nbytes;
Bool flag = TRUE;
Char *buffer;
Error_Block eb;
if (fdOpenSession(TaskSelf()) == 0)
{
System_printf("tcpWorker: session error for clientfd = 0x%x\n", clientfd);
}
else
{
System_printf("tcpWorker: start clientfd = 0x%x\n", clientfd);
}
/* Make sure Error_Block is initialized */
Error_init(&eb);
uint32_t received_bytes=0;
#ifndef NO_COPY
/* Get a buffer to receive incoming packets. Use the default heap. */
buffer = Memory_alloc(NULL, TCPPACKETSIZE, 0, &eb);
if (buffer == NULL) {
System_printf("tcpWorker: failed to alloc memory\n");
Task_exit();
}
#else
HANDLE hBuffer;
#endif
/* Loop while we receive data */
while (flag) {
#ifdef NO_COPY
nbytes = recvnc(clientfd, (void **)&buffer, 0, &hBuffer);
#else
nbytes = recv(clientfd, buffer, TCPPACKETSIZE, 0);
#endif
if (nbytes > 0) {
/* Echo the data back */
// send(clientfd, (char *)buffer, nbytes, 0 );
received_bytes += nbytes;
#ifdef NO_COPY
recvncfree(hBuffer);
#endif
}
else {
if (nbytes < 0 )
{
System_printf("Socket error %d\n", fdError());
}
fdClose(clientfd);
flag = FALSE;
}
}
System_printf("tcpWorker stop clientfd = 0x%x, %d bytes received\n", clientfd,received_bytes);
#ifndef NO_COPY
/* Free the buffer back to the heap */
Memory_free(NULL, buffer, TCPPACKETSIZE);
#endif
fdCloseSession(TaskSelf());
System_flush();
/*
* Since deleteTerminatedTasks is set in the cfg file,
* the Task will be deleted when the idle task runs.
*/
Task_exit();
}
I am testing with iperf v2 connecting to the Concerto to measure the max receive rate. When the NO_COPY macro is not defined iperf runs to completion and I get the total number of bytes received in the debug console after the test completes and the connection is closed. However, when NO_COPY is defined recvnc() returns -1 right after the worker task is started and fderror gives error 22 (Invalid argument), though iperf keeps sending data, meaning that NDK is still ACKing them.
This is with the default NDK setting, I have also tried increasing the buffer sizes etc though I don't get any OOM errors in the console.
Is there a tried and tested example using recvnv()?