这周我一直在学习 unix 套接字,我对来自客户端应用程序的 connect() 调用有疑问。
是 connect() 函数调用 BLOCKING。在服务器应用程序创建自己的套接字、将其绑定(bind)到同一地址并开始监听传入连接之前,它会阻塞吗?
在我的客户中,我拥有的是
printf(" abc %s\n", bind_path);
if((retval = connect(sh->sock_fd, (const struct sockaddr*)&sadr, sizeof(struct sockaddr_un))) == -1)
{
perror("123");
return SOCKET_ERROR;
}
return SOCKET_OK;
我得到的是,
ankit@ankit-ThinkPad-W530:~/Desktop/week2_3_tasks/ipc_socket_exercise$ ./user_application_proc2_client.out
**** Process 2 (Client) Started
**** Process 2 PID : 7106
/tmp/sock_10
**** Socket connected successfully with handle 3
abc /tmp/sock_10
123: No such file or directory
**** Error connnecting socket to address .. exiting
最佳答案
Is the connect() function call BLOCKING[?]
不适用于 UNIX 套接字。它可能会阻塞其他类型的套接字(例如 IP 套接字)。
Will it BLOCK till the server application creates its own socket, binds it to the same address and start listening for incoming connections?
没有。你自己看到了这个——你得到了一个“没有这样的文件或目录”的错误!显然它在返回该错误之前没有等待服务器。
关于c - Linux 套接字 (AF_UNIX) 连接 () 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38891599/