Changeset 607
- Timestamp:
- 07/23/05 15:30:35 (3 years ago)
- Files:
-
- trunk/src/sessions.c (modified) (14 diffs)
- trunk/src/sessions.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/sessions.c
r605 r607 48 48 static int session_destroy(Session *s); 49 49 static void resource_remove(Resource *r,int kill_session); 50 static int session_io_handler(Session *s); 50 51 51 52 static void session_stream_destroyed(gpointer key,gpointer value,gpointer user_data){ … … 59 60 60 61 g_hash_table_foreach(sessions_jid,session_stream_destroyed,stream); 62 } 63 64 typedef struct { 65 GSource g_src; 66 Session *session; 67 }Source; 68 69 static gboolean session_g_source_prepare(GSource *source, gint* timeout_){ 70 71 *timeout_=-1; 72 73 return FALSE; 74 } 75 static gboolean session_g_source_check(GSource *source){ 76 Source *src=(Source *)(gpointer)source; 77 78 return src->session->g_pollfd.revents != 0; 79 } 80 static gboolean session_g_source_dispatch(GSource *source,GSourceFunc callback,gpointer user_data){ 81 Source *src=(Source *)(gpointer)source; 82 83 session_io_handler(src->session); 84 return TRUE; 85 } 86 87 static GSourceFuncs source_funcs = { 88 session_g_source_prepare, 89 session_g_source_check, 90 session_g_source_dispatch, 91 NULL 92 }; 93 94 static void session_setup_g_source(Session *s) { 95 96 if (!s->ggs) return; 97 98 if (s->g_source && s->g_pollfd.fd != s->ggs->fd) { 99 g_source_remove_poll(s->g_source, &s->g_pollfd); 100 } 101 102 if (!s->g_source) { 103 s->g_source = g_source_new(&source_funcs, sizeof(Source)); 104 ((Source *)(gpointer)s->g_source)->session=s; 105 g_source_attach(s->g_source,g_main_loop_get_context(main_loop)); 106 } 107 108 s->g_pollfd.events=G_IO_ERR|G_IO_HUP|G_IO_NVAL; 109 if (s->ggs->check&GG_CHECK_READ) s->g_pollfd.events|=G_IO_IN; 110 if (s->ggs->check&GG_CHECK_WRITE) s->g_pollfd.events|=G_IO_OUT; 111 112 if (s->g_pollfd.fd != s->ggs->fd) { 113 s->g_pollfd.fd=s->ggs->fd; 114 if (s->g_pollfd.fd!=-1) g_source_add_poll(s->g_source, &s->g_pollfd); 115 } 116 } 117 118 static void session_remove_g_source(Session *s) { 119 120 if (!s->g_source) return; 121 122 if (s->g_pollfd.fd!=-1) g_source_remove_poll(s->g_source, &s->g_pollfd); 123 g_source_destroy(s->g_source); 124 s->g_source=NULL; 61 125 } 62 126 … … 349 413 } 350 414 s->connected=0; 351 s->io_watch=0;352 415 session_schedule_reconnect(s); 353 416 session_remove(s); … … 355 418 356 419 357 int session_io_handler(GIOChannel *source,GIOCondition condition,gpointer data){ 358 Session *s; 420 int session_io_handler(Session *s){ 359 421 struct gg_event *event; 360 422 char *jid,*str; 361 423 int chat; 362 GIOCondition cond ;424 GIOCondition condition=s->g_pollfd.revents; 363 425 time_t timestamp; 364 426 365 s=(Session *)data;366 427 user_load_locale(s->user); 367 428 debug(L_("Checking error conditions...")); … … 401 462 jabber_iq_send_error(s->s,s->jid,NULL,s->req_id,401,_("Unauthorized")); 402 463 else presence_send(s->s,NULL,s->user->jid,0,NULL,"Login failed",0); 403 s->io_watch=0;404 464 if (!s->req_id) 405 465 session_schedule_reconnect(s); … … 546 606 } 547 607 548 cond=G_IO_ERR|G_IO_HUP|G_IO_NVAL; 549 if (s->ggs->check&GG_CHECK_READ) cond|=G_IO_IN; 550 if (s->ggs->check&GG_CHECK_WRITE) cond|=G_IO_OUT; 551 s->io_watch=g_io_add_watch(s->ioch,cond,session_io_handler,s); 608 session_setup_g_source(s); 552 609 553 610 gg_event_free(event); … … 562 619 563 620 g_message(L_("Deleting session for '%s'"),s->jid); 564 if (s->io_watch) g_source_remove(s->io_watch);565 621 if (s->ping_timeout_func) g_source_remove(s->ping_timeout_func); 566 622 if (s->timeout_func) g_source_remove(s->timeout_func); … … 579 635 } 580 636 } 581 if (s->ioch) g_io_channel_close(s->ioch);637 session_remove_g_source(s); 582 638 if (s->ggs){ 583 639 if (s->connected){ … … 673 729 static int session_try_login(Session *s){ 674 730 struct gg_login_params login_params; 675 GIOCondition cond;676 731 GgServer *serv; 677 732 int r; … … 681 736 682 737 if (s->timeout_func) g_source_remove(s->timeout_func); 683 if (s-> io_watch) g_source_remove(s->io_watch);684 if (s->ioch) {685 g_io_channel_close(s->ioch);686 s->ioch=NULL;687 }738 if (s->ggs) { 739 gg_free_session(s->ggs); 740 s->ggs=NULL; 741 } 742 session_remove_g_source(s); 688 743 689 744 memset(&login_params,0,sizeof(login_params)); … … 711 766 #endif 712 767 713 if (s->ggs) gg_free_session(s->ggs);714 768 s->ggs=gg_login(&login_params); 715 769 if (!s->ggs){ … … 717 771 return 1; 718 772 } 719 720 s->ioch=g_io_channel_unix_new(s->ggs->fd); 721 cond=G_IO_ERR|G_IO_HUP|G_IO_NVAL; 722 if (s->ggs->check&GG_CHECK_READ) cond|=G_IO_IN; 723 if (s->ggs->check&GG_CHECK_WRITE) cond|=G_IO_OUT; 724 s->io_watch=g_io_add_watch(s->ioch,cond,session_io_handler,s); 773 session_setup_g_source(s); 725 774 726 775 s->timeout_func=g_timeout_add(conn_timeout*1000,session_timeout,s); 727 728 729 776 return FALSE; 730 777 } … … 750 797 s->query=xmlnode_dup(query); 751 798 s->current_server=g_list_first(gg_servers); 799 s->g_pollfd.fd=-1; 752 800 753 801 if (!delay_login && session_try_login(s)) return NULL; … … 1037 1085 } 1038 1086 g_message(L_("%sGG session: %p"),space,s->ggs); 1039 g_message(L_("%s IO Channel: %p"),space,s->ioch);1087 g_message(L_("%sGSource: %p"),space,s->g_source); 1040 1088 g_message(L_("%sStream: %p"),space,s->s); 1041 1089 g_message(L_("%sConnected: %i"),space,s->connected); trunk/src/sessions.h
r595 r607 40 40 char *gg_status_descr; 41 41 42 G IOChannel *ioch; /* GG IO Channel */43 guint io_watch;42 GSource *g_source; 43 GPollFD g_pollfd; 44 44 45 45 int connected;
