openslp/openslp.poll.diff

854 lines
31 KiB
Diff
Raw Normal View History

--- ./common/slp_dhcp.c.orig 2005-08-22 17:24:56.813080069 +0000
+++ ./common/slp_dhcp.c 2005-08-22 17:25:15.753392664 +0000
@@ -69,6 +69,9 @@
#include <bits/ioctls.h>
#include <sys/time.h>
#endif
+#ifdef HAVE_POLL
+#include <sys/poll.h>
+#endif
#include <stdlib.h>
#include <string.h>
@@ -166,7 +169,11 @@ static int dhcpSendRequest(int sockfd, v
ETIMEDOUT read timed out
=========================================================================*/
{
+#ifdef HAVE_POLL
+ struct pollfd writefd;
+#else
fd_set writefds;
+#endif
int xferbytes;
int flags = 0;
@@ -174,10 +181,17 @@ static int dhcpSendRequest(int sockfd, v
flags = MSG_NOSIGNAL;
#endif
+#ifdef HAVE_POLL
+ writefd.fd = sockfd;
+ writefd.events = POLLOUT;
+ writefd.revents = 0;
+ xferbytes = poll(&writefd, 1, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
FD_ZERO(&writefds);
FD_SET(sockfd, &writefds);
-
- if((xferbytes = select(sockfd + 1, 0, &writefds, 0, timeout)) > 0)
+ xferbytes = select(sockfd + 1, 0, &writefds, 0, timeout);
+#endif
+ if(xferbytes > 0)
{
if((xferbytes = sendto(sockfd, (char*)buf, (int)bufsz, flags,
peeraddr, sizeof(struct sockaddr_in))) <= 0)
@@ -214,12 +228,23 @@ static int dhcpRecvResponse(int sockfd,
=========================================================================*/
{
int xferbytes;
+#ifdef HAVE_POLL
+ struct pollfd readfd;
+#else
fd_set readfds;
+#endif
+#ifdef HAVE_POLL
+ readfd.fd = sockfd;
+ readfd.events = POLLIN;
+ readfd.revents = 0;
+ xferbytes = poll(&readfd, 1, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
-
- if((xferbytes = select(sockfd + 1, &readfds, 0 , 0, timeout)) > 0)
+ xferbytes = select(sockfd + 1, &readfds, 0 , 0, timeout);
+#endif
+ if(xferbytes > 0)
{
if((xferbytes = recvfrom(sockfd, (char*)buf, (int)bufsz, 0, 0, 0)) <= 0)
{
--- ./common/slp_network.c.orig 2005-08-22 17:24:56.814079927 +0000
+++ ./common/slp_network.c 2005-08-22 17:25:15.754392523 +0000
@@ -221,7 +221,11 @@ int SLPNetworkSendMessage(int sockfd,
/* ETIME read timed out */
/*=========================================================================*/
{
+#ifdef HAVE_POLL
+ struct pollfd writefd;
+#else
fd_set writefds;
+#endif
int xferbytes;
int flags = 0;
@@ -233,10 +237,17 @@ int SLPNetworkSendMessage(int sockfd,
while(buf->curpos < buf->end)
{
+#ifdef HAVE_POLL
+ writefd.fd = sockfd;
+ writefd.events = POLLOUT;
+ writefd.revents = 0;
+ xferbytes = poll(&writefd, 1, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
FD_ZERO(&writefds);
FD_SET(sockfd, &writefds);
xferbytes = select(sockfd + 1, 0, &writefds, 0, timeout);
+#endif
if(xferbytes > 0)
{
if(socktype == SOCK_DGRAM)
@@ -301,16 +312,27 @@ int SLPNetworkRecvMessage(int sockfd,
/*=========================================================================*/
{
int xferbytes, recvlen;
+#ifdef HAVE_POLL
+ struct pollfd readfd;
+#else
fd_set readfds;
+#endif
char peek[16];
int peeraddrlen = sizeof(struct sockaddr_in);
/*---------------------------------------------------------------*/
/* take a peek at the packet to get version and size information */
/*---------------------------------------------------------------*/
+#ifdef HAVE_POLL
+ readfd.fd = sockfd;
+ readfd.events = POLLIN;
+ readfd.revents = 0;
+ xferbytes = poll(&readfd, 1, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
xferbytes = select(sockfd + 1, &readfds, 0 , 0, timeout);
+#endif
if(xferbytes > 0)
{
if(socktype == SOCK_DGRAM)
@@ -371,9 +393,16 @@ int SLPNetworkRecvMessage(int sockfd,
{
while((*buf)->curpos < (*buf)->end)
{
+#ifdef HAVE_POLL
+ readfd.fd = sockfd;
+ readfd.events = POLLIN;
+ readfd.revents = 0;
+ xferbytes = poll(&readfd, 1, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
xferbytes = select(sockfd + 1, &readfds, 0 , 0, timeout);
+#endif
if(xferbytes > 0)
{
xferbytes = recv(sockfd,
--- ./common/slp_network.h.orig 2005-08-22 17:24:56.815079785 +0000
+++ ./common/slp_network.h 2005-08-22 17:25:15.754392523 +0000
@@ -72,6 +72,9 @@
#include <fcntl.h>
#include <errno.h>
#endif
+#ifdef HAVE_POLL
+#include <sys/poll.h>
+#endif
#include "slp_buffer.h"
#include "slp_property.h"
--- ./common/slp_xcast.c.orig 2005-08-22 17:24:56.815079785 +0000
+++ ./common/slp_xcast.c 2005-08-22 17:25:15.755392381 +0000
@@ -65,6 +65,9 @@
#include <fcntl.h>
#include <errno.h>
#endif
+#ifdef HAVE_POLL
+#include <sys/poll.h>
+#endif
#ifndef UNICAST_NOT_SUPPORTED
#include "../libslp/slp.h"
@@ -281,8 +284,12 @@ int SLPXcastRecvMessage(const SLPXcastSo
<20>* <20> <20>Zero on success, non-zero with errno set on failure.
<20>*========================================================================*/
{
+#ifdef HAVE_POLL
+ struct pollfd readfds[SLP_MAX_IFACES];
+#else
fd_set readfds;
int highfd;
+#endif
int i;
int readable;
size_t bytesread;
@@ -295,6 +302,15 @@ int SLPXcastRecvMessage(const SLPXcastSo
recvloop = 1;
while(recvloop)
{
+#ifdef HAVE_POLL
+ for (i=0; i<sockets->sock_count; i++)
+ {
+ readfds[i].fd = sockets->sock[i];
+ readfds[i].events = POLLIN;
+ readfds[i].revents = 0;
+ }
+ readable = poll(readfds, sockets->sock_count, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
/* Set the readfds */
FD_ZERO(&readfds);
highfd = 0;
@@ -309,12 +325,17 @@ int SLPXcastRecvMessage(const SLPXcastSo
/* Select */
readable = select(highfd + 1,&readfds,NULL,NULL,timeout);
+#endif
if(readable > 0)
{
/* Read the datagram */
for (i=0; i<sockets->sock_count; i++)
{
+#ifdef HAVE_POLL
+ if((readfds[i].revents & POLLIN) != 0)
+#else
if(FD_ISSET(sockets->sock[i],&readfds))
+#endif
{
/* Peek at the first 16 bytes of the header */
bytesread = recvfrom(sockets->sock[i],
--- ./configure.in.orig 2005-08-22 17:24:56.816079643 +0000
+++ ./configure.in 2005-08-22 17:25:15.756392239 +0000
@@ -170,7 +170,7 @@ AC_CHECK_LIB(resolv, inet_aton)
AC_CHECK_LIB(socket, main)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(m, main)
-AC_CHECK_FUNCS(ceil log10 strncasecmp strcasecmp )
+AC_CHECK_FUNCS(ceil log10 strncasecmp strcasecmp poll )
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ common/Makefile ])
AC_CONFIG_FILES([ libslpattr/Makefile ])
--- ./libslp/libslp_mdns.c.orig 2005-08-22 17:24:56.817079502 +0000
+++ ./libslp/libslp_mdns.c 2005-08-22 17:25:15.757392097 +0000
@@ -742,8 +742,12 @@ int SLPMDNSXcastRecvMessage(const SLPXca
* Zero on success, non-zero with errno set on failure.
*========================================================================*/
{
+#ifdef HAVE_POLL
+ struct pollfd readfds[SLP_MAX_IFACES * 2];
+#else
fd_set readfds;
int highfd;
+#endif
int i;
int readable;
size_t bytesread;
@@ -761,6 +765,21 @@ int SLPMDNSXcastRecvMessage(const SLPXca
recvloop = 1;
while(recvloop)
{
+#ifdef HAVE_POLL
+ for (i=0; i<sockets->sock_count; i++)
+ {
+ readfds[i].fd = sockets->sock[i];
+ readfds[i].events = POLLIN;
+ readfds[i].revents = 0;
+ }
+ for (i=0; i<mdnssockets->sock_count; i++)
+ {
+ readfds[i + sockets->sock_count].fd = mdnssockets->sock[i];
+ readfds[i + sockets->sock_count].events = POLLIN;
+ readfds[i + sockets->sock_count].revents = 0;
+ }
+ readable = poll(readfds, sockets->sock_count + mdnssockets->sock_count, timeout ? timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : -1);
+#else
/* Set the readfds */
FD_ZERO(&readfds);
highfd = 0;
@@ -779,12 +798,17 @@ int SLPMDNSXcastRecvMessage(const SLPXca
/* Select */
readable = select(highfd + 1,&readfds,NULL,NULL,timeout);
+#endif
if(readable > 0)
{
/* Read the datagram */
for (i=0; i<sockets->sock_count; i++)
{
+#ifdef HAVE_POLL
+ if((readfds[i].revents & POLLIN) != 0)
+#else
if(FD_ISSET(sockets->sock[i],&readfds))
+#endif
{
/* Peek at the first 16 bytes of the header */
bytesread = recvfrom(sockets->sock[i],
@@ -850,7 +874,11 @@ int SLPMDNSXcastRecvMessage(const SLPXca
}
for (i=0; i<mdnssockets->sock_count; i++)
{
+#ifdef HAVE_POLL
+ if((readfds[sockets->sock_count + i].revents & POLLIN) == 0)
+#else
if(!FD_ISSET(mdnssockets->sock[i],&readfds))
+#endif
continue;
*buf = SLPBufferRealloc(*buf, 8000);
(*buf)->curpos = (*buf)->start;
--- ./slpd/slpd_incoming.c.orig 2005-08-22 17:24:56.818079360 +0000
+++ ./slpd/slpd_incoming.c 2005-08-22 17:25:15.758391955 +0000
@@ -313,23 +313,20 @@ void IncomingSocketListen(SLPList* sockl
/*=========================================================================*/
void SLPDIncomingHandler(int* fdcount,
- fd_set* readfds,
- fd_set* writefds)
+ SLPD_fdset *fdset)
/* Handles all outgoing requests that are pending on the specified file */
/* discriptors */
/* */
-/* fdcount (IN/OUT) number of file descriptors marked in fd_sets */
+/* fdcount (IN/OUT) number of file descriptors marked in fdset */
/* */
-/* readfds (IN) file descriptors with pending read IO */
-/* */
-/* writefds (IN) file descriptors with pending read IO */
+/* fdset (IN) file descriptors with pending read/write IO */
/*=========================================================================*/
{
SLPDSocket* sock;
sock = (SLPDSocket*) G_IncomingSocketList.head;
while (sock && *fdcount)
{
- if (FD_ISSET(sock->fd,readfds))
+ if (SLPD_fdset_readok(fdset, sock))
{
switch (sock->state)
{
@@ -354,7 +351,7 @@ void SLPDIncomingHandler(int* fdcount,
*fdcount = *fdcount - 1;
}
- else if (FD_ISSET(sock->fd,writefds))
+ else if (SLPD_fdset_writeok(fdset, sock))
{
switch (sock->state)
{
--- ./slpd/slpd_incoming.h.orig 2005-08-22 17:24:56.818079360 +0000
+++ ./slpd/slpd_incoming.h 2005-08-22 17:25:15.758391955 +0000
@@ -57,6 +57,7 @@
/* common code includes */
/*=========================================================================*/
#include "slp_linkedlist.h"
+#include "slpd_socket.h"
/*=========================================================================*/
@@ -74,16 +75,13 @@ void SLPDIncomingAge(time_t seconds);
/*=========================================================================*/
void SLPDIncomingHandler(int* fdcount,
- fd_set* readfds,
- fd_set* writefds);
+ SLPD_fdset *fdset);
/* Handles all outgoing requests that are pending on the specified file */
/* discriptors */
/* */
-/* fdcount (IN/OUT) number of file descriptors marked in fd_sets */
+/* fdcount (IN/OUT) number of file descriptors marked in fdset */
/* */
-/* readfds (IN) file descriptors with pending read IO */
-/* */
-/* writefds (IN) file descriptors with pending read IO */
+/* fdset (IN) file descriptors with pending read/write IO */
/*=========================================================================*/
--- ./slpd/slpd_main.c.orig 2005-08-22 17:29:17.587046733 +0000
+++ ./slpd/slpd_main.c 2005-08-22 17:28:13.043216959 +0000
@@ -82,12 +82,11 @@ int G_SIGINT; /* Signal being used for
#endif
/*==========================================================================*/
+#ifdef HAVE_POLL
/*-------------------------------------------------------------------------*/
-void LoadFdSets(SLPList* socklist,
- int* highfd,
- fd_set* readfds,
- fd_set* writefds)
+void LoadFdSets(SLPList* socklist,
+ SLPD_fdset *fdset)
/*-------------------------------------------------------------------------*/
{
SLPDSocket* sock = 0;
@@ -96,9 +95,87 @@ void LoadFdSets(SLPList* socklist,
sock = (SLPDSocket*)socklist->head;
while(sock)
{
- if(sock->fd > *highfd)
+ if (fdset->used == fdset->allocated) {
+ fdset->allocated += 32;
+ if (fdset->used)
+ fdset->fds = xrealloc(fdset->fds, fdset->allocated * sizeof(*fdset->fds));
+ else
+ fdset->fds = xmalloc(fdset->allocated * sizeof(*fdset->fds));
+ if (!fdset->fds)
+ SLPDFatal("No memory for fdset.\n");
+ }
+ fdset->fds[fdset->used].fd = sock->fd;
+ fdset->fds[fdset->used].events = 0;
+ fdset->fds[fdset->used].revents = 0;
+ switch(sock->state)
+ {
+ case DATAGRAM_UNICAST:
+ case DATAGRAM_MULTICAST:
+ case DATAGRAM_BROADCAST:
+ fdset->fds[fdset->used].events |= POLLIN;
+ break;
+
+ case SOCKET_LISTEN:
+ if(socklist->count < SLPD_MAX_SOCKETS)
+ {
+ fdset->fds[fdset->used].events |= POLLIN;
+ }
+ break;
+
+ case STREAM_READ:
+ case STREAM_READ_FIRST:
+ fdset->fds[fdset->used].events |= POLLIN;
+ break;
+
+ case STREAM_WRITE:
+ case STREAM_WRITE_FIRST:
+ case STREAM_CONNECT_BLOCK:
+ fdset->fds[fdset->used].events |= POLLOUT;
+ break;
+
+ case SOCKET_CLOSE:
+ del = sock;
+ break;
+
+ default:
+ break;
+ }
+
+ if (fdset->fds[fdset->used].events)
{
- *highfd = sock->fd;
+ sock->fdsetnr = fdset->used++;
+ }
+ else
+ {
+ sock->fdsetnr = -1;
+ }
+
+ sock = (SLPDSocket*)sock->listitem.next;
+
+ if(del)
+ {
+ SLPDSocketFree((SLPDSocket*)SLPListUnlink(socklist,(SLPListItem*)del));
+ del = 0;
+ }
+ }
+}
+
+#else
+
+/*-------------------------------------------------------------------------*/
+void LoadFdSets(SLPList* socklist,
+ SLPD_fdset *fdset)
+/*-------------------------------------------------------------------------*/
+{
+ SLPDSocket* sock = 0;
+ SLPDSocket* del = 0;
+
+ sock = (SLPDSocket*)socklist->head;
+ while(sock)
+ {
+ if(sock->fd > fdset->highfd)
+ {
+ fdset->highfd = sock->fd;
}
switch(sock->state)
@@ -106,25 +183,25 @@ void LoadFdSets(SLPList* socklist,
case DATAGRAM_UNICAST:
case DATAGRAM_MULTICAST:
case DATAGRAM_BROADCAST:
- FD_SET(sock->fd,readfds);
+ FD_SET(sock->fd,&fdset->readfds);
break;
case SOCKET_LISTEN:
if(socklist->count < SLPD_MAX_SOCKETS)
{
- FD_SET(sock->fd,readfds);
+ FD_SET(sock->fd,&fdset->readfds);
}
break;
case STREAM_READ:
case STREAM_READ_FIRST:
- FD_SET(sock->fd,readfds);
+ FD_SET(sock->fd,&fdset->readfds);
break;
case STREAM_WRITE:
case STREAM_WRITE_FIRST:
case STREAM_CONNECT_BLOCK:
- FD_SET(sock->fd,writefds);
+ FD_SET(sock->fd,&fdset->writefds);
break;
case SOCKET_CLOSE:
@@ -145,17 +222,18 @@ void LoadFdSets(SLPList* socklist,
}
}
+#endif
+
/*------------------------------------------------------------------------*/
void HandleSigTerm()
/*------------------------------------------------------------------------*/
{
struct timeval timeout;
- fd_set readfds;
- fd_set writefds;
- int highfd = 0;
+ SLPD_fdset fdset;
int fdcount = 0;
+ SLPD_fdset_init(&fdset);
SLPDLog("****************************************\n");
SLPDLogTime();
SLPDLog("SLPD daemon shutting down\n");
@@ -179,16 +257,19 @@ void HandleSigTerm()
/* if possible wait until all outgoing socket are done and closed */
while(SLPDOutgoingDeinit(1))
{
- FD_ZERO(&writefds);
- FD_ZERO(&readfds);
- LoadFdSets(&G_OutgoingSocketList, &highfd, &readfds,&writefds);
- fdcount = select(highfd+1,&readfds,&writefds,0,&timeout);
+ SLPD_fdset_reset(&fdset);
+ LoadFdSets(&G_OutgoingSocketList, &fdset);
+#ifdef HAVE_POLL
+ fdcount = poll(fdset.fds, fdset.used, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
+#else
+ fdcount = select(fdset.highfd+1,&fdset.readfds,&fdset.writefds,0,&timeout);
+#endif
if(fdcount == 0)
{
break;
}
- SLPDOutgoingHandler(&fdcount,&readfds,&writefds);
+ SLPDOutgoingHandler(&fdcount,&fdset);
}
SLPDOutgoingDeinit(0);
@@ -491,11 +572,10 @@ int SetUpSignalHandlers()
int main(int argc, char* argv[])
/*=========================================================================*/
{
- fd_set readfds;
- fd_set writefds;
- int highfd;
+ SLPD_fdset fdset;
int fdcount = 0;
+ SLPD_fdset_init(&fdset);
reg_file_dir = strdup("/etc/slp.reg.d");
#ifdef DEBUG
@@ -616,14 +696,12 @@ int main(int argc, char* argv[])
/*--------------------------------------------------------*/
/* Load the fdsets up with all valid sockets in the list */
/*--------------------------------------------------------*/
- highfd = 0;
- FD_ZERO(&readfds);
- FD_ZERO(&writefds);
- LoadFdSets(&G_IncomingSocketList, &highfd, &readfds,&writefds);
- LoadFdSets(&G_OutgoingSocketList, &highfd, &readfds,&writefds);
+ SLPD_fdset_reset(&fdset);
+ LoadFdSets(&G_IncomingSocketList, &fdset);
+ LoadFdSets(&G_OutgoingSocketList, &fdset);
#ifdef ENABLE_MDNS_SLPD
- LoadFdSets(&G_MDNSSocketList, &highfd, &readfds,&writefds);
+ LoadFdSets(&G_MDNSSocketList, &fdset);
#endif
/*--------------------------------------------------*/
@@ -637,14 +715,18 @@ int main(int argc, char* argv[])
/*-------------*/
/* Main select */
/*-------------*/
- fdcount = select(highfd+1,&readfds,&writefds,0,0);
+#ifdef HAVE_POLL
+ fdcount = poll(fdset.fds, fdset.used, -1);
+#else
+ fdcount = select(fdset.highfd+1,&fdset.readfds,&fdset.writefds,0,0);
+#endif
if(fdcount > 0) /* fdcount will be < 0 when interrupted by a signal */
{
- SLPDIncomingHandler(&fdcount,&readfds,&writefds);
- SLPDOutgoingHandler(&fdcount,&readfds,&writefds);
+ SLPDIncomingHandler(&fdcount,&fdset);
+ SLPDOutgoingHandler(&fdcount,&fdset);
#ifdef ENABLE_MDNS_SLPD
- SLPDMDNSHandler(&fdcount,&readfds,&writefds);
+ SLPDMDNSHandler(&fdcount,&fdset);
#endif
}
--- ./slpd/slpd_mdns.c.orig 2005-08-22 17:24:56.821078934 +0000
+++ ./slpd/slpd_mdns.c 2005-08-22 17:25:15.761391529 +0000
@@ -207,23 +207,20 @@ int SLPDMDNSDeinit()
/*=========================================================================*/
void SLPDMDNSHandler(int* fdcount,
- fd_set* readfds,
- fd_set* writefds)
+ SLPD_fdset* fdset)
/* Handles all outgoing requests that are pending on the specified file */
/* discriptors */
/* */
-/* fdcount (IN/OUT) number of file descriptors marked in fd_sets */
+/* fdcount (IN/OUT) number of file descriptors marked in fdset */
/* */
-/* readfds (IN) file descriptors with pending read IO */
-/* */
-/* writefds (IN) file descriptors with pending read IO */
+/* fdset (IN) file descriptors with pending read/write IO */
/*=========================================================================*/
{
SLPDSocket* sock;
sock = (SLPDSocket*) G_MDNSSocketList.head;
while (sock && *fdcount)
{
- if (FD_ISSET(sock->fd,readfds))
+ if (SLPD_fdset_readok(fdset, sock))
{
switch (sock->state)
{
--- ./slpd/slpd_mdns.h.orig 2005-08-22 17:24:56.821078934 +0000
+++ ./slpd/slpd_mdns.h 2005-08-22 17:25:15.761391529 +0000
@@ -8,6 +8,7 @@
/*=========================================================================*/
#include "slp_linkedlist.h"
#include "slp_mdns.h"
+#include "slpd_socket.h"
/*=========================================================================*/
@@ -17,16 +18,13 @@ extern SLPList G_MDNSSocketList;
/*=========================================================================*/
void SLPDMDNSHandler(int* fdcount,
- fd_set* readfds,
- fd_set* writefds);
+ SLPD_fdset* fdset);
/* Handles all outgoing requests that are pending on the specified file */
/* discriptors */
/* */
-/* fdcount (IN/OUT) number of file descriptors marked in fd_sets */
+/* fdcount (IN/OUT) number of file descriptors marked in fdset */
/* */
-/* readfds (IN) file descriptors with pending read IO */
-/* */
-/* writefds (IN) file descriptors with pending read IO */
+/* fdset (IN) file descriptors with pending read/write IO */
/*=========================================================================*/
--- ./slpd/slpd_outgoing.c.orig 2005-08-22 17:24:56.822078792 +0000
+++ ./slpd/slpd_outgoing.c 2005-08-22 17:25:15.762391388 +0000
@@ -451,24 +451,21 @@ void SLPDOutgoingDatagramWrite(SLPDSocke
/*=========================================================================*/
void SLPDOutgoingHandler(int* fdcount,
- fd_set* readfds,
- fd_set* writefds)
+ SLPD_fdset* fdset)
/* Handles all outgoing requests that are pending on the specified file */
/* discriptors */
/* */
-/* fdcount (IN/OUT) number of file descriptors marked in fd_sets */
+/* fdcount (IN/OUT) number of file descriptors marked in fdset */
/* */
-/* readfds (IN) file descriptors with pending read IO */
-/* */
-/* writefds (IN) file descriptors with pending read IO */
+/* fdset (IN) file descriptors with pending read/write IO */
/*=========================================================================*/
{
SLPDSocket* sock;
sock = (SLPDSocket*)G_OutgoingSocketList.head;
while ( sock && *fdcount )
{
- if ( FD_ISSET(sock->fd,readfds) )
+ if (SLPD_fdset_readok(fdset, sock))
{
switch ( sock->state )
{
@@ -490,7 +487,7 @@ void SLPDOutgoingHandler(int* fdcount,
*fdcount = *fdcount - 1;
}
- else if ( FD_ISSET(sock->fd,writefds) )
+ else if (SLPD_fdset_writeok(fdset, sock))
{
switch ( sock->state )
{
--- ./slpd/slpd_outgoing.h.orig 2005-08-22 17:24:56.823078650 +0000
+++ ./slpd/slpd_outgoing.h 2005-08-22 17:25:15.763391246 +0000
@@ -74,17 +74,14 @@ void SLPDOutgoingAge(time_t seconds);
/*=========================================================================*/
void SLPDOutgoingHandler(int* fdcount,
- fd_set* readfds,
- fd_set* writefds);
+ SLPD_fdset* fdset);
/* Handles all incoming requests that are pending on the specified file */
/* discriptors */
/* */
-/* fdcount (IN/OUT) number of file descriptors marked in fd_sets */
+/* fdcount (IN/OUT) number of file descriptors marked in fdset */
/* */
-/* readfds (IN) file descriptors with pending read IO */
-/* */
-/* writefds (IN) file descriptors with pending read IO */
+/* fdset (IN) file descriptors with pending read/write IO */
/*=========================================================================*/
--- ./slpd/slpd_socket.h.orig 2005-08-22 17:24:56.823078650 +0000
+++ ./slpd/slpd_socket.h 2005-08-22 17:25:15.763391246 +0000
@@ -107,8 +107,50 @@ typedef struct _SLPDSocket
/* Outgoing socket stuff */
int reconns;
SLPList sendlist;
+#ifdef HAVE_POLL
+ int fdsetnr;
+#endif
}SLPDSocket;
+#ifdef HAVE_POLL
+
+#include <sys/poll.h>
+
+typedef struct _SLPD_fdset {
+ struct pollfd *fds;
+ int used;
+ int allocated;
+} SLPD_fdset;
+
+/* the following code supports only one fdset at a time */
+
+#define SLPD_fdset_readok(fdset, sock) ((sock)->fdsetnr != -1 && (sock)->fdsetnr < (fdset)->used && (fdset)->fds[(sock)->fdsetnr].fd == (sock)->fd ? ((fdset)->fds[(sock)->fdsetnr].revents & ((fdset)->fds[(sock)->fdsetnr].events & POLLIN ? (POLLIN|POLLERR|POLLHUP) : POLLIN)) != 0 : 0)
+#define SLPD_fdset_writeok(fdset, sock) ((sock)->fdsetnr != -1 && (sock)->fdsetnr < (fdset)->used && (fdset)->fds[(sock)->fdsetnr].fd == (sock)->fd ? ((fdset)->fds[(sock)->fdsetnr].revents & ((fdset)->fds[(sock)->fdsetnr].events & POLLOUT ? (POLLOUT|POLLERR|POLLHUP) : POLLOUT)) != 0 : 0)
+
+#define SLPD_fdset_reset(fdset) ((fdset)->used = 0)
+#define SLPD_fdset_init(fdset) ((fdset)->used = (fdset)->allocated = 0, (fdset)->fds = 0)
+#define SLPD_fdset_free(fdset) ((fdset)->allocated && xfree((fdset)->fds), SLPD_fdset_init(fdset))
+
+#else
+
+typedef struct _SLPD_fdset {
+ fd_set readfds;
+ fd_set writefds;
+ int highfd;
+} SLPD_fdset;
+
+#define SLPD_fdset_readok(fdset, sock) (FD_ISSET((sock)->fd, &(fdset)->readfds))
+#define SLPD_fdset_writeok(fdset, sock) (FD_ISSET((sock)->fd, &(fdset)->writefds))
+
+#define SLPD_fdset_reset(fdset) do { \
+ FD_ZERO(&(fdset)->readfds); \
+ FD_ZERO(&(fdset)->writefds); \
+ (fdset)->highfd = 0; \
+ } while(0)
+#define SLPD_fdset_init(fdset)
+#define SLPD_fdset_free(fdset)
+
+#endif
/*==========================================================================*/
SLPDSocket* SLPDSocketCreateConnected(struct in_addr* addr);
--- ./slpd/slpd_win32.c.orig 2005-08-22 17:24:56.824078508 +0000
+++ ./slpd/slpd_win32.c 2005-08-22 17:25:15.764391104 +0000
@@ -81,9 +81,7 @@ extern int G_SIGTERM;
/*-------------------------------------------------------------------------*/
void LoadFdSets(SLPList* socklist,
- int* highfd,
- fd_set* readfds,
- fd_set* writefds);
+ SLPD_fdset *fdset);
/* see slpd_main.c */
/*-------------------------------------------------------------------------*/
@@ -221,16 +219,18 @@ void ServiceStop()
void ServiceStart (int argc, char **argv)
/*--------------------------------------------------------------------------*/
{
- fd_set readfds;
- fd_set writefds;
- int highfd;
+ SLPD_fdset fdset;
int fdcount = 0;
time_t curtime;
time_t alarmtime;
+#ifndef HAVE_POLL
struct timeval timeout;
+#endif
WSADATA wsaData;
WORD wVersionRequested = MAKEWORD(1,1);
+ SLPD_fdset_init(&fdset);
+
/*------------------------*/
/* Service initialization */
/*------------------------*/
@@ -335,11 +335,9 @@ void ServiceStart (int argc, char **argv
/*--------------------------------------------------------*/
/* Load the fdsets up with all valid sockets in the list */
/*--------------------------------------------------------*/
- highfd = 0;
- FD_ZERO(&readfds);
- FD_ZERO(&writefds);
- LoadFdSets(&G_IncomingSocketList, &highfd, &readfds,&writefds);
- LoadFdSets(&G_OutgoingSocketList, &highfd, &readfds,&writefds);
+ SLPD_fdset_reset(&fdset);
+ LoadFdSets(&G_IncomingSocketList, &fdset);
+ LoadFdSets(&G_OutgoingSocketList, &fdset);
/*--------------------------------------------------*/
/* Before select(), check to see if we got a signal */
@@ -352,13 +350,17 @@ void ServiceStart (int argc, char **argv
/*-------------*/
/* Main select */
/*-------------*/
+#ifdef HAVE_POLL
+ fdcount = poll(fdset.fds, fdset.used, SLPD_AGE_INTERVAL * 1000);
+#else
timeout.tv_sec = SLPD_AGE_INTERVAL;
timeout.tv_usec = 0;
- fdcount = select(highfd+1,&readfds,&writefds,0,&timeout);
+ fdcount = select(fdset.highfd+1,&fdset.readfds,&fdset.writefds,0,&timeout);
+#endif
if(fdcount > 0) /* fdcount will be < 0 when timed out */
{
- SLPDIncomingHandler(&fdcount,&readfds,&writefds);
- SLPDOutgoingHandler(&fdcount,&readfds,&writefds);
+ SLPDIncomingHandler(&fdcount,&fdset);
+ SLPDOutgoingHandler(&fdcount,&fdset);
}
/*----------------*/