15.4 Socket Functions


There are several differences and restrictions in the socket functions when using Unix domain sockets. We list the POSIX requirements when applicable , and note that not all implementations are currently at this level.

  1. The default file access permissions for a pathname created by bind should be 0777 (read, write, and execute by user , group , and other), modified by the current umask value.

  2. The pathname associated with a Unix domain socket should be an absolute pathname, not a relative pathname. The reason to avoid the latter is that its resolution depends on the current working directory of the caller. That is, if the server binds a relative pathname, then the client must be in the same directory as the server (or must know this directory) for the client's call to either connect or sendto to succeed.

    POSIX says that binding a relative pathname to a Unix domain socket gives unpredictable results.

  3. The pathname specified in a call to connect must be a pathname that is currently bound to an open Unix domain socket of the same type (stream or datagram). Errors occur if: (i) the pathname exists but is not a socket; (ii) the pathname exists and is a socket, but no open socket descriptor is associated with the pathname; or (iii) the pathname exists and is an open socket, but is of the wrong type (that is, a Unix domain stream socket cannot connect to a pathname associated with a Unix domain datagram socket, and vice versa).

  4. The permission testing associated with the connect of a Unix domain socket is the same as if open had been called for write-only access to the pathname.

  5. Unix domain stream sockets are similar to TCP sockets: They provide a byte stream interface to the process with no record boundaries.

  6. If a call to connect for a Unix domain stream socket finds that the listening socket's queue is full (Section 4.5), ECONNREFUSED is returned immediately. This differs from TCP: The TCP listener ignores an arriving SYN if the socket's queue is full, and the TCP connector retries by sending the SYN several times.

  7. Unix domain datagram sockets are similar to UDP sockets: They provide an unreliable datagram service that preserves record boundaries.

  8. Unlike UDP sockets, sending a datagram on an unbound Unix domain datagram socket does not bind a pathname to the socket. (Recall that sending a UDP datagram on an unbound UDP socket causes an ephemeral port to be bound to the socket.) This means the receiver of the datagram will be unable to send a reply unless the sender has bound a pathname to its socket. Similarly, unlike TCP and UDP, calling connect for a Unix domain datagram socket does not bind a pathname to the socket.



UNIX Network Programming Volume 1, Third Edition
Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition)
ISBN: 0131411551
EAN: 2147483647
Year: 2003
Pages: 441

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net