2009-05-27 10 views

cevap

11

bir süre geçti ben C ile oynanan, ancak bir dosya tanımlayıcısı bayrakları değiştirmek için fcntl() işlevini kullanabilirsiniz beri:

#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); 
+0

Evet, kabul edilen yöntem budur. ~ O_NONBLOCK ile fcntl yapmaya iyi cevap ve güzel, ters yaklaşım. :) – BobbyShaftoe

7

ben sadece O_NONBLOCK bayrak dönerse olmayan ayar beklenebilir dosya tanıtıcıyı varsayılan kipte, bloke eden varsayılan moda:

/* Makes the given file descriptor non-blocking. 
* Returns 1 on success, 0 on failure. 
*/ 
int make_blocking(int fd) 
{ 
    int flags; 

    flags = fcntl(fd, F_GETFL, 0); 
    if(flags == -1) /* Failed? */ 
    return 0; 
    /* Clear the blocking flag. */ 
    flags &= ~O_NONBLOCK; 
    return fcntl(fd, F_SETFL, flags) != -1; 
} 
İlgili konular