#ifdef __MINGW32__
#include <winsock2.h>
#else
+#ifdef USE_POLL
+#include <poll.h>
+#else
#include <sys/select.h>
#endif
+#endif
void tw_free_request(struct tw_http_request* req) {
if(req->method != NULL) free(req->method);
char buffer[512];
char cbuf[2];
int phase = 0;
+
+#ifdef USE_POLL
+ struct pollfd pollfds[1];
+ pollfds[0].fd = sock;
+ pollfds[0].events = POLLIN | POLLPRI;
+#else
fd_set fds;
+#endif
bool bad = false;
int nl = 0;
while(1) {
+#ifndef USE_POLL
FD_ZERO(&fds);
FD_SET(sock, &fds);
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
+#endif
#ifndef NO_SSL
if(ssl == NULL || !SSL_has_pending(ssl)) {
#endif
+#ifdef USE_POLL
+ int n = poll(pollfds, 1, 5000);
+#else
#ifdef __HAIKU__
- int n = select(32, &fds, NULL, NULL, &tv);
+ int n = select(32, &fds, NULL, NULL, &tv);
#else
int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
+#endif
#endif
if(n <= 0) {
cm_log("HTTP", "Timeout, disconncting");
#include "strptime.h"
#else
+#ifdef USE_POLL
+#include <poll.h>
+#else
#include <sys/select.h>
+#endif
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
extern struct tw_config config;
extern char tw_server[];
-fd_set fdset;
int sockcount = 0;
SOCKADDR addresses[MAX_PORTS];
#endif
void tw_server_loop(void) {
- struct timeval tv;
int i;
#if defined(__MINGW32__) || defined(__HAIKU__)
struct thread_entry threads[2048];
for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) {
threads[i].used = false;
}
+#endif
+#ifdef USE_POLL
+ struct pollfd pollfds[sockcount];
+ for(i = 0; i < sockcount; i++) {
+ pollfds[i].fd = sockets[i];
+ pollfds[i].events = POLLIN | POLLPRI;
+ }
+#else
+ fd_set fdset;
+ struct timeval tv;
#endif
while(1) {
- FD_ZERO(&fdset);
- for(i = 0; i < sockcount; i++) {
- FD_SET(sockets[i], &fdset);
- }
- tv.tv_sec = 1;
- tv.tv_usec = 0;
+#ifdef USE_POLL
+ int ret = poll(pollfds, sockcount, 1000);
+#else
+ FD_ZERO(&fdset);
+ for(i = 0; i < sockcount; i++) {
+ FD_SET(sockets[i], &fdset);
+ }
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
#ifdef __HAIKU__
- int ret = select(32, &fdset, NULL, NULL, &tv);
+ int ret = select(32, &fdset, NULL, NULL, &tv);
#else
int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
+#endif
#endif
if(ret == -1) {
#ifndef __MINGW32__
/* connection */
int i;
for(i = 0; i < sockcount; i++) {
- if(FD_ISSET(sockets[i], &fdset)) {
+ bool cond;
+#ifdef USE_POLL
+ cond = pollfds[i].revents & POLLIN;
+#else
+ cond = FD_ISSET(sockets[i], &fdset);
+#endif
+ if(cond) {
SOCKADDR claddr;
int clen = sizeof(claddr);
int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen);