Re: C++ TCP code differences Pi-3 to Pi-4?


Bernard Littau
 

Hi Larry,

Change your use of accept to accept(localSocket, NULL,NULL); and remove all the client addr and len stuff. 

I think you are getting stack garbage in your clilen parameter that is causing accept to fail.  Since you are not using the return values just get rid of them.  

Bernard
KE7FEQ 

On Wed, Sep 9, 2020 at 02:49 Larry K8UT <K8UT@...> wrote:
Thanks for the hints and suggestions. On a whim, I loaded a microSD card with the beta Raspberry Pi 64 bit OS and ... it works! Fearing my success was a fluke, I loaded/reloaded microSD cards with production 32 bit versions and beta 64 bit versions, inserting them in 2gb and 8gb Pi-4 hardware. Identical results in all tests: 32 bit platform fails at socket Accept stage; 64 bit succeeds.

Here's the code. Works on 32 bit Pi-3, on 64 bit Pi-4; not on 32 bit Pi-4:


//----- get TCP Packet String from CLIENT console-----------------------


string getTcpPacketString(int localSocket ) {


 


socklen_t clilen;


struct sockaddr_in cliaddr;


int newsockfd;


 


signal(SIGCHLD, SIG_IGN);// delete zombie fork processes


// waiting for poll()


int pResult = poll(fds, nfds, timeout);


if ( pResult == -1 ) { error("ERROR on socket poll()\n"); }


if ( pResult == 0 ) { usleep(10000); return ""; } // no client connected during this cycle


 


    newsockfd = accept(localSocket, (struct sockaddr *) &cliaddr, &clilen);


    if (newsockfd < 0) {


cout << "Error on accept..." << endl;


usleep(10000);


return "-1";


//error("ERROR on accept");


}


uint maxPacketSize = 2048;


char packet_data[maxPacketSize];


memcpy(packet_data, "\0", maxPacketSize);


 


uint received_bytes = read( newsockfd, packet_data, maxPacketSize);


if (received_bytes < 0) { error("ERROR reading from socket"); }


 


string localString(packet_data);


localString = localString.substr(0, received_bytes); 


// return a substring, else that entire DIM size is returned with trailing random chars


 


close(newsockfd);


return localString;


} // end getTcpPacketString ------------------------------------------


 








Join RaspberryPi-4-HamRadio@groups.io to automatically receive all group messages.