[問題] unix-domain socket descriptor 請益
The Linux Programming Interface
裡面講解在同一個host 兩個processes用socket通訊,
Server:
.....略
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
bind(sfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un));
cfd = accept(sfd, NULL, NULL);
while ((numRead = read(cfd, buf, BUF_SIZE)) > 0)
Client:
connect(sfd, (struct sockaddr *) &addr,sizeof(struct sockaddr_un));
write(sfd, buf, numRead);
accept()會回傳cfd這個新的descriptor來跟client的sfd進行連線。
想請問為什麼server端的sfd不能同時listen跟read/write,一定要在產一個新的cfd?
有沒有比較直觀的理解?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.75.14.193 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1569319474.A.D12.html
※ 編輯: anoymouse (211.75.14.193 臺灣), 09/24/2019 18:06:42
→
09/24 18:46,
6年前
, 1F
09/24 18:46, 1F
→
09/24 18:46,
6年前
, 2F
09/24 18:46, 2F
噓
09/24 18:48,
6年前
, 3F
09/24 18:48, 3F
→
09/24 19:23,
6年前
, 4F
09/24 19:23, 4F
→
09/24 19:55,
6年前
, 5F
09/24 19:55, 5F
→
09/24 19:56,
6年前
, 6F
09/24 19:56, 6F
→
09/24 21:35,
6年前
, 7F
09/24 21:35, 7F
→
09/24 22:47,
6年前
, 8F
09/24 22:47, 8F
推
09/24 23:50,
6年前
, 9F
09/24 23:50, 9F
→
09/24 23:51,
6年前
, 10F
09/24 23:51, 10F
→
09/24 23:51,
6年前
, 11F
09/24 23:51, 11F
→
09/24 23:52,
6年前
, 12F
09/24 23:52, 12F
→
09/24 23:53,
6年前
, 13F
09/24 23:53, 13F
→
09/24 23:53,
6年前
, 14F
09/24 23:53, 14F
→
09/24 23:55,
6年前
, 15F
09/24 23:55, 15F
→
09/24 23:55,
6年前
, 16F
09/24 23:55, 16F
→
09/24 23:55,
6年前
, 17F
09/24 23:55, 17F
※ 編輯: anoymouse (61.230.163.114 臺灣), 09/25/2019 01:05:43
推
09/28 23:29,
6年前
, 18F
09/28 23:29, 18F
Linux 近期熱門文章
21
56
PTT數位生活區 即時熱門文章