/Conn_engine_poll.c (8a866dbb20b17aa5efd9466ccacd74e25baa6923) (2761 bytes) (mode 100644) (type blob)
#include <Conn_config.h>
#ifdef POLL_FOUND
#include <Conn_engine_poll.h>
/*
* Variables
*/
static unsigned long Conn_poll_allocated_slots = 0;
static struct pollfd *Conn_poll_pfds = NULL;
/*
* Functions
*/
/*
* Init the engine
*/
int Conn_poll_init(void)
{
return 0;
}
int Conn_poll_shutdown(void)
{
free(Conn_poll_pfds);
return 0;
}
/*
* Grow the number of slots needed for poll
*/
int Conn_poll_grow(unsigned int alloc)
{
struct pollfd *p, *set;
unsigned int diff, mem;
Log(10, "%s: Trying to grow pollfds from %d to %d.\n",
__FUNCTION__,
Conn_poll_allocated_slots, alloc);
if (alloc <= Conn_poll_allocated_slots)
return 0;
diff = alloc - Conn_poll_allocated_slots;
mem = alloc * sizeof(struct pollfd);
p = (struct pollfd *) realloc(Conn_poll_pfds, mem);
if (p == NULL) {
snprintf(Conn_error, sizeof(Conn_error),
"Cannot alloc %u bytes for pollfds.", mem);
return -1;
}
set = p + Conn_poll_allocated_slots;
memset(set, 0, diff * sizeof(struct pollfd));
Conn_poll_pfds = p;
return 0;
}
/*
* Add a target to the list
*/
int Conn_poll_add_obj(struct Conn *C)
{
Conn_poll_pfds[C->slot].fd = C->fd;
Conn_poll_pfds[C->slot].events = C->events;
return 0;
}
/*
* Remove a target from the list
*/
int Conn_poll_del_obj(struct Conn *C)
{
Conn_poll_pfds[C->slot].fd = -1;
Conn_poll_pfds[C->slot].events = 0;
return 0;
}
/*
* Change event mask
*/
int Conn_poll_chg_obj(struct Conn *C)
{
Conn_poll_pfds[C->slot].events = C->events;
return 0;
}
/*
* Calls a callback for fds with activity
* Returns: -1 on error, 0 nothing to do, n (>0) if some work was done
* timeout is in 1/1000 seconds increments.
*/
int Conn_poll_poll(const int timeout2, void (*cb)(const unsigned int slot,
const int revents))
{
int slot, events;
Log(10, "%s: timeout2=%ums...\n", __FUNCTION__, timeout2);
again:
events = poll(&Conn_poll_pfds[0], Conn_no, timeout2);
if ((events == -1) && (errno == EINTR))
goto again;
if (events < 0) {
snprintf(Conn_error, sizeof(Conn_error),
"%s: Conn_no=%d [%s]",
__FUNCTION__, Conn_no,
strerror(errno));
return -1;
}
gettimeofday(&Conn_now, NULL);
if (events == 0)
return 0;
/* We do revers scan because of moving Conn objects */
Log(11, "\tProcessing %d event(s)...\n",
events);
slot = Conn_no - 1;
do {
if (Conn_poll_pfds[slot].revents & POLLNVAL) {
Log(0, "BUG NVAL!\n");
exit(1);
}
cb(slot, Conn_poll_pfds[slot].revents);
slot--;
} while (slot >= 0);
return events;
}
/*
* Move a slot over an other.
*/
int Conn_poll_move_slot(const unsigned int dst, const unsigned int src)
{
struct pollfd tmp;
tmp = Conn_poll_pfds[dst];
Conn_poll_pfds[dst] = Conn_poll_pfds[src];
Conn_poll_pfds[src] = tmp;
return 0;
}
#endif
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
94 |
2e97920b91646e1a8c2438ca375e2aaae22793fb |
.gitignore |
100644 |
blob |
169 |
c003c095218f64ad33aeb89987f61eb575557d96 |
.mailmap |
100644 |
blob |
1945 |
fecf0e7a7e8580485101a179685aedc7e00affbb |
Changelog.pre109 |
100644 |
blob |
33594 |
bee2aa87c3f0e64f6e285d355b16d1625fb83266 |
Conn.c |
100644 |
blob |
1526 |
e10421bf8e376a6b479156ca7be599e3a7bc7727 |
Conn.h |
100644 |
blob |
835 |
3e3dff5bad664ce3c207f971f93c3a9125690e5e |
Conn.spec.in |
100644 |
blob |
95 |
709b9e660dcb7e8c7f17cda4e15cf3e37ec73839 |
Conn_config.h.in |
100644 |
blob |
32116 |
1ef5a31760df3e75df94dfc24bf9b82be345f074 |
Conn_engine_core.c |
100644 |
blob |
9809 |
1b67b229f712fc9f929bd50db99edd16dee93d24 |
Conn_engine_core.h |
100644 |
blob |
3960 |
51e1c1125e9dd4cbfdefa2dab9c1817a346e7827 |
Conn_engine_epoll.c |
100644 |
blob |
610 |
b8597ef7043fa9b6ccd58c0f484f040e8621cc95 |
Conn_engine_epoll.h |
100644 |
blob |
2761 |
8a866dbb20b17aa5efd9466ccacd74e25baa6923 |
Conn_engine_poll.c |
100644 |
blob |
597 |
183f7af0b0688200fa8f69527c03ee075c83df12 |
Conn_engine_poll.h |
100644 |
blob |
30 |
d987fa5df957830331139935d517009e2911b0cf |
INSTALL |
100644 |
blob |
25275 |
92b8903ff3fea7f49ef5c041b67a087bca21c5ec |
LICENSE |
100644 |
blob |
1300 |
3dca4a4b1231b9544475cabe887ceed92e014d17 |
Makefile.in |
100644 |
blob |
192 |
5b11bdfb23857d8588845465aef993b320596b44 |
README |
100644 |
blob |
3347 |
21c1e62573729f1d34b5be7ea2d9e20ffe0c1c65 |
TODO |
100755 |
blob |
23 |
d33bb6c4ecdce1390ce1db3c79ea3b93e22ea755 |
configure |
040000 |
tree |
- |
d4c9c4a69c5cfa2a84316967185f1661b6817779 |
docs |
100755 |
blob |
13311 |
a6e2825b35f915e6d64c2a981fa3b6266b2bf587 |
duilder |
100644 |
blob |
325 |
0397e6b6c1db3a3995fc8f73de7df276c7f83015 |
duilder.conf |
040000 |
tree |
- |
7b6e9c21cc34a982588af6cbbac0447b70a01ed6 |
examples |
040000 |
tree |
- |
751693d0803f700dd060788cc9383aa24b472267 |
tests |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/Conn
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/Conn
Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/Conn
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main