Socket IO 不正常 - Linux

By Frederic
at 2011-09-15T13:57
at 2011-09-15T13:57
Table of Contents
小弟有個 socket 程式在收封包時會卡住的問題,想請問大家,
程式片段 ==>
01: FD_ZERO(&readList);
02: FD_SET(udpSd, &readList);
03:
04: rc = select(maxfd1, &readList, NULL, NULL, wait_time, 0);
05: if (rc > 0) {
06: if (FD_ISSET(udpSd, &readList))
07: {
08: cnt = recvfrom(udpSd, udpBuf, SZ_UDP_BUF, 0, &from_addr, &from_len);
09: if (cnt > 0) {
10: .....
11: }
12: }
13: ...
14: }
此片段是某個 thread 會執行到的一段程式碼。
在執行時會卡在第8行,無法從 recvfrom 回來。
雖然在第8行,給 recvfrom 的 flag 是 0,表示是 blocked 的 socket,
然透過第4行的 select() 叫用,
應該是不會讓 recvfrom 因收不到 data 而卡住才對。
請教大家,發生 recvfrom 卡住的狀況其可能原因為何呢 ?
----
ps: 試過第8行的 flag 指定為 nonblocked 的話,就不會卡住,
但小弟想追查為何會卡住。
----
--
程式片段 ==>
01: FD_ZERO(&readList);
02: FD_SET(udpSd, &readList);
03:
04: rc = select(maxfd1, &readList, NULL, NULL, wait_time, 0);
05: if (rc > 0) {
06: if (FD_ISSET(udpSd, &readList))
07: {
08: cnt = recvfrom(udpSd, udpBuf, SZ_UDP_BUF, 0, &from_addr, &from_len);
09: if (cnt > 0) {
10: .....
11: }
12: }
13: ...
14: }
此片段是某個 thread 會執行到的一段程式碼。
在執行時會卡在第8行,無法從 recvfrom 回來。
雖然在第8行,給 recvfrom 的 flag 是 0,表示是 blocked 的 socket,
然透過第4行的 select() 叫用,
應該是不會讓 recvfrom 因收不到 data 而卡住才對。
請教大家,發生 recvfrom 卡住的狀況其可能原因為何呢 ?
----
ps: 試過第8行的 flag 指定為 nonblocked 的話,就不會卡住,
但小弟想追查為何會卡住。
----
--
Tags:
Linux
All Comments

By Joe
at 2011-09-19T07:21
at 2011-09-19T07:21

By Suhail Hany
at 2011-09-23T06:42
at 2011-09-23T06:42

By Michael
at 2011-09-28T01:50
at 2011-09-28T01:50

By Yuri
at 2011-09-28T06:50
at 2011-09-28T06:50

By Megan
at 2011-09-29T05:55
at 2011-09-29T05:55

By Delia
at 2011-10-02T13:29
at 2011-10-02T13:29

By Ursula
at 2011-10-05T03:52
at 2011-10-05T03:52

By Anthony
at 2011-10-08T00:28
at 2011-10-08T00:28

By Irma
at 2011-10-08T15:02
at 2011-10-08T15:02

By Madame
at 2011-10-10T15:55
at 2011-10-10T15:55

By Ina
at 2011-10-11T16:07
at 2011-10-11T16:07

By Tristan Cohan
at 2011-10-13T13:24
at 2011-10-13T13:24

By Genevieve
at 2011-10-17T06:33
at 2011-10-17T06:33

By Hedwig
at 2011-10-21T09:03
at 2011-10-21T09:03

By Cara
at 2011-10-25T07:21
at 2011-10-25T07:21

By Olivia
at 2011-10-27T12:15
at 2011-10-27T12:15

By Susan
at 2011-10-30T21:48
at 2011-10-30T21:48

By Isabella
at 2011-11-02T06:18
at 2011-11-02T06:18

By Eartha
at 2011-11-03T10:08
at 2011-11-03T10:08

By Agatha
at 2011-11-07T17:57
at 2011-11-07T17:57

By Olga
at 2011-11-10T14:57
at 2011-11-10T14:57

By Jack
at 2011-11-14T15:23
at 2011-11-14T15:23

By Hedwig
at 2011-11-14T23:38
at 2011-11-14T23:38

By Delia
at 2011-11-16T22:59
at 2011-11-16T22:59

By Tracy
at 2011-11-18T09:16
at 2011-11-18T09:16

By Mia
at 2011-11-18T15:12
at 2011-11-18T15:12

By Steve
at 2011-11-21T22:07
at 2011-11-21T22:07

By Franklin
at 2011-11-22T23:45
at 2011-11-22T23:45

By Oliver
at 2011-11-23T01:07
at 2011-11-23T01:07

By Hardy
at 2011-11-23T22:50
at 2011-11-23T22:50

By Ida
at 2011-11-24T23:47
at 2011-11-24T23:47

By Dinah
at 2011-11-29T11:42
at 2011-11-29T11:42

By Jessica
at 2011-11-30T03:32
at 2011-11-30T03:32

By Brianna
at 2011-12-03T14:16
at 2011-12-03T14:16

By Robert
at 2011-12-06T07:45
at 2011-12-06T07:45

By Carolina Franco
at 2011-12-09T18:50
at 2011-12-09T18:50

By Bennie
at 2011-12-13T05:40
at 2011-12-13T05:40
Related Posts
神奇的回收筒...

By Bethany
at 2011-09-14T21:11
at 2011-09-14T21:11
請教一下kvm如何切換主機

By Heather
at 2011-09-14T21:07
at 2011-09-14T21:07
CentOS 安裝問題

By Tristan Cohan
at 2011-09-14T18:28
at 2011-09-14T18:28
Win7/XP iSCSI initiator抓不到Unbuntu 11.04的iSCSI Target

By Zenobia
at 2011-09-14T18:19
at 2011-09-14T18:19
在文字介面下載google doc或是skydrive的檔案??

By Michael
at 2011-09-14T15:38
at 2011-09-14T15:38