Mercurial > libavformat.hg
comparison os_support.c @ 1797:20c8dfd3ee84 libavformat
poll() emulation for BeOS, and maybe MinGW.
| author | mmu_man |
|---|---|
| date | Thu, 15 Feb 2007 07:44:10 +0000 |
| parents | 65b7b3ff4ed7 |
| children | d1e61f4d02cd |
comparison
equal
deleted
inserted
replaced
| 1796:29962f054bd0 | 1797:20c8dfd3ee84 |
|---|---|
| 33 #include <unistd.h> | 33 #include <unistd.h> |
| 34 #include <fcntl.h> | 34 #include <fcntl.h> |
| 35 #include <sys/time.h> | 35 #include <sys/time.h> |
| 36 #endif | 36 #endif |
| 37 #include <time.h> | 37 #include <time.h> |
| 38 #ifndef HAVE_SYS_POLL_H | |
| 39 #include <sys/select.h> | |
| 40 #endif | |
| 38 | 41 |
| 39 /** | 42 /** |
| 40 * gets the current time in micro seconds. | 43 * gets the current time in micro seconds. |
| 41 */ | 44 */ |
| 42 int64_t av_gettime(void) | 45 int64_t av_gettime(void) |
| 92 add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; | 95 add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; |
| 93 | 96 |
| 94 return 1; | 97 return 1; |
| 95 } | 98 } |
| 96 #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */ | 99 #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */ |
| 100 | |
| 101 #ifndef HAVE_SYS_POLL_H | |
| 102 int poll(struct pollfd *fds, nfds_t numfds, int timeout) | |
| 103 { | |
| 104 fd_set read_set; | |
| 105 fd_set write_set; | |
| 106 fd_set exception_set; | |
| 107 nfds_t i; | |
| 108 int n; | |
| 109 int rc; | |
| 110 | |
| 111 FD_ZERO(&read_set); | |
| 112 FD_ZERO(&write_set); | |
| 113 FD_ZERO(&exception_set); | |
| 114 | |
| 115 n = -1; | |
| 116 for(i = 0; i < numfds; i++) { | |
| 117 if (fds[i].fd < 0) | |
| 118 continue; | |
| 119 if (fds[i].fd >= FD_SETSIZE) { | |
| 120 errno = EINVAL; | |
| 121 return -1; | |
| 122 } | |
| 123 | |
| 124 if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set); | |
| 125 if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); | |
| 126 if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set); | |
| 127 | |
| 128 if (fds[i].fd > n) | |
| 129 n = fds[i].fd; | |
| 130 }; | |
| 131 | |
| 132 if (n == -1) | |
| 133 /* Hey!? Nothing to poll, in fact!!! */ | |
| 134 return 0; | |
| 135 | |
| 136 if (timeout < 0) | |
| 137 rc = select(n+1, &read_set, &write_set, &exception_set, NULL); | |
| 138 else { | |
| 139 struct timeval tv; | |
| 140 | |
| 141 tv.tv_sec = timeout / 1000; | |
| 142 tv.tv_usec = 1000 * (timeout % 1000); | |
| 143 rc = select(n+1, &read_set, &write_set, &exception_set, &tv); | |
| 144 }; | |
| 145 | |
| 146 if (rc < 0) | |
| 147 return rc; | |
| 148 | |
| 149 for(i = 0; i < (nfds_t) n; i++) { | |
| 150 fds[i].revents = 0; | |
| 151 | |
| 152 if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN; | |
| 153 if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT; | |
| 154 if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR; | |
| 155 }; | |
| 156 | |
| 157 return rc; | |
| 158 } | |
| 159 | |
| 160 | |
| 161 #endif /* HAVE_SYS_POLL_H */ | |
| 162 |
