Page 1 of 3

send with big buffer

Posted: Fri Aug 13, 2010 10:42 am
by Lino
Hello,

I have this problem, I am using this command send(cli_sock,buffer,i,0); with big buffers over 5000 bytes.
But there is a strange problem,with a sniffer, I read all TCP's packet that my DS sends, but the packets, with send of 5200 bytes, are 2 and they are same.

Why? can you help me?

Excuse me for my English.

Re: send with big buffer

Posted: Fri Aug 13, 2010 11:57 am
by WinterMute
send can and will return without sending all of the data you requested, you need to check for this and compensate.

Code: Select all

//---------------------------------------------------------------------------------
int sendData(int socket, int sendsize, char *buffer) {
//---------------------------------------------------------------------------------
	while(sendsize) {
		int len = send(socket, buffer, sendsize, 0);
		if (len <= 0) break;
		sendsize -= len;
		buffer += len;
	}
	return sendsize <= 0;
}

Re: send with big buffer

Posted: Fri Aug 13, 2010 12:15 pm
by Lino
Ok thanks Ill try. But the send works fine, if I use send(cli_sock,buffer,5000,0) it returns 5000. But with sniffer I can read 2 packets with same content.

Re: send with big buffer

Posted: Fri Aug 13, 2010 12:50 pm
by Lino
Here's the test :

i = 5300;

Code: Select all

int data_send;
				
for(data_send=0;data_send < i;data_send += res){
	res = i - data_send;
	if(res > 800)
		res = 800;
	res = send(cli_sock,&buffer[data_send],res,0);
	if(res <= 0)
		break;			
}
res = data_send;
The sniffer (only 3 packets for over 5200 bytes)

Code: Select all

TCP  840
TCP 1460
TCP 1460
with same content.

Re: send with big buffer

Posted: Fri Aug 13, 2010 2:14 pm
by elhobbs
your loop has some confusing logic - try wintermute's loop and see if it works as expected. I use a similiar loop in cquake and it works fine.

it is probably counter productive to cap the sends at 800 bytes in any case as it will drastically reduce your throughput.

Re: send with big buffer

Posted: Fri Aug 13, 2010 5:42 pm
by Lino
it is not working. Anyway thanks.

Re: send with big buffer

Posted: Fri Aug 13, 2010 5:56 pm
by elhobbs
what about the client receiving the data? the ds tcp/ip stack has some weird window size issues so it may stop transmitting quickly if there are no acks - the data will be in the stack on the ds but waiting to transmit.

Re: send with big buffer

Posted: Fri Aug 13, 2010 6:21 pm
by Lino
Im working on my hb fb4nds, and Im sending a picture, you can read here, the func fb_upload_profile_image.
It woks well sometimes. In the func fb_send_req I create the socket and http request, POST.

Re: send with big buffer

Posted: Fri Aug 13, 2010 7:00 pm
by elhobbs
I suspect your POST may be malformed. you need to be carefull about unaligned access to ints. x86 handles this fine, but the arm processors in the ds only support aligned access - 4 bytes for ints and 2 bytes for shorts.

here is an example of a potential problem:

Code: Select all

size_data = *((int *)postdata); 
since postdata is a "char *" this will return unreliable results if it is not 4 byte aligned. you will need to read the bytes individually and build the int off of the buffer.

Re: send with big buffer

Posted: Fri Aug 13, 2010 7:32 pm
by Lino
The HTTP POST is good. You can check, the alignment, in the func init_fb. Anyway thare are opcodes with translation in arm cpus.