while(bytesSent < amount )
while ((rv = send(osfd,buf,amount,flags)) == -1)
_PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,            PRIntervalTime timeout){    PRInt32 osfd = fd->secret->md.osfd;    PRInt32 rv, err;#ifdef BSD_SELECT    struct timeval tv, *tvp;    fd_set wd;#else    int socks[1];     long lTimeout = -1; #endif    PRInt32 bytesSent = 0;    while(bytesSent < amount )     {        while ((rv = send( osfd, (char *) buf, amount, 0 )) == -1)         {            if (((err = sock_errno()) == EWOULDBLOCK)                 && (!fd->secret->nonblocking))            {#ifdef BSD_SELECT                if ( timeout == PR_INTERVAL_NO_TIMEOUT )                 {                    tvp = NULL;                }                 else                 {                    tv.tv_sec = PR_IntervalToSeconds(timeout);                    tv.tv_usec = PR_IntervalToMicroseconds(                        timeout - PR_SecondsToInterval(tv.tv_sec));                    tvp = &tv;                }                FD_ZERO(&wd);                FD_SET(osfd, &wd);                if ((rv = _MD_SELECT( osfd + 1, NULL, &wd, NULL,tvp)) == -1) {#else                if ( timeout == PR_INTERVAL_NO_TIMEOUT )                 {                    lTimeout = -1;                 }                 else                 {                    lTimeout = PR_IntervalToMilliseconds(timeout);                 }                socks[0] = osfd;                 if ((rv = _MD_SELECT( socks, 0, 1, 0, lTimeout)) == -1) {#endif                    _PR_MD_MAP_SELECT_ERROR(sock_errno());                    break;                }                if (rv == 0)                 {                    PR_SetError(PR_IO_TIMEOUT_ERROR, 0);                    return -1;                }            }             else {                _PR_MD_MAP_SEND_ERROR(err);                return -1;            }        }        bytesSent += rv;        if (fd->secret->nonblocking)        {            break;        }        if ((rv >= 0) && (bytesSent < amount ))         {#ifdef BSD_SELECT           if ( timeout == PR_INTERVAL_NO_TIMEOUT )            {               tvp = NULL;           }            else            {               tv.tv_sec = PR_IntervalToSeconds(timeout);               tv.tv_usec = PR_IntervalToMicroseconds(                   timeout - PR_SecondsToInterval(tv.tv_sec));               tvp = &tv;           }           FD_ZERO(&wd);           FD_SET(osfd, &wd);           if ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL,tvp)) == -1) {#else            if ( timeout == PR_INTERVAL_NO_TIMEOUT )             {                lTimeout = -1;             }             else             {                lTimeout = PR_IntervalToMilliseconds(timeout);             }            socks[0] = osfd;             if ((rv = _MD_SELECT(socks, 0, 1, 0,lTimeout)) == -1) {#endif                _PR_MD_MAP_SELECT_ERROR(sock_errno());                break;            }            if (rv == 0)             {                PR_SetError(PR_IO_TIMEOUT_ERROR, 0);                return -1;            }        }    }    return bytesSent;}