18,363
社区成员




int sendn(SOCKET fd,char *bp,int len)
{
int cnt;
int rc;
cnt=len;//要发送的字节数,即Length of the data in buf.
//用下面的这个while循环来保证,要发送的数据全部都被发送出去了。
while(cnt>0)
{
rc=send(fd,bp,cnt,0);
if(rc<0)
{
CString aaa;
aaa="发送错误\n";
// AfxGetMainWnd()->SendMessageToDescendants(WM_AGE1,(LPARAM)aaa.GetBuffer(0),1);
aaa.ReleaseBuffer();
return -1;
}
if(rc==0)
return len-cnt;
//发送完一批数据后,缓冲区指针要改变,
bp+=rc;
//Length of the data in buf也要变。
cnt-=rc;
}
return len;
}