int read_wait(char *buf, size_t size, int sec)
int main() { char buf[80] = {0x00,}; int n; if ((n = read_wait(buf, 80, 5)) < 0) printf("Time out\n"); } else { printf("%s\n", buf); } }
#include <sys/select.h> #include <sys/types.h> #include <unistd.h> int read_wait(char *buf, size_t size, int sec) { fd_set rfds; struct timeval tv; int n, retval; FD_ZERO(&rfds); FD_SET(0, &rfds); tv.tv_sec = sec; tv.tv_usec = 0; retval = select (1, &rfds, NULL, NULL, &tv); if (retval) { n = read(0, buf, size); return n; } else { return -1; } }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
설명
사용방법
코드
변경사항
Recent Posts
Archive Posts
Tags