BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 29th, 2011, 05:01 PM
ktoz ktoz is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Posts: 562 ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level)ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level)ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level)ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level)ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level)ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level)ktoz User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 4 m 2 sec
Reputation Power: 69
Only receiving max of 1448 bytes on socket reads

Hi

I'm writing a native MySQL connection class in Objective C and have it working nicely so long as the App using the class and the MySQL server are on the same machine. If the MySQL database is on a remote server, when I read data from the BSD socket file descriptor, it maxes out at 1448 bytes. Queries whose results are smaller than 1448 bytes execute fine, but above that, and I don't know how to retreive all the expected data. Here's how I'm reading the socket

Code:
- (NSData *) reply
{
	NSMutableData	*result		= [NSMutableData data];
	int		bytesRead	= readBufferLength;
	
	while (bytesRead == readBufferLength)
	{
		bytesRead = read(socketFD, readBuffer, readBufferLength);
		
		NSLog(@"bytesRead: %i", bytesRead);
		
		// append buffer's data to result
		if (bytesRead > 0)
			[result appendBytes: readBuffer length: bytesRead];
		else
		{
			// some sort of error occurred, log it, 
			// release result and break out of the loop
			NSLog(@"error: %@", [MySQLSocket socketError]);
			
			[result release];
			result	= nil;
			
			break;
		}
	}
	
	return result;
}


Anyone know how I can read more than 1448 bytes from the file descriptor? Is there some system variable I need to set? BTW, "readBuffer" above is 1MB so there's no question of it holding most queries in one shot.

Any help greatly appreciated.

Reply With Quote
  #2  
Old February 7th, 2011, 11:16 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,387 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 21 h 39 m 3 sec
Reputation Power: 4080
Your logic appears flawed. What is readBufferLength? A constant defined somewhere?
Code:
while (bytesRead == readBufferLength) {
       bytesRead = read(socketFD, readBuffer, readBufferLength);

One of the things you have to understand about the read() call is that it returns the number of bytes actually read. You may request readBufferLength bytes to be read in, but the function is allowed to return any number of bytes from 0 up to readBufferLength bytes. Consider that you request 1000 bytes, but it only has 500 bytes to return to you because that's what the query returned. Or, your query may have 1000 bytes in the result set, but the network stack chooses to return the data to you in two 500 byte packets. Hence, your while loop logic is wrong. It should be:
Code:
while (bytesRead > 0) {
 ...
}
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Last edited by Scorpions4ever : February 7th, 2011 at 11:18 AM.

Reply With Quote
  #3  
Old September 1st, 2011, 04:32 PM
miky miky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 44 miky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 20 m 45 sec
Reputation Power: 10
Quote:
Originally Posted by ktoz
Hi

I'm writing a native MySQL connection class in Objective C and have it working nicely so long as the App using the class and the MySQL server are on the same machine. If the MySQL database is on a remote server, when I read data from the BSD socket file descriptor, it maxes out at 1448 bytes. Queries whose results are smaller than 1448 bytes execute fine, but above that, and I don't know how to retreive all the expected data. Here's how I'm reading the socket

Anyone know how I can read more than 1448 bytes from the file descriptor? Is there some system variable I need to set? BTW, "readBuffer" above is 1MB so there's no question of it holding most queries in one shot.

Any help greatly appreciated.


Hello I'm a network guy so your question about these 1448 bytes shocked me very quickly.
1448 = 1500 - 20 (ip) - 20 (tcp) - 12 (???)
Headers of ip and tcp are 20 bytes long, the 12 other bytes might be made of mysql header (I read that it's 4 bytes) and 8 bytes for something else

What it means is that you might have 1448 bytes of data in each networking packet.
When you say "on the same machine" I think you use the loopback interface (127.0.0.1) to send your data. On my system its mtu is 33200, so there are no problems for these 1500 bytes. But what if you tried to use the ip address of your network card ? I wouldn't be surprised if you had the same behavior that you saw when dealing with a remote machine.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > Only receiving max of 1448 bytes on socket reads

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap