Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions
fpm_events.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fpm_event_s
struct  fpm_event_queue_s
struct  fpm_event_module_s

Defines

#define FPM_EV_TIMEOUT   (1 << 0)
#define FPM_EV_READ   (1 << 1)
#define FPM_EV_PERSIST   (1 << 2)
#define FPM_EV_EDGE   (1 << 3)
#define fpm_event_set_timer(ev, flags, cb, arg)   fpm_event_set((ev), -1, (flags), (cb), (arg))

Typedefs

typedef struct fpm_event_queue_s fpm_event_queue

Functions

void fpm_event_loop (int err)
void fpm_event_fire (struct fpm_event_s *ev)
int fpm_event_init_main ()
int fpm_event_set (struct fpm_event_s *ev, int fd, int flags, void(*callback)(struct fpm_event_s *, short, void *), void *arg)
int fpm_event_add (struct fpm_event_s *ev, unsigned long int timeout)
int fpm_event_del (struct fpm_event_s *ev)
int fpm_event_pre_init (char *machanism)
const char * fpm_event_machanism_name ()
int fpm_event_support_edge_trigger ()

Class Documentation

struct fpm_event_queue_s

Definition at line 26 of file fpm_events.h.

Collaboration diagram for fpm_event_queue_s:
Class Members
struct fpm_event_s * ev
struct fpm_event_queue_s * next
struct fpm_event_queue_s * prev

Define Documentation

#define FPM_EV_EDGE   (1 << 3)

Definition at line 11 of file fpm_events.h.

#define FPM_EV_PERSIST   (1 << 2)

Definition at line 10 of file fpm_events.h.

#define FPM_EV_READ   (1 << 1)

Definition at line 9 of file fpm_events.h.

#define FPM_EV_TIMEOUT   (1 << 0)

Definition at line 8 of file fpm_events.h.

#define fpm_event_set_timer (   ev,
  flags,
  cb,
  arg 
)    fpm_event_set((ev), -1, (flags), (cb), (arg))

Definition at line 13 of file fpm_events.h.


Typedef Documentation


Function Documentation

int fpm_event_add ( struct fpm_event_s ev,
unsigned long int  timeout 
)

Definition at line 473 of file fpm_events.c.

