Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
104 views
in Technique[技术] by (71.8m points)

c - accept4 blocks though SOCK_NONBLOCK is set

I'm trying to accept a socket non-blockingly:

accept4(s, (struct sockaddr *) &peerAddress, &len,SOCK_NONBLOCK);

where as s is a fd, peerAddres is an address, and len, is its length. I wish that accept won't block the thread. Though, once I debug, the process is stuck at this line, while no connection is pending. What is my mistake?

question from:https://stackoverflow.com/questions/65625778/accept4-blocks-though-sock-nonblock-is-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SOCK_NONBLOCK just sets the newly accepted socket to non-blocking. It does not make accept itself non-blocking. For this one would need to set the listen socket non-blocking before calling accept.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...