ikcp_send 返回成功发送的字节数,-1 为错误,-2 为 EAGAIN

This commit is contained in:
skywind3000 2023-05-07 13:49:56 +08:00
parent c0cb6ab3ac
commit f2aa30ea21

13
ikcp.c
View File

@ -470,7 +470,7 @@ int ikcp_send(ikcpcb *kcp, const char *buffer, int len)
{
IKCPSEG *seg;
int count, i;
int append = 0;
int sent = 0;
assert(kcp->mss > 0);
if (len < 0) return -1;
@ -498,11 +498,11 @@ int ikcp_send(ikcpcb *kcp, const char *buffer, int len)
len -= extend;
iqueue_del_init(&old->node);
ikcp_segment_delete(kcp, old);
append = extend;
sent = extend;
}
}
if (len <= 0) {
return 0;
return sent;
}
}
@ -510,8 +510,8 @@ int ikcp_send(ikcpcb *kcp, const char *buffer, int len)
else count = (len + kcp->mss - 1) / kcp->mss;
if (count >= (int)IKCP_WND_RCV) {
if (kcp->stream != 0 && append > 0)
return append;
if (kcp->stream != 0 && sent > 0)
return sent;
return -2;
}
@ -537,9 +537,10 @@ int ikcp_send(ikcpcb *kcp, const char *buffer, int len)
buffer += size;
}
len -= size;
sent += size;
}
return 0;
return sent;
}