{
       struct timeval now;
       struct timeval tmp;

       if (!ev) {
              return -1;
       }

       ev->index = -1;

       /* it's a triggered event on incoming data */
       if (ev->flags & FPM_EV_READ) {
              ev->which = FPM_EV_READ;
              if (fpm_event_queue_add(&fpm_event_queue_fd, ev) != 0) {
                     return -1;
              }
              return 0;
       }

       /* it's a timer event */
       ev->which = FPM_EV_TIMEOUT;

       fpm_clock_get(&now);
       if (frequency >= 1000) {
              tmp.tv_sec = frequency / 1000;
              tmp.tv_usec = (frequency % 1000) * 1000;
       } else {
              tmp.tv_sec = 0;
              tmp.tv_usec = frequency * 1000;
       }
       ev->frequency = tmp;
       fpm_event_set_timeout(ev, now);

       if (fpm_event_queue_add(&fpm_event_queue_timer, ev) != 0) {
              return -1;
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fpm_event_del ( struct fpm_event_s ev)

Definition at line 515 of file fpm_events.c.

{
       if (ev->index >= 0 && fpm_event_queue_del(&fpm_event_queue_fd, ev) != 0) {
              return -1;
       }

       if (ev->index < 0 && fpm_event_queue_del(&fpm_event_queue_timer, ev) != 0) {
              return -1;
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fpm_event_fire ( struct fpm_event_s ev)

Definition at line 449 of file fpm_events.c.

{
       if (!ev || !ev->callback) {
              return;
       }

       (*ev->callback)( (struct fpm_event_s *) ev, ev->which, ev->arg);      
}

Here is the caller graph for this function:

Definition at line 302 of file fpm_events.c.

{
       struct fpm_worker_pool_s *wp;
       int max;

       if (!module) {
              zlog(ZLOG_ERROR, "no event module found");
              return -1;
       }

       if (!module->wait) {
              zlog(ZLOG_ERROR, "Incomplete event implementation. Please open a bug report on https://bugs.php.net.");
              return -1;
       }

       /* count the max number of necessary fds for polling */
       max = 1; /* only one FD is necessary at startup for the master process signal pipe */
       for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
              if (!wp->config) continue;
              if (wp->config->catch_workers_output && wp->config->pm_max_children > 0) {
                     max += (wp->config->pm_max_children * 2);
              }
       }

       if (module->init(max) < 0) {
              zlog(ZLOG_ERROR, "Unable to initialize the event module %s", module->name);
              return -1;
       }

       zlog(ZLOG_DEBUG, "event module is %s and %d fds have been reserved", module->name, max);

       if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_event_cleanup, NULL)) {
              return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fpm_event_loop ( int  err)

Definition at line 340 of file fpm_events.c.

{
       static struct fpm_event_s signal_fd_event;

       /* sanity check */
       if (fpm_globals.parent_pid != getpid()) {
              return;
       }

       fpm_event_set(&signal_fd_event, fpm_signals_get_fd(), FPM_EV_READ, &fpm_got_signal, NULL);
       fpm_event_add(&signal_fd_event, 0);

       /* add timers */
       if (fpm_globals.heartbeat > 0) {
              fpm_pctl_heartbeat(NULL, 0, NULL);
       }

       if (!err) {
              fpm_pctl_perform_idle_server_maintenance_heartbeat(NULL, 0, NULL);

              zlog(ZLOG_DEBUG, "%zu bytes have been reserved in SHM", fpm_shm_get_size_allocated());
              zlog(ZLOG_NOTICE, "ready to handle connections");
       }

       while (1) {
              struct fpm_event_queue_s *q, *q2;
              struct timeval ms;
              struct timeval tmp;
              struct timeval now;
              unsigned long int timeout;
              int ret;

              /* sanity check */
              if (fpm_globals.parent_pid != getpid()) {
                     return;
              }

              fpm_clock_get(&now);
              timerclear(&ms);

              /* search in the timeout queue for the next timer to trigger */
              q = fpm_event_queue_timer;
              while (q) {
                     if (!timerisset(&ms)) {
                            ms = q->ev->timeout;
                     } else {
                            if (timercmp(&q->ev->timeout, &ms, <)) {
                                   ms = q->ev->timeout;
                            }
                     }
                     q = q->next;
              }

              /* 1s timeout if none has been set */
              if (!timerisset(&ms) || timercmp(&ms, &now, <) || timercmp(&ms, &now, ==)) {
                     timeout = 1000;
              } else {
                     timersub(&ms, &now, &tmp);
                     timeout = (tmp.tv_sec * 1000) + (tmp.tv_usec / 1000) + 1;
              }

              ret = module->wait(fpm_event_queue_fd, timeout);

              /* is a child, nothing to do here */
              if (ret == -2) {
                     return;
              }

              if (ret > 0) {
                     zlog(ZLOG_DEBUG, "event module triggered %d events", ret);
              }

              /* trigger timers */
              q = fpm_event_queue_timer;
              while (q) {
                     fpm_clock_get(&now);
                     if (q->ev) {
                            if (timercmp(&now, &q->ev->timeout, >) || timercmp(&now, &q->ev->timeout, ==)) {
                                   fpm_event_fire(q->ev);
                                   /* sanity check */
                                   if (fpm_globals.parent_pid != getpid()) {
                                          return;
                                   }
                                   if (q->ev->flags & FPM_EV_PERSIST) {
                                          fpm_event_set_timeout(q->ev, now);
                                   } else { /* delete the event */
                                          q2 = q;
                                          if (q->prev) {
                                                 q->prev->next = q->next;
                                          }
                                          if (q->next) {
                                                 q->next->prev = q->prev;
                                          }
                                          if (q == fpm_event_queue_timer) {
                                                 fpm_event_queue_timer = q->next;
                                                 fpm_event_queue_timer->prev = NULL;
                                          }
                                          q = q->next;
                                          free(q2);
                                          continue;
                                   }
                            }
                     }
                     q = q->next;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* fpm_event_machanism_name ( )

Definition at line 290 of file fpm_events.c.

{
       return module ? module->name : NULL;
}

Here is the caller graph for this function:

int fpm_event_pre_init ( char *  machanism)

Definition at line 231 of file fpm_events.c.

{
       /* kqueue */
       module = fpm_event_kqueue_module();
       if (module) {
              if (!machanism || strcasecmp(module->name, machanism) == 0) {
                     return 0;
              }
       }

       /* port */
       module = fpm_event_port_module();
       if (module) {
              if (!machanism || strcasecmp(module->name, machanism) == 0) {
                     return 0;
              }
       }

       /* epoll */
       module = fpm_event_epoll_module();
       if (module) {
              if (!machanism || strcasecmp(module->name, machanism) == 0) {
                     return 0;
              }
       }

       /* /dev/poll */
       module = fpm_event_devpoll_module();
       if (module) {
              if (!machanism || strcasecmp(module->name, machanism) == 0) {
                     return 0;
              }
       }

       /* poll */
       module = fpm_event_poll_module();
       if (module) {
              if (!machanism || strcasecmp(module->name, machanism) == 0) {
                     return 0;
              }
       }

       /* select */
       module = fpm_event_select_module();
       if (module) {
              if (!machanism || strcasecmp(module->name, machanism) == 0) {
                     return 0;
              }
       }

       if (machanism) {
              zlog(ZLOG_ERROR, "event mechanism '%s' is not available on this system", machanism);
       } else {
              zlog(ZLOG_ERROR, "unable to find a suitable event mechanism on this system");
       }
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fpm_event_set ( struct fpm_event_s ev,
int  fd,
int  flags,
void(*)(struct fpm_event_s *, short, void *)  callback,
void *  arg 
)

Definition at line 459 of file fpm_events.c.

{
       if (!ev || !callback || fd < -1) {
              return -1;
       }
       memset(ev, 0, sizeof(struct fpm_event_s));
       ev->fd = fd;
       ev->callback = callback;
       ev->arg = arg;
       ev->flags = flags;
       return 0;
}

Here is the caller graph for this function:

Definition at line 296 of file fpm_events.c.

{
       return module ? module->support_edge_trigger : 0;
}

Here is the caller graph for this function: