TI中文支持网
TI专业的中文技术问题搜集分享网站

CC3235SF: 关于如何获取socket发送缓冲区的大小问题

Part Number:CC3235SF

请问我想要获取TCP-client socket端口的发送缓冲区应该怎么获取呢?如何修改发送缓冲区的大小?关于我使用MQTT-client例程来进行发送数据到上位机,但是我发现在使用sl_send()函数的时候出现了返回-11的情况,而且经过测试,十几分钟约出现丢包四五次的情况,这种情况应该如何解决呢?

以下是关于TCP socket的相关接口函数,请问这样编写代码是否有问题呢?数据发往上位机是通过调用tcp_client_send()来执行。

//****************************************************************************
int32_t tcp_client_disconnect(void)
{_i16 status=0;if (!is_connect){//UART_PRINT("tcp_connect_close, error, tcp_client_socket < 0");return -1;}UART_PRINT("tcp_connect_close, start close\n\r");is_connect = FALSE;/* Calling 'close' with the socket descriptor,* once operation is finished. */status = sl_Close(tcp_client_socket);tcp_client_socket = -1;ASSERT_ON_ERROR(status);UART_PRINT("tcp_connect_close,  close OK\n\r");return 0;
}

int32_t tcp_client_connect( void)
{SlSockAddr_t *sa;sockAddr_t sAddr;int32_t addrSize;int32_t status;int32_t nonBlocking;ip_t ip_addr;int32_t timeout;ip_addr.ipv4 = wifi_config.server_ip;uint16_t portNumber = wifi_config.server_port;if (is_connect){//UART_PRINT("tcp is already connected\n\r");return -1;}UART_PRINT("tcp_connect_start, start connect\n\r");/* filling the TCP server socket address */sAddr.in4.sin_family = SL_AF_INET;/* Since this is the client's side,* we must know beforehand the IP address* and the port of the server wer'e trying to connect.*/sAddr.in4.sin_port = sl_Htons((unsigned short)portNumber);sAddr.in4.sin_addr.s_addr = sl_Htonl((unsigned int)ip_addr.ipv4);sa = (SlSockAddr_t*)&sAddr.in4;addrSize = sizeof(SlSockAddrIn_t);/* Get socket descriptor - this would be the* socket descriptor for the TCP session.*/tcp_client_socket = sl_Socket(sa->sa_family, SL_SOCK_STREAM, TCP_PROTOCOL_FLAGS);ASSERT_ON_ERROR(tcp_client_socket);nonBlocking = TRUE;//timeout=30;status = sl_SetSockOpt(tcp_client_socket, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlocking, sizeof(nonBlocking));if(status < 0){UART_PRINT("[line:%d, error:%d], socket = %d\n\r", __LINE__, status, tcp_client_socket);usleep(1000000);sl_Close(tcp_client_socket);tcp_client_socket = -1;return(-1);}status = -1;/* Calling 'sl_Connect' followed by server's* 'sl_Accept' would start session with* the TCP server. */while(status < 0){status = sl_Connect(tcp_client_socket, sa, addrSize);if(status == SL_ERROR_BSD_EALREADY){usleep(1000000);continue;}else if(status < 0){UART_PRINT("[line:%d, error:%d], socket = %d\n\r", __LINE__, status, tcp_client_socket);usleep(100000);sl_Close(tcp_client_socket);tcp_client_socket = -1;return(-1);}}is_connect = TRUE;UART_PRINT("tcp_connect_start, connect OK,tcp_client_socket = %d\n\r ", tcp_client_socket);return 0;
}

extern mqd_t appQueue ;
uint8_t n=0;
int32_t tcp_client_send(uint8_t* data_buf, uint16_t buf_len)
{_u16 temp=0;int32_t status=0;//UART_PRINT("tcp_client_send, send start\n\r");if (!is_connect){UART_PRINT("tcp is disconnected\n\r");return -1;}/* Send packets to the server */status = sl_Send(tcp_client_socket, data_buf, buf_len, 0);  //返回的是buf_len
//UART_PRINT("MinTxPayloadSize = %d\r\n",g_pCB->FlowContCB.MinTxPayloadSize);
//UART_PRINT("TxPoolCnt = %d\r\n",g_pCB->FlowContCB.TxPoolCnt);while(status != buf_len)//死循环{n++;status = sl_Send(tcp_client_socket, data_buf, buf_len, 0);if(n==5){// usleep(5);//需不需要呢?n=0;status = sl_Send(tcp_client_socket, data_buf, buf_len, 0);if(status != buf_len)break;}}if(status == SL_ERROR_BSD_EAGAIN){status = sl_Send(tcp_client_socket, data_buf, buf_len, 0);}else if(status < 0){UART_PRINT("[line:%d, error:%d]\n\r", __LINE__, status);usleep(100000);tcp_client_disconnect();return(-1);}else{// UART_PRINT("Tcp client Sent %u packets successfully\n\r", status);}return 0;
}

int32_t tcp_client_receive(uint8_t* data_buf, uint16_t* receive_len)
{int32_t status;//UART_PRINT("tcp_client_receive, receive start\n\r");if (!is_connect){//UART_PRINT("tcp is disconnected\n\r");return -1;}status = sl_Recv(tcp_client_socket, data_buf, MAX_BUF_SIZE, 0);if(status == SL_ERROR_BSD_EAGAIN){}else if(status < 0){UART_PRINT("[line:%d, error:%d]\n\r", __LINE__, status);usleep(100000);tcp_client_disconnect();return(-1);}else if(status == 0){UART_PRINT("TCP Server closed the connection\n\r");usleep(100000);tcp_client_disconnect();return(-1);}else{//UART_PRINT("Tcp client Receive %u packets successfully\n\r", status);}*receive_len = (uint16_t)status;return 0;
}

bool tcp_is_connected(void)
{return is_connect;
}

还有就是,为什么我DEBUG的时候g_pCB->FlowContCB.MinTxPayloadSize是有值的,但是打印的时候却全是0呢?

UART_PRINT("MinTxPayloadSize = %d\r\n",g_pCB->FlowContCB.MinTxPayloadSize);

请尽快给与解答,急~谢谢

Kevin Qiu1:

你的问题在英文论坛已有工程师回复:https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1070454/cc3235sf-about-sl_-send-failed-to-send-and-returned—11

Shlomi正在跟进,请继续在原帖讨论

,

wu:

但是我的问题依旧解决不了,请给予更多的帮助

,

wu:

我已经将板子上的18引脚空出来了,那么我应该如何操作才能获取NWP日志呢?

,

wu:

因为我使用开发板上的下载器来将程序下载到自己的板子上,那么我这里的连接需要怎么连接呢?

请尽快回复,比较急需解决

,

wu:

怎么操作呢?能不能告诉一声呢!!!!

,

Kevin Qiu1:

通常我们不会在重复的问题上继续投入,解析NWP log也需要英文论坛产品线工程师操作,我没有解析NWP log的可用资源

回答你的问题:

wu 说:

因为我使用开发板上的下载器来将程序下载到自己的板子上,那么我这里的连接需要怎么连接呢?

你的情况只需要将P62改为P18,然后按照文档20章的步骤操作就可以了,上面图片中说的两种情况不适合你,指的是其他板子

,

wu:

请问我将服务器主动关闭的时候,DEBUF时发现sl_Socket()返回的是-2005,查找资料好像这个错误码表示主机驱动程序检测到错误,API已中止,请问这是什么情况呢?但是当我发送一种电量类型的数据时呢,再主动关闭服务器的时候,重新打开,是可以重新建立起连接的,sl_Socket()也不会返回-2005.

,

Kevin Qiu1:

关于这个错误参考里面的说明:https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/813438/cc3120-sl_recv-returns–2005-error-code

,

wu:

里面并没有提到相关的解决方法,请给出具体的查找或者解决方案。

赞(0)
未经允许不得转载:TI中文支持网 » CC3235SF: 关于如何获取socket发送缓冲区的大小问题
分享到: 更多 (0)