Diff for /libaitio/src/bpf.c between versions 1.1.2.18 and 1.1.2.19

version 1.1.2.18, 2013/06/26 15:31:17 version 1.1.2.19, 2013/06/26 16:22:12
Line 232  chkZCbuf(struct bpf_zbuf_header *bzh) Line 232  chkZCbuf(struct bpf_zbuf_header *bzh)
 }  }
   
 static inline ssize_t  static inline ssize_t
nextZCbuf(int eth, void ** __restrict zcache, struct bpf_zbuf * __restrict zbuf)nextZCbuf(int eth, struct bpf_zbuf * __restrict zbuf, void * __restrict buf, size_t buflen)
 {  {
         ssize_t rlen = 0;          ssize_t rlen = 0;
           struct bpf_zbuf bz;
         struct bpf_zbuf_header *bzh;          struct bpf_zbuf_header *bzh;
           off_t pos = 0;
   
        if (!*zcache || *zcache == zbuf->bz_bufb) {        bzh = (struct bpf_zbuf_header *) zbuf->bz_bufa;
                bzh = (struct bpf_zbuf_header *) zbuf->bz_bufa;        if (chkZCbuf(bzh)) {
                if (chkZCbuf(bzh)) {                rlen = MIN(atomic_load_acq_int(&bzh->bzh_kernel_len), buflen);
                        *zcache = zbuf->bz_bufa;                memcpy(buf + pos, zbuf->bz_bufa + sizeof(struct bpf_zbuf_header), rlen);
                        rlen = atomic_load_acq_int(&bzh->bzh_kernel_len);                ackZCbuf(bzh);
                }                pos += rlen;
        } else if (*zcache == zbuf->bz_bufa) { 
                bzh = (struct bpf_zbuf_header *) zbuf->bz_bufb; 
                if (chkZCbuf(bzh)) { 
                        *zcache = zbuf->bz_bufb; 
                        rlen = atomic_load_acq_int(&bzh->bzh_kernel_len); 
                } 
         }          }
           bzh = (struct bpf_zbuf_header *) zbuf->bz_bufb;
           if (chkZCbuf(bzh)) {
                   rlen = MIN(atomic_load_acq_int(&bzh->bzh_kernel_len), buflen);
                   memcpy(buf + pos, zbuf->bz_bufb + sizeof(struct bpf_zbuf_header), rlen);
                   ackZCbuf(bzh);
                   pos += rlen;
           }
   
           if (!pos)
                   ioctl(eth, BIOCROTZBUF, &bz);
         return rlen;          return rlen;
 }  }
 #endif  #endif
Line 268  ssize_t Line 273  ssize_t
 io_etherRecv(int eth, void * __restrict buf, size_t buflen, void * __restrict zcbuf)  io_etherRecv(int eth, void * __restrict buf, size_t buflen, void * __restrict zcbuf)
 {  {
         ssize_t rlen = 0;          ssize_t rlen = 0;
         void *zcache = NULL;  
 #ifdef __FreeBSD__  
         struct bpf_zbuf bz;  
         struct bpf_zbuf_header *bzh;  
 #else  
         if (zcbuf) {  
                 io_SetErr(ENOTSUP, "bpf zero copy buffer mode is not supported");  
                 return -1;  
         }  
 #endif  
   
         if (!buf || !buflen) {          if (!buf || !buflen) {
                 io_SetErr(EINVAL, "invalid arguments");                  io_SetErr(EINVAL, "invalid arguments");
Line 291  io_etherRecv(int eth, void * __restrict buf, size_t bu Line 286  io_etherRecv(int eth, void * __restrict buf, size_t bu
         } else {          } else {
 #ifdef __FreeBSD__  #ifdef __FreeBSD__
                 do {                  do {
                        rlen = nextZCbuf(eth, &zcache, (struct bpf_zbuf*) zcbuf);                        rlen = nextZCbuf(eth, (struct bpf_zbuf*) zcbuf, buf, buflen);
                        if (rlen > 0) {                        if (!rlen)
                                bzh = (struct bpf_zbuf_header*) zcache; 
                                memcpy(buf, zcache + sizeof(struct bpf_zbuf_header),  
                                                MIN(buflen, rlen)); 
                        } 
                        if (!rlen && !ioctl(eth, BIOCROTZBUF, &bz)) 
                                 continue;                                  continue;
                 } while (0);                  } while (0);
 #else  #else

Removed from v.1.1.2.18  
changed lines
  Added in v.1.1.2.19


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>