unix/linux socket write函数的封装
int writecnta(int &sock,char *buf){ int length; int wlength; int tmpLength; tmpLength=0; length=strlen(buf); while(tmpLength != length) { wlength=write(sock,&buf[tmpLength]
·
int writecnta(int &sock,char *buf)
{
int length;
int wlength;
int tmpLength;
tmpLength=0;
length=strlen(buf);
while(tmpLength != length)
{
wlength=write(sock,&buf[tmpLength],length-tmpLength);
if(wlength < 0)
{
if( errno == EINTR )
{
wlength=0;
}
else
{
close(sock);
return 1;
}
}
else
{
tmpLength+=wlength;
}
}
return 0;
}
{
int length;
int wlength;
int tmpLength;
tmpLength=0;
length=strlen(buf);
while(tmpLength != length)
{
wlength=write(sock,&buf[tmpLength],length-tmpLength);
if(wlength < 0)
{
if( errno == EINTR )
{
wlength=0;
}
else
{
close(sock);
return 1;
}
}
else
{
tmpLength+=wlength;
}
}
return 0;
}
更多推荐
已为社区贡献2条内容
所有评论(0)