// File: /workspace/github_cpp_makefile_star2_O1/xocoder[P]m_kcptun/src/kcp_local.cpp
// Function: local_tcpin_callback(chann_msg_t*)
void
_local_tcpin_callback(chann_msg_t *e) {
   session_unit_t *u = (session_unit_t*)e->opaque;
   tun_local_t *tun = (tun_local_t*)u->opaque;

   switch (e->event) {

      case CHANN_EVENT_RECV: {
         if ( u->connected ) {
            const int mss = tun->kcpout->mss - MKCP_OVERHEAD;
            long chann_ret = 0;
            do {
               int offset = proto_mark_data(tun->buf, u->sid);
               chann_ret = mnet_chann_recv(e->n, &tun->buf[offset], mss - offset);

               if (chann_ret > 0 && _local_kcp_can_send_more(tun)) {
                  int kcp_ret = ikcp_send(tun->kcpout, (const char*)tun->buf, chann_ret + offset);
                  if (kcp_ret < 0) {
                     cerr << "Fail to send kcp " << kcp_ret << endl;
                  }
               }
            } while (chann_ret > 0);
         }
         break;
      }

      case CHANN_EVENT_DISCONNECT:  {

         // send disconnect msg
         if ( _local_kcp_can_send_more(tun) ) {
            unsigned char buf[16] = { 0 };
            if ( proto_mark_cmd(buf, u->sid, PROTO_CMD_CLOSE) ) {
               ikcp_send(tun->kcpout, (const char*)buf, 16);
            }
         }

         session_destroy(tun->session_lst, u);
         mnet_chann_close(e->n);

         cout << "local tcp error or disconnect !" << endl;
         break;
      }

      default: {
         break;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq %rax, -0x30(%rbp)
movq 0x18(%rax), %r14
movl (%rdi), %eax
cmpl $0x5, %eax
je 0x8c6f
cmpl $0x1, %eax
jne 0x8d11
movq -0x30(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x8d11
movq 0x48(%r14), %rax
movl 0x8(%rax), %r12d
addl $-0x18, %r12d
leaq 0x98(%r14), %r15
movq -0x30(%rbp), %rax
movl (%rax), %esi
movq %r15, %rdi
callq 0x71ec
movl %eax, %r13d
movq 0x8(%rbx), %rdi
cltq
leaq (%r14,%rax), %rsi
addq $0x98, %rsi
movl %r12d, -0x34(%rbp)
movl %r12d, %edx
subl %r13d, %edx
callq 0x4c63
testl %eax, %eax
jle 0x8d11
movl %eax, %r12d
movq 0x48(%r14), %rdi
callq 0x3f05
movq 0x78(%r14), %rcx
movl 0x12c(%rcx), %ecx
leal (%rcx,%rcx,2), %ecx
cmpl %ecx, %eax
jge 0x8c3a
movq 0x48(%r14), %rdi
addl %r13d, %r12d
movq %r15, %rsi
movl %r12d, %edx
callq 0x2cc4
testl %eax, %eax
jns 0x8c3a
movl %eax, %r12d
movl $0x11, %edx
movq 0x73fa(%rip), %r13      # 0xfff0
movq %r13, %rdi
leaq 0x33f9(%rip), %rsi      # 0xbff9
callq 0x22e0
movq %r13, %rdi
movl %r12d, %esi
callq 0x2400
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2270
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x21d0
movq -0x30(%rbp), %rax
movl (%rax), %esi
movq %r15, %rdi
callq 0x71ec
movl %eax, %r13d
movq 0x8(%rbx), %rdi
cltq
leaq (%r15,%rax), %rsi
movl -0x34(%rbp), %edx
subl %eax, %edx
callq 0x4c63
movl %eax, %r12d
testl %eax, %eax
jg 0x8bb7
jmp 0x8d11
movq 0x48(%r14), %rdi
callq 0x3f05
movq 0x78(%r14), %rcx
movl 0x12c(%rcx), %ecx
leal (%rcx,%rcx,2), %ecx
cmpl %ecx, %eax
jge 0x8cb9
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rdi
movaps %xmm0, (%rdi)
movq -0x30(%rbp), %rax
movl (%rax), %esi
movl $0x3, %edx
callq 0x71bd
testl %eax, %eax
je 0x8cb9
movq 0x48(%r14), %rdi
leaq -0x50(%rbp), %rsi
movl $0x10, %edx
callq 0x2cc4
movq 0x50(%r14), %rdi
movq -0x30(%rbp), %rsi
callq 0x905a
movq 0x8(%rbx), %rdi
callq 0x464a
movq 0x72fa(%rip), %rbx      # 0xffd0
leaq 0x332e(%rip), %rsi      # 0xc00b
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x22e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x21d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq