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.

Send a struct as an array of char in TCP send() in NDK causes failure

Hello,

I have been using NDK to launch server functions using the

DaemonNew() call. The TX buffer size is set to 8192.

In the callback function at some point data in sent using:

Example:

resp = send( s, passer, 1000, 0);

where (outside the function):

char

 

 

and passer elements have any value.

This works fine. Now I need to send a structure. If I do the following:

Case 1:

resp = send( s, &COPROC_INPUTDATA, 1000, 0);

Where COPROC_INPUTDATA is a structure of arrays of char and other stuff. The size is >1000, but I am only sending 1000 for a test.

OR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Case 2:

 

 

 

char

 

 

*pass=0;

pass = (

char *) &COPROC_INPUTDATA;

resp = send( s, pass, 1000, 0);

OR

Case 3:

 

char

 

*pass=0;

 

 

pass = (

char *) &COPROC_INPUTDATA;

memcpy(passer, pass, 1000);

 

resp = send( s, passer, 1000, 0);

All of these result in a failed send where after checking fdError() the error code is 9 (bad file descriptor) which seems not to have much to do with the array, but apparently is only affect by the pointer type. I am truely at a loss as to why this should have any effect on send().

Any thoughts are very welcome.

Thanks in advance.

 

Dan.

  • Sorry about the formatting above!

    It looked fine until I pushed "Post"...

    Dan.

  • Update;

    OK...I had some cases even a "plain vanilla" array of char could cause the error as well.

    What has (so far) seemed to make a difference was the removal of a status check just before the send.

    Before:

    fdStatus(s, FDSTATUS_RECV, stat);

    send(...);

    Before this send ocurred there is a lot of network activity: Data being uploaded on one socket and then closing, and two internal task changes all occurring right before this portion. I am assuming this could be the cause behind the "Bad File Descriptor" error so as well as removing the fdStatus() check I have also added a small delay (1msec) right before entering the loop that includes this send. It seems to work at the moment. I will report back.

     

    Dan.