ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_epoll.c
(Generate patch)

Comparing libev/ev_epoll.c (file contents):
Revision 1.7 by root, Wed Oct 31 22:16:37 2007 UTC vs.
Revision 1.12 by root, Sat Nov 3 11:44:44 2007 UTC

1/* 1/*
2 * libev epoll fd activity backend
3 *
2 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
3 * All rights reserved. 5 * All rights reserved.
4 * 6 *
5 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 8 * modification, are permitted provided that the following conditions are
35epoll_modify (int fd, int oev, int nev) 37epoll_modify (int fd, int oev, int nev)
36{ 38{
37 int mode = nev ? oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD : EPOLL_CTL_DEL; 39 int mode = nev ? oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD : EPOLL_CTL_DEL;
38 40
39 struct epoll_event ev; 41 struct epoll_event ev;
40 ev.data.fd = fd; 42 ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */
41 ev.events = 43 ev.events =
42 (nev & EV_READ ? EPOLLIN : 0) 44 (nev & EV_READ ? EPOLLIN : 0)
43 | (nev & EV_WRITE ? EPOLLOUT : 0); 45 | (nev & EV_WRITE ? EPOLLOUT : 0);
44 46
45 epoll_ctl (epoll_fd, mode, fd, &ev); 47 epoll_ctl (epoll_fd, mode, fd, &ev);
53 epoll_fd = epoll_create (256); 55 epoll_fd = epoll_create (256);
54 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC); 56 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC);
55 57
56 /* re-register interest in fds */ 58 /* re-register interest in fds */
57 for (fd = 0; fd < anfdmax; ++fd) 59 for (fd = 0; fd < anfdmax; ++fd)
58 if (anfds [fd].events && !(anfds [fd].events & EV_REIFY))//D 60 if (anfds [fd].events)//D
59 epoll_modify (fd, EV_NONE, anfds [fd].events); 61 epoll_modify (fd, EV_NONE, anfds [fd].events);
60} 62}
61 63
62static struct epoll_event *events; 64static struct epoll_event *events;
63static int eventmax; 65static int eventmax;
71 if (eventcnt < 0) 73 if (eventcnt < 0)
72 return; 74 return;
73 75
74 for (i = 0; i < eventcnt; ++i) 76 for (i = 0; i < eventcnt; ++i)
75 fd_event ( 77 fd_event (
76 events [i].data.fd, 78 events [i].data.u64,
77 (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) 79 (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0)
78 | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) 80 | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0)
79 ); 81 );
80 82
81 /* if the receive array was full, increase its size */ 83 /* if the receive array was full, increase its size */
82 if (eventcnt == eventmax) 84 if (expect_false (eventcnt == eventmax))
83 { 85 {
84 free (events); 86 free (events);
85 eventmax += eventmax >> 1; 87 eventmax = array_roundsize (events, eventmax << 1);
86 events = malloc (sizeof (struct epoll_event) * eventmax); 88 events = malloc (sizeof (struct epoll_event) * eventmax);
87 } 89 }
88} 90}
89 91
90static void 92static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines