winlin

fix bug of forward, earse the forwarded msgs.

@@ -292,7 +292,11 @@ int SrsForwarder::forward() @@ -292,7 +292,11 @@ int SrsForwarder::forward()
292 } 292 }
293 } 293 }
294 294
  295 + // ignore when no messages.
295 int count = (int)msgs.size(); 296 int count = (int)msgs.size();
  297 + if (msgs.empty()) {
  298 + continue;
  299 + }
296 300
297 // reportable 301 // reportable
298 if (pithy_print.can_print()) { 302 if (pithy_print.can_print()) {
@@ -301,16 +305,32 @@ int SrsForwarder::forward() @@ -301,16 +305,32 @@ int SrsForwarder::forward()
301 } 305 }
302 306
303 // all msgs to forward. 307 // all msgs to forward.
304 - for (int i = 0; i < count; i++) { 308 + int i = 0;
  309 + for (i = 0; i < count; i++) {
305 SrsSharedPtrMessage* msg = msgs[i]; 310 SrsSharedPtrMessage* msg = msgs[i];
306 msgs[i] = NULL; 311 msgs[i] = NULL;
  312 +
  313 + // we erased the sendout messages, the msg must not be NULL.
  314 + srs_assert(msg);
307 315
308 - if ((ret = client->send_message(msg)) != ERROR_SUCCESS) { 316 + ret = client->send_message(msg);
  317 + if (ret != ERROR_SUCCESS) {
309 srs_error("forwarder send message to server failed. ret=%d", ret); 318 srs_error("forwarder send message to server failed. ret=%d", ret);
310 - return ret; 319 + break;
311 } 320 }
312 } 321 }
313 - msgs.clear(); 322 +
  323 + // clear sendout mesages.
  324 + if (i < count) {
  325 + srs_warn("clear forwarded msg, total=%d, forwarded=%d, ret=%d", count, i, ret);
  326 + } else {
  327 + srs_info("clear forwarded msg, total=%d, forwarded=%d, ret=%d", count, i, ret);
  328 + }
  329 + msgs.erase(msgs.begin(), msgs.begin() + i);
  330 +
  331 + if (ret != ERROR_SUCCESS) {
  332 + break;
  333 + }
314 } 334 }
315 335
316 return ret; 336 return ret;