Lines Matching defs:fde
1254 static void dump_fde(fdevent *fde, const char *info)
1256 fprintf(stderr,"FDE #%03d %c%c%c %s\n", fde->fd,
1257 fde->state & FDE_READ ? 'R' : ' ',
1258 fde->state & FDE_WRITE ? 'W' : ' ',
1259 fde->state & FDE_ERROR ? 'E' : ' ',
1263 #define dump_fde(fde, info) do { } while(0)
1347 fdevent* fde = fd_table[ fd - WIN32_FH_BASE ];
1349 if (fde != NULL && fde->fd == fd) {
1350 if ((fde->state & FDE_PENDING) == 0) {
1351 fde->state |= FDE_PENDING;
1352 fdevent_plist_enqueue( fde );
1354 fde->events |= hook->wanted;
1618 static void fdevent_connect(fdevent *fde)
1621 int events = fde->state & FDE_EVENTMASK;
1624 event_looper_hook( looper, fde->fd, events );
1627 static void fdevent_disconnect(fdevent *fde)
1630 int events = fde->state & FDE_EVENTMASK;
1633 event_looper_unhook( looper, fde->fd, events );
1636 static void fdevent_update(fdevent *fde, unsigned events)
1639 unsigned events0 = fde->state & FDE_EVENTMASK;
1645 D("fdevent_update: remove %x from %d\n", removes, fde->fd);
1646 event_looper_unhook( looper, fde->fd, removes );
1649 D("fdevent_update: add %x to %d\n", adds, fde->fd);
1650 event_looper_hook ( looper, fde->fd, adds );
1753 static void fdevent_register(fdevent *fde)
1755 int fd = fde->fd - WIN32_FH_BASE;
1758 FATAL("bogus negative fd (%d)\n", fde->fd);
1763 if(fde->fd > 32000) {
1764 FATAL("bogus huuuuge fd (%d)\n", fde->fd);
1780 fd_table[fd] = fde;
1783 static void fdevent_unregister(fdevent *fde)
1785 int fd = fde->fd - WIN32_FH_BASE;
1788 FATAL("fd out of range (%d)\n", fde->fd);
1791 if(fd_table[fd] != fde) {
1797 if(!(fde->state & FDE_DONT_CLOSE)) {
1798 dump_fde(fde, "close");
1799 adb_close(fde->fd);
1838 fdevent *fde = (fdevent*) malloc(sizeof(fdevent));
1839 if(fde == 0) return 0;
1840 fdevent_install(fde, fd, func, arg);
1841 fde->state |= FDE_CREATED;
1842 return fde;
1845 void fdevent_destroy(fdevent *fde)
1847 if(fde == 0) return;
1848 if(!(fde->state & FDE_CREATED)) {
1849 FATAL("fde %p not created by fdevent_create()\n", fde);
1851 fdevent_remove(fde);
1854 void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg)
1856 memset(fde, 0, sizeof(fdevent));
1857 fde->state = FDE_ACTIVE;
1858 fde->fd = fd;
1859 fde->func = func;
1860 fde->arg = arg;
1862 fdevent_register(fde);
1863 dump_fde(fde, "connect");
1864 fdevent_connect(fde);
1865 fde->state |= FDE_ACTIVE;
1868 void fdevent_remove(fdevent *fde)
1870 if(fde->state & FDE_PENDING) {
1871 fdevent_plist_remove(fde);
1874 if(fde->state & FDE_ACTIVE) {
1875 fdevent_disconnect(fde);
1876 dump_fde(fde, "disconnect");
1877 fdevent_unregister(fde);
1880 fde->state = 0;
1881 fde->events = 0;
1885 void fdevent_set(fdevent *fde, unsigned events)
1889 if((fde->state & FDE_EVENTMASK) == (int)events) return;
1891 if(fde->state & FDE_ACTIVE) {
1892 fdevent_update(fde, events);
1893 dump_fde(fde, "update");
1896 fde->state = (fde->state & FDE_STATEMASK) | events;
1898 if(fde->state & FDE_PENDING) {
1903 fde->events &= (~events);
1904 if(fde->events == 0) {
1905 fdevent_plist_remove(fde);
1906 fde->state &= (~FDE_PENDING);
1911 void fdevent_add(fdevent *fde, unsigned events)
1914 fde, (fde->state & FDE_EVENTMASK) | (events & FDE_EVENTMASK));
1917 void fdevent_del(fdevent *fde, unsigned events)
1920 fde, (fde->state & FDE_EVENTMASK) & (~(events & FDE_EVENTMASK)));
1925 fdevent *fde;
1933 while((fde = fdevent_plist_dequeue())) {
1934 unsigned events = fde->events;
1935 fde->events = 0;
1936 fde->state &= (~FDE_PENDING);
1937 dump_fde(fde, "callback");
1938 fde->func(fde->fd, events, fde->arg);