Back to index

courier  0.68.2
Classes | Defines | Functions
mksocket.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pollfd

Defines

#define POLLIN   1
#define POLLPRI   2
#define POLLOUT   4
#define POLLERR   8
#define POLLHUP   16
#define POLLNVAL   32

Functions

int mksocket (const char *address, const char *service, int socktype, int *fd1, int *fd2, int recycle_fd_func(int(*)(int, void *), void *, void *), void *voidarg)
int poll (struct pollfd *pfd, unsigned int n, int timeout)

Class Documentation

struct pollfd

Definition at line 32 of file mksocket.h.

Class Members
short events
int fd
short revents

Define Documentation

#define POLLERR   8

Definition at line 28 of file mksocket.h.

#define POLLHUP   16

Definition at line 29 of file mksocket.h.

#define POLLIN   1

Definition at line 25 of file mksocket.h.

#define POLLNVAL   32

Definition at line 30 of file mksocket.h.

#define POLLOUT   4

Definition at line 27 of file mksocket.h.

#define POLLPRI   2

Definition at line 26 of file mksocket.h.


Function Documentation

int mksocket ( const char *  address,
const char *  service,
int  socktype,
int *  fd1,
int *  fd2,
int   recycle_fd_funcint(*)(int, void *), void *, void *,
void *  voidarg 
)

Definition at line 307 of file mksocket.c.

{
       int fd_flag=0;

       *fd1= -1;
       *fd2= -1;

       if (address && strcmp(address, "0"))
       {
#if HAVE_INET_PTON
              SOCKADDR_STORAGE ina;

              if (inet_pton(AF_INET, address, &ina) > 0)
                     fd_flag=MKS_USEAFINET4;
#else
              struct in_addr ina;

              if (inet_aton(address, &ina))
                     fd_flag=MKS_USEAFINET4;
#endif

       }


       *fd1=mksocket2(address, service, socktype, fd_flag,
                     recycle_fd_func, voidarg);

       /* BSD requires both an IPv6 and an IPv4 socket */

#if    HAVE_SOXWRAP_IPV6

       if (address == 0 || strcmp(address, "0") == 0)
       {
              int fd=mksocket2(address, service, socktype,
                             (MKS_USEAFINET4|MKS_ERROK),
                             recycle_fd_func, voidarg);

              if (fd < 0)
              {
                     if (fd != -2)
                     {
                            if (*fd1 >= 0)
                                   close(*fd1);
                            return -1;
                     }
              }

              *fd2=fd;
       }
#endif
       if (*fd1 < 0 && *fd2 < 0)
              return -1;

       if (*fd1 < 0)
       {
              *fd1=*fd2;
              *fd2=-1;
       }
       return 0;
}

Here is the call graph for this function:

int poll ( struct pollfd pfd,
unsigned int  n,
int  timeout 
)

Definition at line 378 of file mksocket.c.

{
       fd_set r, w, e;
       int maxfd=-1;
       unsigned int i;
       struct timeval tv;
       int cnt=0;

       FD_ZERO(&r);
       FD_ZERO(&w);
       FD_ZERO(&e);

       for (i=0; i<n; i++)
       {
              if (pfd[i].fd >= maxfd)
                     maxfd=pfd[i].fd;

              pfd[i].revents=0;
              if (pfd[i].events & (POLLIN|POLLPRI))
                     FD_SET(pfd[i].fd, &r);
              if (pfd[i].events & POLLOUT)
                     FD_SET(pfd[i].fd, &w);
              if (pfd[i].events & POLLPRI)
                     FD_SET(pfd[i].fd, &e);
       }

       tv.tv_sec=timeout/1000;
       tv.tv_usec=(timeout % 1000) * 1000;

       if (select(maxfd+1, &r, &w, &e, timeout < 0 ?NULL:&tv) < 0)
              return -1;

       for (i=0; i<n; i++)
       {
              if (FD_ISSET(pfd[i].fd, &r))
                     pfd[i].revents |= POLLIN;
              if (FD_ISSET(pfd[i].fd, &w))
                     pfd[i].revents |= POLLOUT;
              if (FD_ISSET(pfd[i].fd, &e))
                     pfd[i].revents |= POLLIN|POLLHUP;

              if (pfd[i].revents)
                     ++cnt;
       }

       return cnt;
}