Re: buffer usage

From: Vincent de RIBOU via skaware <skaware_at_list.skarnet.org>
Date: Thu, 25 Aug 2016 06:24:04 +0000 (UTC)

complete code heremain.c

|   |
|   | |   |   |   |   |   |
| main.cCreate a gist now Instantly share code, notes, and snippets. |
| |
| Afficher sur gist.github.com | Aperçu par Yahoo |
| |
|   |

 Vincent de RIBOU région Ouest - France belzo2005-dolphin_at_yahoo.fr

    Le Jeudi 25 août 2016 8h22, Vincent de RIBOU via skaware <skaware_at_list.skarnet.org> a écrit :
 

 Hi Laurent,
In fact I face my CB in using 2 calls of 'read' blocked on 2nd call throgu 'buffer_fill', but when using 2 'readv' calls it ends on 0 return code at 2nd call, so succeeds.I don't understand why 'read' can block when 'readv' only ends with nothing read.
My CB implementation is :
CALLER        if (x[4].revents & IOPAUSE_READ) {
            char msg[128];
            int lg=0;
            ERRORLOG("get\n");
            lg=buffer_get(&listener_b, msg, 128);
            if (lg < 0) {
                perror("buffer_get");
                break;
            }
            msg[lg]=0;    // just for printing
            BASIC_LOG("msg: lg(%d)\n", msg);
        }
CBstatic int listener_read(int fd, siovec_t const *io, unsigned int nb) {
    int total=0;
    unsigned i;
    ERRORLOG("listener_read, fd(%d), io(%p), nb(%d)\n", fd, io, nb);
    for(i=0; i<nb; i++) {
        ERRORLOG("listener_read 1, io[%d].s(%p), io[%d].len(%d)\n", i, io[i].s, i, io[i].len);
    }

#if 0   // blocks on 2 call from buffer_fill
    int nbytes=0;
    unsigned tmp=0;
    // still hung at read when nothing readable
    i=0;
    while(i<nb) {
        fprintf(stderr, "tmp(%u)\n", tmp);
        if(io[i].s) {
            int addrlen=sizeof(struct sockaddr);
            nbytes=read(fd, io[i].s+tmp, io[i].len-tmp);
            if((nbytes < 0) && (errno!=EINTR))
                return -1;
            else if(!nbytes) {
                ERRORLOG("nothing read\n");
                break;
            }
            total+=nbytes;
            tmp+=nbytes;
        }
        if(tmp<=io[i].len) {
            if(tmp<io[i].len) {
                ERRORLOG("partial read\n");
                continue;
            }
            else {
                ERRORLOG("not possible\n");
            }
        }
        if(total) {
            ERRORLOG("data read\n");
            break;
        }
       
        tmp=0;
        i++;
    }
#else
   
    total = fd_readsv(fd, io, nb);
       
#endif

    ERRORLOG("total (%d)\n", total);
    return total;
}

Regards,
 Vincent de RIBOU région Ouest - France belzo2005-dolphin_at_yahoo.fr

    Le Mercredi 24 août 2016 14h00, Laurent Bercot <ska-skaware_at_skarnet.org> a écrit :
 

 On 24/08/2016 11:39, Vincent de RIBOU via skaware wrote:
> Laurent,
> maybe I was not clear enough.
> in my buffer CB, set at init, I used 'fd_readsv' instead of my 'listener_read' CB and it works.but it uses 'readv' instead of my 'recvfrom' syscall. not so painfull but in this way I can't know the ID of peer.

  Indeed, that's not clear.
  I have no idea what your architecture is, what you're trying to accomplish,
what you're having trouble with and what your precise questions are.

  Please detail your questions, and give a pointer to the code, if possible;
if not, please at least write some general pseudocode to explain what it
does, and give a little context. It's the only way we can help you. :)

-- 
  Laurent
  
Received on Thu Aug 25 2016 - 06:24:04 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC