Re: buffer usage

From: Vincent de RIBOU via skaware <>
Date: Thu, 25 Aug 2016 06:21:36 +0000 (UTC)

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;
            lg=buffer_get(&listener_b, msg, 128);
            if (lg < 0) {
            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
    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");
        if(tmp<=io[i].len) {
            if(tmp<io[i].len) {
                ERRORLOG("partial read\n");
            else {
                ERRORLOG("not possible\n");
        if(total) {
            ERRORLOG("data read\n");
    total = fd_readsv(fd, io, nb);

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

 Vincent de RIBOU région Ouest - France

    Le Mercredi 24 août 2016 14h00, Laurent Bercot <> 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. :)

Received on Thu Aug 25 2016 - 06:21:36 UTC

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