View Full Version : How to change the max message size that a socket can send?
vonaldinjo
05-10-2003, 12:24 PM
When I use sendto() to send messages, i get the error "message too long"? How can I find out the maximum possible size? Can I change it?
What is meant by sending message atomically? Does all sockets do this "sending message atomically"? Message size is associated with that? Can I change it?
When I use sendto() to send messages, i get the error "message too long"? How can I find out the maximum possible size? Can I change it?
What is meant by sending message atomically? Does all sockets do this "sending message atomically"? Message size is associated with that? Can I change it?
The error you got is EMSGSIZE, which is what you have written: The socket requires the message be sent atomically and the size of the message made this impossible.
If you are using raw sockets, the most probable cause is the MTU in the route to the destination is smaller than the packet size, and you are using the DF option.
The same will most probably happen with UDP datagrams. A UDP datagram must be put into an IP packet (plus the UDP header), if the Don't Fragment option is set in the IP packet, and the MTU for the destination is not big enough to allow transit of these packets, then the packet will be rejected in its path (with an ICMP response). I guess that, if the MTU has already been discovered, and the message is bigger than that, sendto() will automatically return the error. I'm just guessing here.
About changing the size... well, if it's due to the MTU in the path to the destination, you won't have a way to change it. Maybe you could disable the DF option in the IP packets, so the packets will be allowed to be fragmented on-route, but I don't know if that's possible. You should take a look at the setsockopt()/getsockopt() with IP_OPTIONS parameter, maybe you can change it from there.
That's all that comes to my mind right now...
What is meant by sending message atomically? Does all sockets do this "sending message atomically"? Message size is associated with that? Can I change it?
OK, I forgot to answer this one:
TCP/IP is a stack of many protocols. They are (somehow) layered one on top of the other. For example, TCP is layered on top of IP, so it uses IP's "services" for performing its own activities to provide services to upper layers.
UDP is a datagram oriented protocol (as opposed to stream-oriented protocols). It allows you to send messages that have boundaries, you will receive the messages complete because it will make sure that the information is delivered as it was sent (for example, no errors in transmission of a single datagram). However, it doesn't provide for delivery ensurance (you might get the message or you might not), message reordering (you can get the messages in a different order than they were sent), and duplicates-droping (you send one datagram, it might arrive many times to the recipient).
The interesting thing about UDP is the datagram concept. It is an atomic unit. It means that it will not be divided into parts or something. So you will get the whole package or not. This is what UDP must ensure to the upper layers: Atomic delivery of the datagrams.
Other protocols in the stack (for example, TCP) don't have this problem (they have bigger ones). In TCP there is no such atomic unit concept. If you send "ABCDEFGH" the recipient might get "A" then "BCDE" then "FGH", for example. So, there are no message boundaries.
So, basically, TCP has no sending message atomically feature. However, when sending information using TCP, TCP will break your information into small packets and then ask IP to send them to the destination. And if TCP thinks necessary, the DF option in the IP packet could be "turned on" so the packet will be delivered atomically...
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.