#include "portab.h"
-static char UNUSED id[] = "$Id: io.c,v 1.3 2005/07/12 20:44:13 fw Exp $";
+static char UNUSED id[] = "$Id: io.c,v 1.10 2005/08/30 13:38:16 fw Exp $";
#include <assert.h>
#include <stdlib.h>
#endif
#endif
+static bool library_initialized;
#ifdef IO_USE_EPOLL
#include <sys/epoll.h>
bool
io_library_init(unsigned int eventsize)
{
+ bool ret;
#ifdef IO_USE_EPOLL
int ecreate_hint = (int)eventsize;
if (ecreate_hint <= 0)
ecreate_hint = 128;
#endif
+ if (library_initialized)
+ return true;
+
#ifdef IO_USE_SELECT
#ifdef FD_SETSIZE
if (eventsize >= FD_SETSIZE)
#ifdef IO_USE_EPOLL
io_masterfd = epoll_create(ecreate_hint);
Log(LOG_INFO,
- "io subsystem: using epoll (hint size %d), initial io_event maxfd: %u, io_masterfd %d",
+ "IO subsystem: epoll (hint size %d, initial maxfd %u, masterfd %d).",
ecreate_hint, eventsize, io_masterfd);
- return io_masterfd >= 0;
+ ret = io_masterfd >= 0;
+ if (ret) library_initialized = true;
+
+ return ret;
#endif
#ifdef IO_USE_SELECT
- Log(LOG_INFO, "io subsystem: using select, initial io_event maxfd: %u",
+ Log(LOG_INFO, "IO subsystem: select (initial maxfd %u).",
eventsize);
FD_ZERO(&readers);
FD_ZERO(&writers);
#ifdef FD_SETSIZE
if (Conf_MaxConnections >= FD_SETSIZE) {
Log(LOG_WARNING,
- "Conf_MaxConnections (%d) exceeds limit (%u), changed Conf_MaxConnections to %u",
+ "MaxConnections (%d) exceeds limit (%u), changed MaxConnections to %u.",
Conf_MaxConnections, FD_SETSIZE, FD_SETSIZE - 1);
Conf_MaxConnections = FD_SETSIZE - 1;
}
#else
Log(LOG_WARNING,
- "FD_SETSIZE undefined, don't know how many descriptors select() can handle on your platform");
-#endif
+ "FD_SETSIZE undefined, don't know how many descriptors select() can handle on your platform ...");
+#endif /* FD_SETSIZE */
+ library_initialized = true;
return true;
-#endif
+#endif /* SELECT */
#ifdef IO_USE_KQUEUE
io_masterfd = kqueue();
Log(LOG_INFO,
- "io subsystem: using kqueue, initial io_event maxfd: %u, io_masterfd %d",
+ "IO subsystem: kqueue (initial maxfd %u, masterfd %d)",
eventsize, io_masterfd);
- return io_masterfd >= 0;
+ ret = io_masterfd >= 0;
+ if (ret) library_initialized = true;
+
+ return ret;
#endif
}
#ifdef IO_USE_KQUEUE
array_free(&io_evcache);
#endif
+ library_initialized = false;
}
{
struct kevent kev;
short filter = 0;
- unsigned int len = array_length(&io_evcache, sizeof kev);
- bool ret;
+ size_t len = array_length(&io_evcache, sizeof kev);
if (what & IO_WANTREAD)
filter = EVFILT_READ;
filter |= EVFILT_WRITE;
if (len >= 100) {
- ret = io_event_kqueue_commit_cache();
- if (ret)
- array_trunc(&io_evcache);
+ (void)io_event_kqueue_commit_cache();
}
EV_SET(&kev, fd, filter, EV_ADD | EV_ENABLE, 0, 0, NULL);
{
int i, total = 0, ret;
struct kevent kev[100];
- struct kevents *newevents;
+ struct kevent *newevents;
struct timespec ts;
int newevents_len;
short type;
ts.tv_nsec = tv->tv_usec * 1000;
do {
- newevents_len = array_length(&io_evcache, sizeof (struct kevent));
+ newevents_len = (int) array_length(&io_evcache, sizeof (struct kevent));
newevents = (newevents_len > 0) ? array_start(&io_evcache) : NULL;
assert(newevents_len >= 0);
if (newevents_len < 0)
assert(newevents);
#endif
- ret = kevent(io_masterfd, newevents, newevents_len, kev, 100, &ts);
+ ret = kevent(io_masterfd, newevents, newevents_len, kev,
+ 100, &ts);
if ((newevents_len>0) && ret != -1)
array_trunc(&io_evcache);