The use of errno when the send () function and recev function report errors

1. The return value of the recev () function:

> 0: received data size;

= 0: the connection is closed;

<0: Error.

 In case of error,

Under these three errors, the connection is considered to be normal and continue to receive

if(errno == EINTR ||(errno == EAGAIN)||errno == EWOULDBLOCK)
                    continue;

if(FD_ISSET(connfd,&r_set)
    {
        int irecv,iunrecv;
        iunrecv = length;
        while(iunrecv>0)
        {
            irecv = recv(concfd,buff,iunrecv,0)
            if(irecv==0)
            {
                 printf("recv error:%s",strerror(errno));
                 return -1;
            }
            if(irecv<0)            
            {
                if(errno == EINTR ||(errno == EAGAIN)||errno == EWOULDBLOCK)
                    continue;

                 printf("recv error:%s",strerror(errno));
                 return -1;
            }
            iunrecv -= irecv;
            buff += irecv;
        }
    }

 

 

 

Published 100 original articles · won 26 · 20,000+ views

Guess you like

Origin blog.csdn.net/modi000/article/details/105605034