Quantcast
Channel: Renesas Synergy Platform
Viewing all articles
Browse latest Browse all 23645

Forum Post: NEtx Socket closing unexpectedly when NOT using printf

$
0
0
Hello forum! I have an ssp1.3 project that contains Guix, USBx, Filex, the Messaging Framework, and NETx. It doesn't do much yet, mostly just the various app notes piled into one application. Three threads - one for TCP, one for GUIX, and one for diagnostic message logging. Basically it does the following: HTTP server getting files from the USB drive - works great. GUIX with a bunch of screens that don't really do anything, just shows that it's all functional. Works fine. Every 10 seconds open a TCP socket to a server and send it a fixed block of data, wait for a response, then close. Seems to work well. A thread that, trough the messaging framework, other tasks can post a message to be logged. Said message goes to either or both of two places: Virtual Debug Console and, if available, a "logging server" via another socket that just echoes the message to the screen. Here's the issue: The socket for the logging server is opened and left open. As messages come in, the get spit out that socket. At the same time, if debugging is enabled, the same exact message gets printf'ed to the virtual debug console. See below... // wait for a message to log g_sf_message0.p_api->pend (g_sf_message0.p_ctrl, &LoggingThread_message_queue, &p_Header, TX_WAIT_FOREVER); . .// bunch of stuff to make sure we want to do something with this message, which we always do, and then... . tx_mutex_get(&g_LoggingThreadSprintfMutex, TX_WAIT_FOREVER); //sprintf and printf are not threadsafe, so grab the mutex sprintf(buffer,"UpTime:%ld %s\r\n",PayloadPtr->timeStamp,PayloadPtr->messageToLog); // format the message to go printf("%s",buffer); tx_mutex_put(&g_LoggingThreadSprintfMutex); // done with the mutex // send the data to the logging server // is the socket already open? If not, retry nx_tcp_socket_info_get(&logSocket, NX_NULL,NX_NULL,NX_NULL,NX_NULL,NX_NULL,NX_NULL,NX_NULL,&socketState,NX_NULL,NX_NULL,NX_NULL); if(socketState != NX_TCP_ESTABLISHED){ // is tcp up and running? status = tx_event_flags_get(&g_ThreadSyncEventGroup, TCP_INIT_DONE_EVENT_FLAG, TX_OR, &actualFlags, TX_NO_WAIT); if((status == TX_SUCCESS) && (actualFlags & TCP_INIT_DONE_EVENT_FLAG)){ // it is!! So lets try and open the connection // don't try and open a connection that is not in the closed state per the manual. Probably not needed, but it doesn't hurt. closeConnection(&logSocket); openConnection(&ip_0, "Logging Socket", LOGGING_SERVER, LOGGING_SOCKET, LOGGING_SOCKET+1, 100, &logSocket, loggingDataReceived); } } else if(socketState == NX_TCP_ESTABLISHED){ sendData(&pool_0, (UCHAR *)buffer, strlen(buffer), &logSocket); } If I leave the printf in the code, everything works great. Runs for days without an issue logging tens of thousands of messages. If I take the printf out (as I would in release mode since there is no virtual console) the logging socket stays open for some small amount of time (5-10 seconds), at which point it gets closed by something. It seems to be related to the timing of the other, periodic TCP send receive, but I can't be sure. Let me repeat that - printf in, all is well. Printf out, logging socket gets closed randomly. No other changes required. Just comment it out, and presto! Failure. Nothing else goes wrong: no crashes, web server still works, USB is fine, GUIX is fine. The code that reopens it if it gets closed works all the time, every time. BTW, that closeConnection(&logSocket) is the only spot in the code that ever closes that socket, so it only gets closed if it's already not open. I ran into the thing about printf in the GUIX thread causing crashes due to linker script issues and the heap, so I have that fix in my linker script. Perhaps this is related? I searched the forums, app notes, etc and found nothing. Hoping someone here has heard of something.

Viewing all articles
Browse latest Browse all 23645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>