buffer usage

From: Vincent de RIBOU via skaware <skaware_at_list.skarnet.org>
Date: Wed, 24 Aug 2016 08:08:42 +0000 (UTC)

Laurent,
I am interested in using perfectly buffer component.I suceeded to read data from multicast socket one time but I am blocked thereafter.
my custom read callback returns the total bytes read.
static int listener_read(int fd, siovec_t const *io, unsigned int nb) {
    int nbytes=0;
    int total=0;
    fprintf(stderr, "listener_read, fd(%d), io(%p), nb(%d)\n", fd, io, nb);

    for(unsigned int i=0; i<nb; i++) {
        fprintf(stderr, "listener_read, io[%d].s(%p), io[%d].len(%d)\n", i, io[i].s, i, io[i].len);
        if(io[i].s) {
            nbytes=recvfrom(fd, io[i].s, io[i].len, 0, 0,0);
            if(nbytes < 0)
                return -1;
            else if(!nbytes)
                break;
            total+=nbytes;
        }
    }
    return total;
}
called with

lg=buffer_get(&listener_b, msg, 128);
the log and then hung on read syscall

1st loop
iopause ... sync, msg (toto) -> fill data in buffer
iopause ... flush -> send data on socket
sender_write, fd(4), io(0x22cb30), nb(2)
sender_write, io[0].s(0x40b040), io[0].len(4)
sender_write, io[1].s(0x0), io[1].len(0)
iopause ... get -> get data from socket
listener_read, fd(3), io(0x22cae0), nb(2)
listener_read, io[0].s(0x40b240), io[0].len(511)
listener_read, io[1].s(0x0), io[1].len(0)
listener_read, fd(3), io(0x22cae0), nb(2)
listener_read, io[0].s(0x40b244), io[0].len(508)
msg: (toto) -> data read

2nd loop
iopause ... sync, msg (toto)
iopause ... flush
sender_write, fd(4), io(0x22cb30), nb(2)
sender_write, io[0].s(0x40b044), io[0].len(4)
sender_write, io[1].s(0x0), io[1].len(0)
iopause ... get
listener_read, fd(3), io(0x22cae0), nb(2)
listener_read, io[0].s(0x40b244), io[0].len(508)
listener_read, io[1].s(0x40b240), io[1].len(3)
listener_read, fd(3), io(0x22cae0), nb(2)
listener_read, io[0].s(0x40b248), io[0].len(504)

Did i implement my custoim callback correctly?Regards,
 Vincent de RIBOU région Ouest - France belzo2005-dolphin_at_yahoo.fr
Received on Wed Aug 24 2016 - 08:08:42 UTC

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