unix-domain socket descriptor 請益 - Linux
By Poppy
at 2019-09-24T18:04
at 2019-09-24T18:04
Table of Contents
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?
有沒有比較直觀的理解?
謝謝
--
裡面講解在同一個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?
有沒有比較直觀的理解?
謝謝
--
Tags:
Linux
All Comments
By Regina
at 2019-09-27T11:29
at 2019-09-27T11:29
By Leila
at 2019-09-29T19:32
at 2019-09-29T19:32
By Ethan
at 2019-10-01T02:35
at 2019-10-01T02:35
By Madame
at 2019-10-05T13:51
at 2019-10-05T13:51
By Hedwig
at 2019-10-10T11:18
at 2019-10-10T11:18
By Annie
at 2019-10-13T11:17
at 2019-10-13T11:17
By Andy
at 2019-10-16T17:24
at 2019-10-16T17:24
By Valerie
at 2019-10-17T14:42
at 2019-10-17T14:42
By Dinah
at 2019-10-21T08:20
at 2019-10-21T08:20
By Liam
at 2019-10-23T22:49
at 2019-10-23T22:49
By Ophelia
at 2019-10-24T03:09
at 2019-10-24T03:09
By Eden
at 2019-10-28T05:04
at 2019-10-28T05:04
By Joseph
at 2019-10-30T11:25
at 2019-10-30T11:25
By Selena
at 2019-11-04T09:05
at 2019-11-04T09:05
Related Posts
ubuntu 16.04外接螢幕內縮(無法全屏)
By Rebecca
at 2019-09-23T13:59
at 2019-09-23T13:59
Ubuntu16.04滑鼠右鍵在桌面失靈
By Oscar
at 2019-09-22T17:21
at 2019-09-22T17:21
Linux系統上看PPT(PowerPoint)
By Carol
at 2019-09-21T14:43
at 2019-09-21T14:43
想在raspberry pi 架設minecraft 伺服器
By Robert
at 2019-09-20T18:37
at 2019-09-20T18:37
awk查詢access.log問題
By Quintina
at 2019-09-20T17:33
at 2019-09-20T17:33