@@ -104,7 +104,7 @@ namespace
104104enum
105105{
106106 YERR_OK, // NO ERROR.
107- YERR_SEND_TIMEOUT = -500 , // Send timeout .
107+ YERR_INVALID_PACKET = -500 , // Invalid packet .
108108 YERR_DPL_ILLEGAL_PDU, // Decode pdu length error.
109109 YERR_RESOLV_HOST_FAILED, // Resolve host failed.
110110 YERR_NO_AVAIL_ADDR, // No available address to connect.
@@ -332,7 +332,7 @@ int io_transport_posix::recv(int &error)
332332 error = xxsocket::get_last_errno ();
333333 return n;
334334}
335- bool io_transport_posix::update (long long &max_wait_duration)
335+ bool io_transport_posix::flush (long long &max_wait_duration)
336336{
337337 bool ret = false ;
338338 do
@@ -412,14 +412,19 @@ int io_transport_kcp::recv(int &error)
412412 if (n > 0 )
413413 { // ikcp in event always in service thread, so no need to lock, TODO: confirm.
414414 // 0: ok, -1: again, -3: error
415- ::ikcp_input (kcp_, sbuf, n);
416- n = ::ikcp_recv (kcp_, buffer_ + offset_, sizeof (buffer_) - offset_);
415+ if (0 == ::ikcp_input (kcp_, sbuf, n))
416+ n = ::ikcp_recv (kcp_, buffer_ + offset_, sizeof (buffer_) - offset_);
417+ else
418+ { // current, simply regards -1,-3 as error and trigger connection lost event.
419+ n = 0 ;
420+ error = YERR_INVALID_PACKET;
421+ }
417422 }
418423 else
419424 error = xxsocket::get_last_errno ();
420425 return n;
421426}
422- bool io_transport_kcp::update (long long &max_wait_duration)
427+ bool io_transport_kcp::flush (long long &max_wait_duration)
423428{
424429 std::lock_guard<std::recursive_mutex> lck (send_mtx_);
425430
@@ -673,7 +678,7 @@ void io_service::perform_transports(fd_set *fds_array, long long &max_wait_durat
673678 for (auto iter = transports_.begin (); iter != transports_.end ();)
674679 {
675680 auto transport = *iter;
676- if (do_read (transport, fds_array, max_wait_duration) && transport->update (max_wait_duration))
681+ if (do_read (transport, fds_array, max_wait_duration) && transport->flush (max_wait_duration))
677682 ++iter;
678683 else
679684 {
@@ -1558,8 +1563,6 @@ const char *io_service::strerror(int error)
15581563 {
15591564 case 0 :
15601565 return " No error." ;
1561- case YERR_SEND_TIMEOUT:
1562- return " Send timeout!" ;
15631566 case YERR_DPL_ILLEGAL_PDU:
15641567 return " Decode frame length failed!" ;
15651568 case YERR_RESOLV_HOST_FAILED:
@@ -1568,6 +1571,8 @@ const char *io_service::strerror(int error)
15681571 return " No available address!" ;
15691572 case YERR_LOCAL_SHUTDOWN:
15701573 return " An existing connection was shutdown by local host!" ;
1574+ case YERR_INVALID_PACKET:
1575+ return " Invalid packet!" ;
15711576 case -1 :
15721577 return " Unknown error!" ;
15731578 default :
0 commit comments