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
545 views
in Technique[技术] by (71.8m points)

c - How to make a file descriptor blocking?

Given an arbitrary file descriptor, can I make it blocking if it is non-blocking? If so, how?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Its been a while since I played with C, but you could use the fcntl() function to change the flags of a file descriptor:

#include <unistd.h>
#include <fcntl.h>

// Save the existing flags

saved_flags = fcntl(fd, F_GETFL);

// Set the new flags with O_NONBLOCK masked out

fcntl(fd, F_SETFL, saved_flags & ~O_NONBLOCK);

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

...