Other Parts Discussed in Thread: CC3120
Tool/software: TI-RTOS
Hi,
I'm working on an application that requires over than 20 socket. I have an MSP432E401Y with 2.10.00.17 SDK.
I'm able to start only 12 socket, and I tried different configuations. (the heap memory is not full)
/* Socket file descriptor table */ #define MAXSOCKETS (32) uint32_t ti_ndk_socket_max_fd = MAXSOCKETS; void *ti_ndk_socket_fdtable[MAXSOCKETS]; #define RECEIVE_BUFFER_SIZE (248)//(2048) #define TX_BUFF_SIZE (124)//(1024) #define RX_BUFF_SIZE (124)//(1024) #define RECEIVE_BUFF_LIMIT (RX_BUFF_SIZE*2) /* NDK memory manager page size and number of pages [used by mmAlloc()] */ #define RAW_PAGE_SIZE (3072) #define RAW_PAGE_COUNT (6)//(6)
My firmware starts N tasks from tcpecho example (they are the same from TI), all the tasks are successfully executed, but only the first 12 are able to open a new socket.
if (fAdd && createTask) {
/*
* Create the Task that farms out incoming TCP connections.
* arg0 will be the port that this task listens to.
*/
for (status=0;status<20;status++){
taskHandle = TaskCreate(tcpHandler, NULL, 1, TCPHANDLERSTACK, TCPPORT + status,
0, 0);
if (!taskHandle) {
/* netOpenHook: Failed to create tcpHandler thread */
while(1);
}
}
createTask = false;
}
/*
* ======== tcpWorker ========
* Task to handle TCP connection. Can be multiple Tasks running
* this function.
*/
void tcpWorker(uint32_t arg0, uint32_t arg1)
/*******************************************************************************
* @fn tcpWorker
*
* @brief Task to handle TCP connection. Can be multiple Tasks running
* this function.
*
* @param arg0: connection identifier, arg1: NULL
*
* @return none (kill task on exit)
*/
{
int clientfd = (int)arg0;
int bytesRcvd;
int bytesSent;
char buffer[TCPPACKETSIZE];
/* tcpWorker: start clientfd */
/* wait packets */
while ((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0) {
bytesSent = send(clientfd, buffer, bytesRcvd, 0);
if (bytesSent < 0 || bytesSent != bytesRcvd) {
/* send failed */
/* TO DO */
break;
}
}
/* tcpWorker stop clientfd */
close(clientfd);
}
/*
* ======== tcpHandler ========
* Creates new Task to handle new TCP connections.
*/
void tcpHandler(uint32_t arg0, uint32_t arg1)
/*******************************************************************************
* @fn tcpHandler
*
* @brief Creates new Task to handle new TCP connections.
*
* @param arg0: PORT SERVER
*
* @return none
*/
{
void *thread = NULL;
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);
/* TCP Socket */
server = socket(AF_INET, SOCK_STREAM, 0);
if (server == -1) {
/* socket failed */
/* TO DO */
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) {
/* bind failed */
/* TO DO */
goto shutdown;
}
status = listen(server, NUMTCPWORKERS);
if (status == -1) {
/* listen failed */
/* TO DO */
goto shutdown;
}
optval = TRUE;
status = setsockopt(server, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
if (status == -1) {
/* setsockopt failed */
/* TO DO */
goto shutdown;
}
while ((clientfd =
accept(server, (struct sockaddr *)&clientAddr, &addrlen)) != -1) {
/* Creating thread clientfd */
thread = TaskCreate(tcpWorker, NULL, TCPWORKER_TASK_PRIORITY, TCPWORKER_STACK_SIZE, (uintptr_t)clientfd,
0, 0);
if (!thread) {
/* Failed to create new thread */
close(clientfd);
}
/* addrlen is a value-result param, must reset for next accept call */
addrlen = sizeof(clientAddr);
}
/* accept failed */
shutdown:
if (server != -1) {
close(server);
}
}
Thanks,
Tom