Changeset 0af5f9d
- Timestamp:
- Mar 25, 2011, 3:55:41 AM (14 years ago)
- Children:
- bb54113
- Parents:
- 37d188f
- git-author:
- David Benjamin <davidben@mit.edu> (02/26/11 16:32:51)
- git-committer:
- David Benjamin <davidben@mit.edu> (03/25/11 03:55:41)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
aim.c
r3472845 r0af5f9d 446 446 } 447 447 448 int owl_aim_process_events(void) 449 { 450 aim_session_t *aimsess; 448 int owl_aim_process_events(aim_session_t *aimsess) 449 { 451 450 aim_conn_t *waitingconn = NULL; 452 451 struct timeval tv; … … 454 453 struct owlfaim_priv *priv; 455 454 456 aimsess=owl_global_get_aimsess(&g);457 455 priv = aimsess->aux_data; 458 456 … … 1795 1793 } 1796 1794 1797 void owl_process_aim(void) 1798 { 1799 if (owl_global_is_doaimevents(&g)) { 1800 owl_aim_process_events(); 1801 } 1802 } 1795 typedef struct _owl_aim_event_source { /*noproto*/ 1796 GSource source; 1797 aim_session_t *sess; 1798 GPtrArray *fds; 1799 } owl_aim_event_source; 1800 1801 static void truncate_pollfd_list(owl_aim_event_source *event_source, int len) 1802 { 1803 GPollFD *fd; 1804 int i; 1805 if (len < event_source->fds->len) 1806 owl_function_debugmsg("Truncating AIM PollFDs to %d, was %d", len, event_source->fds->len); 1807 for (i = len; i < event_source->fds->len; i++) { 1808 fd = event_source->fds->pdata[i]; 1809 g_source_remove_poll(&event_source->source, fd); 1810 g_free(fd); 1811 } 1812 g_ptr_array_remove_range(event_source->fds, len, event_source->fds->len - len); 1813 } 1814 1815 static gboolean owl_aim_event_source_prepare(GSource *source, int *timeout) 1816 { 1817 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1818 aim_conn_t *cur; 1819 GPollFD *fd; 1820 int i; 1821 1822 /* AIM HACK: 1823 * 1824 * The problem - I'm not sure where to hook into the owl/faim 1825 * interface to keep track of when the AIM socket(s) open and 1826 * close. In particular, the bosconn thing throws me off. So, 1827 * rather than register particular dispatchers for AIM, I look up 1828 * the relevant FDs and add them to select's watch lists, then 1829 * check for them individually before moving on to the other 1830 * dispatchers. --asedeno 1831 */ 1832 i = 0; 1833 for (cur = event_source->sess->connlist; cur; cur = cur->next) { 1834 if (cur->fd != -1) { 1835 /* Add new GPollFDs as necessary. */ 1836 if (i == event_source->fds->len) { 1837 fd = g_new0(GPollFD, 1); 1838 g_ptr_array_add(event_source->fds, fd); 1839 g_source_add_poll(source, fd); 1840 owl_function_debugmsg("Allocated new AIM PollFD, len = %d", event_source->fds->len); 1841 } 1842 fd = event_source->fds->pdata[i]; 1843 fd->fd = cur->fd; 1844 fd->events |= G_IO_IN | G_IO_HUP | G_IO_ERR; 1845 if (cur->status & AIM_CONN_STATUS_INPROGRESS) { 1846 /* Yes, we're checking writable sockets here. Without it, AIM 1847 login is really slow. */ 1848 fd->events |= G_IO_OUT; 1849 } 1850 i++; 1851 } 1852 } 1853 /* If the number of GPollFDs went down, clean up. */ 1854 truncate_pollfd_list(event_source, i); 1855 1856 *timeout = -1; 1857 return FALSE; 1858 } 1859 1860 static gboolean owl_aim_event_source_check(GSource *source) 1861 { 1862 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1863 int i; 1864 1865 for (i = 0; i < event_source->fds->len; i++) { 1866 GPollFD *fd = event_source->fds->pdata[i]; 1867 if (fd->revents & fd->events) 1868 return TRUE; 1869 } 1870 return FALSE; 1871 } 1872 1873 static gboolean owl_aim_event_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) 1874 { 1875 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1876 owl_aim_process_events(event_source->sess); 1877 return TRUE; 1878 } 1879 1880 static void owl_aim_event_source_finalize(GSource *source) 1881 { 1882 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1883 truncate_pollfd_list(event_source, 0); 1884 g_ptr_array_free(event_source->fds, TRUE); 1885 } 1886 1887 static GSourceFuncs aim_event_funcs = { 1888 owl_aim_event_source_prepare, 1889 owl_aim_event_source_check, 1890 owl_aim_event_source_dispatch, 1891 owl_aim_event_source_finalize, 1892 }; 1893 1894 GSource *owl_aim_event_source_new(aim_session_t *sess) 1895 { 1896 GSource *source; 1897 owl_aim_event_source *event_source; 1898 1899 source = g_source_new(&aim_event_funcs, sizeof(owl_aim_event_source)); 1900 event_source = (owl_aim_event_source *)source; 1901 event_source->sess = sess; 1902 /* TODO: When we depend on glib 2.22+, use g_ptr_array_new_with_free_func. */ 1903 event_source->fds = g_ptr_array_new(); 1904 return source; 1905 } -
global.c
r37d188f r0af5f9d 697 697 } 698 698 699 int owl_global_is_doaimevents(const owl_global *g) 700 { 701 if (g->aim_doprocessing) return(1); 702 return(0); 699 bool owl_global_is_doaimevents(const owl_global *g) 700 { 701 return g->aim_event_source != NULL; 703 702 } 704 703 705 704 void owl_global_set_doaimevents(owl_global *g) 706 705 { 707 g->aim_doprocessing=1; 706 if (g->aim_event_source) 707 return; 708 g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g)); 709 g_source_attach(g->aim_event_source, NULL); 708 710 } 709 711 710 712 void owl_global_set_no_doaimevents(owl_global *g) 711 713 { 712 g->aim_doprocessing=0; 714 if (!g->aim_event_source) 715 return; 716 g_source_destroy(g->aim_event_source); 717 g_source_unref(g->aim_event_source); 718 g->aim_event_source = NULL; 713 719 } 714 720 -
owl.h
r37d188f r0af5f9d 612 612 aim_conn_t bosconn; 613 613 int aim_loggedin; /* true if currently logged into AIM */ 614 int aim_doprocessing; /* true if we should process AIM events (like pending login)*/614 GSource *aim_event_source; /* where we get our AIM events from */ 615 615 char *aim_screenname; /* currently logged in AIM screen name */ 616 616 char *aim_screenname_for_filters; /* currently logged in AIM screen name */
Note: See TracChangeset
for help on using the changeset viewer.