This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[SOCK ERROR] - close socket (21) operation failed to transmit all queued packets after sl_close() is called

Other Parts Discussed in Thread: CC3200SDK, UNIFLASH, CC3200, CC3200-LAUNCHXL

Hi,

I am using CC3200SDK_1.1.0. 

I have written http webserver. Below is the sample code

SlSockAddrIn_t  local_addr;

uint32_t        non_blocking = 0;

SlSockAddr_t s Addr;

SlSocklen_t iAddrSize;

int16_t socket_fd;

int16_t new_socket_fd;

//filling the TCP server socket address
local_addr.sin_family = SL_AF_INET;
local_addr.sin_port = sl_Htons(80);
local_addr.sin_addr.s_addr = 0;

char buffer[1024] = {0};

socket_id = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);

sl_Bind(socket_id, (SlSockAddr_t *)&local_addr, addr_size);

sl_Listen(socket_id, 1);

sl_SetSockOpt(socket_id, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &non_blocking, sizeof(non_blocking));

while(1)

{

new_socket_fd = sl_Accept(socket_id, ( struct SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize);

sl_Recv(new_socket_fd, buffer, 1024, 0);

sl_Send(new_socket_fd, "Success", strlen("Success"), 0);

sl_Close(new_socket_fd);

}

Some times I used to get "[SOCK ERROR] - close socket (21) operation failed to transmit all queued packets" error. and client doesn't receive any response and continues to be in wait state. It is not every time I get this error. It's rare but it happens maybe once in 500 requests and it causing my client to be blocking state.

Can you please advice how can i handle this rare exception? I tried putting delay between sl_Send() and sl_Close() but didn't succeed. 

 

  • Hi Tejas,

    To elaborate a little on TCP connection when closing, a TCP FIN packet is sent to the other side and an ACK should be received. At this point, the receiver is closed but you can still transmit (at least until the other side send FIN packet of his own for which an ACK is sent back). So you can look at it as "half close".

    The error you get can happen when you closed the socket and you truely have packets in your TX queue pending to be transmitted or when you do not have packets pending for transmission but something in the TCP state procedure went wrong.

    In any case, it can happen if:

    • the other side closed the socket which caused FIN packet sent to SimpleLink before you closed the socket on your side
    • TCP reset sent (for any reason) which cause to break the TCP connection
    • TCP window of the other side got full and thus could not get any additional packets which made the packets you want to send stuck in your TX buffer

    Without sniffer it would be hard to debug.

    One last thing, there was a related but regarding TCP timeout that has been fixed in latest servicepack.

    What servicepack are you using? I see you are using a relatively old SDK (1.1.0) so I assume you do not use the latest SDK.

    Please move to SDK1.2.0 and servicepack v1.0.1.6-2.7.0.0.

    It can be downloaded from http://www.ti.com/tool/cc3200sdk

    Regards,

    Shlomi

  • Hello Tejas,

    Any update on the post?

    Regards,
    Shlomi

  • I am moved to SDK1.2.0 and servicepack v1.0.1.6-2.7.0.0 but Now I am facing other issues. The code which was working on old SDK. Now it's not working on new one. I have used custom webserver so i stopped internal webserver using sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID); API. Now this api is returning -100 error code(SL_API_ABORTED).
  • Hello,

    The -100 which is the SL_API_ABORTED indicates that the host is detecting an error from network processor or timeout on the command sent.

    Since it did worked for you before, can you please try to format the device using Uniflash and load the new service pack and your application again? Just want to make sure we are starting from scratch.

    Additionally, are you using TI LaunchPad or some custom board of your own? what is the CC3200 version?

    Regards,

    Shlomi

  • I have tried again with format using uniflash and loading new service pack but didn't succeed. I am using CC3200-LAUNCHXL Rev4.1

  • Is it only this API, sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID)?

    Or do you see other APIs returning the same as well (if you remark this call)?

    Shlomi

  • In my code I have called sl_Start(NULL, NULL, NULL) twice as it is required. One when I initialize everything and second when I connect to wifi station, I check if device is in station mode. So first sl_Start returns 0(ROLE_STA). and second sl_Start returns 1(ROLE_UNKNOWN). my application tries to set mode to station using sl_WlanSetMode(ROLE_STA) and it returns -100 and then on wards simplelink APIs starts to return -100 even sl_NetAppStop.
  • Hello Tejas,

    You cannot call sl_start() twice in a role.

    Only if sl_stop() has been called previously, you can call sl_start() again.

    Can you verify that after you configure everything, you call sl_stop() and only then sl_start()?

    Regards,

    Shlomi

  • Hi Shlomi,

    Same code was working fine with TI SDK 1.1.0 . I have put sl_Stop() before second sl_Start() and now it's working fine. but some times I can see Tx failed error .  The message looks like "SimpleLinkSockEventHandler: [SOCK ERROR] - TX FAILED  :  socket 22 , reason (0)" . 

  • Hello Tejas,

    It is different from what you reported in the initial post.

    How is this error effecting the behavior.

    Do you really see that some expected data is not reaching its destination.

    It may be that the other side closed the socket which caused FIN packet sent to SimpleLink before you closed the socket on your side. I am trying to understand whether it really breaks the process or not.

    In any case, a sniffer would help a lot here.

    Regards,

    Shlomi