comparison src/protocols/qq/sendqueue.c @ 14021:ef8490f9e823

[gaim-migrate @ 16618] Replaced all C++-style comments with C-style ones. Cleaned up some comments and implemented a more consistent formatting scheme. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Wed, 02 Aug 2006 15:35:36 +0000
parents 983fd420e86b
children
comparison
equal deleted inserted replaced
14020:13e7ba964993 14021:ef8490f9e823
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23 // START OF FILE 23 #include "connection.h"
24 /*****************************************************************************/ 24 #include "debug.h"
25 #include "connection.h" // GaimConnection 25 #include "internal.h"
26 #include "debug.h" // gaim_debug 26 #include "notify.h"
27 #include "internal.h" // _("get_text") 27 #include "prefs.h"
28 #include "notify.h" // gaim_notify 28 #include "request.h"
29 #include "prefs.h" // gaim_prefs_get_bool 29
30 #include "request.h" // gaim_request_action 30 #include "header_info.h"
31 31 #include "qq_proxy.h"
32 #include "header_info.h" // cmd alias
33 #include "qq_proxy.h" // qq_proxy_write
34 #include "sendqueue.h" 32 #include "sendqueue.h"
35 33
36 #define QQ_RESEND_MAX 5 // max resend per packet 34 #define QQ_RESEND_MAX 5 /* max resend per packet */
37 35
38 typedef struct _gc_and_packet gc_and_packet; 36 typedef struct _gc_and_packet gc_and_packet;
39 37
40 struct _gc_and_packet { 38 struct _gc_and_packet {
41 GaimConnection *gc; 39 GaimConnection *gc;
42 qq_sendpacket *packet; 40 qq_sendpacket *packet;
43 }; 41 };
44 42
45 /*****************************************************************************/ 43 /* Remove a packet with send_seq from sendqueue */
46 // Remove a packet with send_seq from sendqueue 44 void qq_sendqueue_remove(qq_data *qd, guint16 send_seq)
47 void qq_sendqueue_remove(qq_data * qd, guint16 send_seq)
48 { 45 {
49 GList *list; 46 GList *list;
50 qq_sendpacket *p; 47 qq_sendpacket *p;
51 48
52 g_return_if_fail(qd != NULL); 49 g_return_if_fail(qd != NULL);
59 g_free(p->buf); 56 g_free(p->buf);
60 g_free(p); 57 g_free(p);
61 break; 58 break;
62 } 59 }
63 list = list->next; 60 list = list->next;
64 } // while 61 }
65 } // qq_sendqueue_remove 62 }
66 63
67 /*****************************************************************************/ 64 /* clean up sendqueue and free all contents */
68 // clean up sendqueue and free all contents 65 void qq_sendqueue_free(qq_data *qd)
69 void qq_sendqueue_free(qq_data * qd)
70 { 66 {
71 qq_sendpacket *p; 67 qq_sendpacket *p;
72 gint i; 68 gint i;
73 69
74 i = 0; 70 i = 0;
78 g_free(p->buf); 74 g_free(p->buf);
79 g_free(p); 75 g_free(p);
80 i++; 76 i++;
81 } 77 }
82 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d packets in sendqueue are freed!\n", i); 78 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d packets in sendqueue are freed!\n", i);
83 } // qq_sendqueue_free 79 }
84 80
85 /*****************************************************************************/ 81 /* packet lost, agree to send again, (and will NOT prompt again)
86 // packet lost, agree to send again, (and will NOT prompt again) 82 * it is removed only when ack-ed by server */
87 // it is removed only when ack-ed by server 83 static void _qq_send_again(gc_and_packet *gp)
88 static void _qq_send_again(gc_and_packet * gp)
89 { 84 {
90 GaimConnection *gc; 85 GaimConnection *gc;
91 qq_data *qd; 86 qq_data *qd;
92 qq_sendpacket *packet; 87 qq_sendpacket *packet;
93 GList *list; 88 GList *list;
104 packet->resend_times = 0; 99 packet->resend_times = 0;
105 packet->sendtime = time(NULL); 100 packet->sendtime = time(NULL);
106 qq_proxy_write(qd, packet->buf, packet->len); 101 qq_proxy_write(qd, packet->buf, packet->len);
107 } 102 }
108 g_free(gp); 103 g_free(gp);
109 } // _qq_send_again 104 }
110 105
111 /*****************************************************************************/ 106 /* packet lost, do not send again */
112 // packet lost, do not send again 107 static void _qq_send_cancel(gc_and_packet *gp)
113 static void _qq_send_cancel(gc_and_packet * gp)
114 { 108 {
115 GaimConnection *gc; 109 GaimConnection *gc;
116 qq_data *qd; 110 qq_data *qd;
117 qq_sendpacket *packet; 111 qq_sendpacket *packet;
118 GList *list; 112 GList *list;
127 list = g_list_find(qd->sendqueue, packet); 121 list = g_list_find(qd->sendqueue, packet);
128 if (list != NULL) 122 if (list != NULL)
129 qq_sendqueue_remove(qd, packet->send_seq); 123 qq_sendqueue_remove(qd, packet->send_seq);
130 124
131 g_free(gp); 125 g_free(gp);
132 } // _qq_send_cancel 126 }
133 127
134 /*****************************************************************************/
135 gboolean qq_sendqueue_timeout_callback(gpointer data) 128 gboolean qq_sendqueue_timeout_callback(gpointer data)
136 { 129 {
137 GaimConnection *gc; 130 GaimConnection *gc;
138 qq_data *qd; 131 qq_data *qd;
139 GList *list; 132 GList *list;
146 gc = (GaimConnection *) data; 139 gc = (GaimConnection *) data;
147 qd = (qq_data *) gc->proto_data; 140 qd = (qq_data *) gc->proto_data;
148 now = time(NULL); 141 now = time(NULL);
149 list = qd->sendqueue; 142 list = qd->sendqueue;
150 143
151 // empty queue, return TRUE so that timeout continues functioning 144 /* empty queue, return TRUE so that timeout continues functioning */
152 if (qd->sendqueue == NULL) 145 if (qd->sendqueue == NULL)
153 return TRUE; 146 return TRUE;
154 147
155 while (list != NULL) { // remove all packet whose resend_times == -1 148 while (list != NULL) { /* remove all packet whose resend_times == -1 */
156 p = (qq_sendpacket *) list->data; 149 p = (qq_sendpacket *) list->data;
157 if (p->resend_times == -1) { // to remove 150 if (p->resend_times == -1) { /* to remove */
158 qd->sendqueue = g_list_remove(qd->sendqueue, p); 151 qd->sendqueue = g_list_remove(qd->sendqueue, p);
159 g_free(p->buf); 152 g_free(p->buf);
160 g_free(p); 153 g_free(p);
161 list = qd->sendqueue; 154 list = qd->sendqueue;
162 } else 155 } else {
163 list = list->next; 156 list = list->next;
164 } // while list 157 }
158 }
165 159
166 list = qd->sendqueue; 160 list = qd->sendqueue;
167 while (list != NULL) { 161 while (list != NULL) {
168 p = (qq_sendpacket *) list->data; 162 p = (qq_sendpacket *) list->data;
169 if (p->resend_times >= QQ_RESEND_MAX) { 163 if (p->resend_times >= QQ_RESEND_MAX) {
170 if (p->resend_times == QQ_RESEND_MAX) { // reach max 164 if (p->resend_times == QQ_RESEND_MAX) { /* reach max */
171 switch (p->cmd) { 165 switch (p->cmd) {
172 case QQ_CMD_KEEP_ALIVE: 166 case QQ_CMD_KEEP_ALIVE:
173 if (qd->logged_in) { 167 if (qd->logged_in) {
174 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection lost!\n"); 168 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection lost!\n");
175 gaim_connection_error(gc, _("Connection lost!")); 169 gaim_connection_error(gc, _("Connection lost!"));
176 qd->logged_in = FALSE; 170 qd->logged_in = FALSE;
177 } // if logged_in 171 }
178 p->resend_times = -1; 172 p->resend_times = -1;
179 break; 173 break;
180 case QQ_CMD_LOGIN: 174 case QQ_CMD_LOGIN:
181 if (!qd->logged_in) // cancel logging progress 175 if (!qd->logged_in) /* cancel logging progress */
182 gaim_connection_error(gc, _("Login failed, no reply!")); 176 gaim_connection_error(gc, _("Login failed, no reply!"));
183 p->resend_times = -1; 177 p->resend_times = -1;
184 break; 178 break;
185 case QQ_CMD_UPDATE_INFO: 179 case QQ_CMD_UPDATE_INFO:
186 gaim_notify_error(gc, NULL, 180 gaim_notify_error(gc, NULL,
189 break; 183 break;
190 default:{ 184 default:{
191 need_action = 185 need_action =
192 gaim_prefs_get_bool("/plugins/prpl/qq/prompt_for_missing_packet"); 186 gaim_prefs_get_bool("/plugins/prpl/qq/prompt_for_missing_packet");
193 if (!need_action) 187 if (!need_action)
194 p->resend_times = -1; // it will be removed next time 188 p->resend_times = -1; /* it will be removed next time */
195 else { // prompt for action 189 else { /* prompt for action */
196 gp = g_new0(gc_and_packet, 1); 190 gp = g_new0(gc_and_packet, 1);
197 gp->gc = gc; 191 gp->gc = gc;
198 gp->packet = p; 192 gp->packet = p;
199 gaim_request_action 193 gaim_request_action
200 (gc, NULL, 194 (gc, NULL,
205 0, gp, 2, 199 0, gp, 2,
206 _("Send"), 200 _("Send"),
207 G_CALLBACK 201 G_CALLBACK
208 (_qq_send_again), 202 (_qq_send_again),
209 _("Cancel"), G_CALLBACK(_qq_send_cancel)); 203 _("Cancel"), G_CALLBACK(_qq_send_cancel));
210 p->resend_times++; // will send once more, but only once 204 /* will send once more, but only once */
211 } // if !need_action 205 p->resend_times++;
212 } // default 206 }
213 } // switch 207 }
214 } // resend_times == QQ_RESEND_MAX 208 }
215 } else { // resend_times < QQ_RESEND_MAX, so sent it again 209 }
210 } else { /* resend_times < QQ_RESEND_MAX, so sent it again */
216 wait_time = (gint) (QQ_SENDQUEUE_TIMEOUT / 1000); 211 wait_time = (gint) (QQ_SENDQUEUE_TIMEOUT / 1000);
217 if (difftime(now, p->sendtime) > (wait_time * (p->resend_times + 1))) { 212 if (difftime(now, p->sendtime) > (wait_time * (p->resend_times + 1))) {
218 qq_proxy_write(qd, p->buf, p->len); 213 qq_proxy_write(qd, p->buf, p->len);
219 p->resend_times++; 214 p->resend_times++;
220 gaim_debug(GAIM_DEBUG_INFO, 215 gaim_debug(GAIM_DEBUG_INFO,
221 "QQ", "<<< [%05d] send again for %d times!\n", p->send_seq, p->resend_times); 216 "QQ", "<<< [%05d] send again for %d times!\n",
222 } // if difftime 217 p->send_seq, p->resend_times);
223 } // if resend_times >= QQ_RESEND_MAX 218 }
219 }
224 list = list->next; 220 list = list->next;
225 } // whiile list 221 }
226 return TRUE; // if we return FALSE, the timeout callback stops functioning 222 return TRUE; /* if we return FALSE, the timeout callback stops functioning */
227 } // qq_sendqueue_timeout_callback 223 }
228
229 /*****************************************************************************/
230 // END OF FILE