//nwrt = write(sockfd,bufMap[sockfd].c_str(),200);// 模拟还有剩余
nwrt = write(sockfd,bufMap[sockfd].c_str(),nrcv);
if(nwrt < 0)
{
if( errno != EWOULDBLOCK)
{
printf("Write error: %s\n", strerror(errno));
}
}
printf("nwrt = %d \n",nwrt);
if(nwrt == nrcv) // 全部写到了内核缓冲区
{
bufMap[sockfd].clear();
//bufMap[sockfd].erase(0,nrcv);
if(FD_ISSET(sockfd,&wrset))
{
FD_CLR(sockfd,&wrset);
}
}
else // 还有剩余
{
printf("write left \n");
bufMap[sockfd].erase(0,nwrt);
std::cout << " after erase: "<<bufMap[sockfd] <<std::endl;
FD_SET(sockfd,&wrset);//开始关注写事件
}
}
else
{
int err = getSocketError(sockfd);
printf("SocketError: %s\n",strerror(err));
}
}
if(FD_ISSET(sockfd,&wrset))
{
nrcv = bufMap[sockfd].size();
printf("write again: nrcv left = %d \n",nrcv);
nwrt = write(sockfd,bufMap[sockfd].c_str(),nrcv);
if(nwrt == nrcv)
{
bufMap[sockfd].clear();
if(FD_ISSET(sockfd,&wrset))
{
FD_CLR(sockfd,&wrset);
}
printf("Write complete! \n");
}
else
{
bufMap[sockfd].erase(0,nwrt);
}
}
if(--nready == 0)
{
break;
}
}
}
return 0;
}