Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix socket, SOCK_SEQPACKET vs SOCK_DGRAM

Tags:

c

unix

It seems there's atleast 3 different local/unix socket types (AF_UNIX) , SOCK_STREAM, SOCK_DGRAM and SOCK_SEQPACKET.

While I know that a SOCK_STREAM gives you a bi-directional byte stream, like TCP or a bidirectional pipe, and the other two gives you a messge/packet API, what's the difference between a unix socket of SOCK_DGRAM and SOCK_SEQPACKET ?

As these are local only, I can't think of a good reason someone would implement SOCK_DGRAM in a manner it could reorder packets.

Also, does SOCK_DGRAM/SOCK_SEQPACKET employ flow control, or can messages be dropped in case of slow readers ?

like image 687
user1255770 Avatar asked Apr 11 '12 10:04

user1255770


People also ask

What is socket Sock_dgram?

SOCK_DGRAM. Provides datagrams, which are connectionless messages of a fixed maximum length. This type of socket is generally used for short messages, such as a name server or time server, because the order and reliability of message delivery is not guaranteed.

What is Sock_seqpacket?

SOCK_SEQPACKET, for a connection-oriented socket that preserves message boundaries and delivers messages in the order that they were sent.” The standard permits that you get reordered packets with SOCK_DGRAM. (In other words, if an OS hands them to you in order, that is an implementation-specific feature.

What is socket Sock_stream?

SOCK_STREAM means that it is a TCP socket. SOCK_DGRAM means that it is a UDP socket. These are used 99% of the time.

What is Af_unix socket?

The AF_UNIX (also known as AF_LOCAL) socket family is used to communicate between processes on the same machine efficiently. Traditionally, UNIX domain sockets can be either unnamed, or bound to a filesystem pathname (marked as being of type socket).


Video Answer


1 Answers

Here is a good article on the intended use case for SOCK_SEQPACKET, the fact that it's not really available in the IP protocol families, and how you can get the same thing with existing TCP semantics:

http://urchin.earth.li/~twic/Sequenced_Packets_Over_Ordinary_TCP.html

Note that SOCK_SEQPACKET is much closer in behavior to SOCK_STREAM than to SOCK_DGRAM.

Citing from the referenced website:

The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type, and is also connection-oriented. The only difference between these types is that record boundaries are maintained using the SOCK_SEQPACKET type. A record can be sent using one or more output operations and received using one or more input operations, but a single operation never transfers parts of more than one record. Record boundaries are visible to the receiver via the MSG_EOR flag in the received message flags returned by the recvmsg() function. It is protocol-specific whether a maximum record size is imposed.

like image 175
R.. GitHub STOP HELPING ICE Avatar answered Oct 09 '22 04:10

R.. GitHub STOP HELPING ICE