SUMMARY: alfs direction

Subhash Chandra mr.subhash at gmail.com
Fri Nov 25 19:12:56 PST 2005


> The way it currently sends strings across needs some major error
> checking going on, too. send() and recv() isn't always reliable in
> communicating a long string.
int sende(int socket, char *string, size_t size, int FLAGS)
{
        int s=strlen(string);
        int nbytes=0;
        int sbytes=0;
        while((nbytes+=sbytes)<s)
        {
                 if((sbytes=send(socket, string+nbytes, size-nbytes+1,
FLAGS))==-1)
                         {
                                     perror("send");
                                     return -1;
                         }
        }
        return nbytes;
}

int recve(int socket, char *string,size_t size,int FLAGS)
{
        int nbytes=0;
        int sbytes=0;
        while(*(string+(nbytes+=sbytes))!='\0')
        {
                 if((sbytes=recv(socket, string+nbytes, size-nbytes+1,
FLAGS))==-1)
                         {
                                     perror("send");
                                     return -1;
                         }
        }
        return nbytes;
}

This works fairly well for long strings; use recve and sende instead
of the recv and send.

***Didn't make extansive checks, lack time

--
╔════════════════════════════╗
║I don't know how much of what I say is true ║
╚════════════════════════════╝


More information about the alfs-discuss mailing list