- 論壇徽章:
- 1
|
原帖由 yjh777 于 2009-6-2 21:45 發(fā)表 ![]()
不會(huì),
一般寫基于AF_LOCAL的服務(wù)程序,bind前先unlink那個(gè)文件,來(lái)保證bind成功。
可以看看《UNIX環(huán)境高級(jí)編程》和《UNIX網(wǎng)絡(luò)編程》里的介紹
接一下
17.3.1. Naming UNIX Domain Sockets
……
On Linux 2.4.22 and Solaris 9, the sockaddr_un structure is defined in the header <sys/un.h> as follows:
struct sockaddr_un {
sa_family_t sun_family; /* AF_UNIX */
char sun_path[108]; /* pathname */
};
On FreeBSD 5.2.1 and Mac OS X 10.3, however, the sockaddr_un structure is defined as
struct sockaddr_un {
unsigned char sun_len; /* length including null */
sa_family_t sun_family; /* AF_UNIX */
char sun_path[104]; /* pathname */
};
The sun_path member of the sockaddr_un structure contains a pathname. When we bind an address to a UNIX domain socket, the system creates a file of type S_IFSOCK with the same name.
This file exists only as a means of advertising the socket name to clients. The file can't be opened or otherwise used for communication by applications.
If the file already exists when we try to bind the same address, the bind request will fail. When we close the socket, this file is not automatically removed, so we need to make sure that we unlink it before our application exits. |
|