send with big buffer

Lino
Posts: 16
Joined: Thu Jan 28, 2010 7:53 am

send with big buffer

Post by Lino » Fri Aug 13, 2010 10:42 am

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.

WinterMute
Site Admin
Posts: 1863
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: send with big buffer

Post by WinterMute » Fri Aug 13, 2010 11:57 am

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;
}
Help keep devkitPro toolchains free, Donate today

Personal Blog

Lino
Posts: 16
Joined: Thu Jan 28, 2010 7:53 am

Re: send with big buffer

Post by Lino » Fri Aug 13, 2010 12:15 pm

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.

Lino
Posts: 16
Joined: Thu Jan 28, 2010 7:53 am

Re: send with big buffer

Post by Lino » Fri Aug 13, 2010 12:50 pm

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.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: send with big buffer

Post by elhobbs » Fri Aug 13, 2010 2:14 pm

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.

Lino
Posts: 16
Joined: Thu Jan 28, 2010 7:53 am

Re: send with big buffer

Post by Lino » Fri Aug 13, 2010 5:42 pm

it is not working. Anyway thanks.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: send with big buffer

Post by elhobbs » Fri Aug 13, 2010 5:56 pm

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.

Lino
Posts: 16
Joined: Thu Jan 28, 2010 7:53 am

Re: send with big buffer

Post by Lino » Fri Aug 13, 2010 6:21 pm

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.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: send with big buffer

Post by elhobbs » Fri Aug 13, 2010 7:00 pm

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.

Lino
Posts: 16
Joined: Thu Jan 28, 2010 7:53 am

Re: send with big buffer

Post by Lino » Fri Aug 13, 2010 7:32 pm

The HTTP POST is good. You can check, the alignment, in the func init_fb. Anyway thare are opcodes with translation in arm cpus.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 9 guests