The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> BSD Help
|
Only receiving max of 1448 bytes on socket reads
Discuss Only receiving max of 1448 bytes on socket reads in the BSD Help forum on Dev Shed. Only receiving max of 1448 bytes on socket reads BSD Help forum discussing all BSD based operating systems including FreeBSD, OpenBSD, NetBSD, and more. BSD refers to the distribution of UNIX originally developed by the University of California at Berkeley.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 29th, 2011, 05:01 PM
|
|
|
|
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.
|

February 7th, 2011, 11:16 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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.
|

September 1st, 2011, 04:32 PM
|
|
Contributing User
|
|
Join Date: Oct 2003
Posts: 44
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|