static ssize_t tls_readv(struct wrap_io *wio, iovec_t *iov, int iovcnt) { struct gnutella_socket *s = wio->ctx; ssize_t ret, done; int i; g_assert(socket_uses_tls(s)); g_assert(iovcnt > 0); done = 0; ret = 0; for (i = 0; i < iovcnt; i++) { const size_t size = iovec_len(&iov[i]); ret = tls_read(wio, iovec_base(&iov[i]), size); if ((ssize_t) -1 == ret) break; done += (size_t) ret; if (size != (size_t) ret) break; } return done > 0 ? done : ret; }
/** * Write I/O vector. * * @return amount of bytes written, or -1 on error. */ static ssize_t tx_deflate_writev(txdrv_t *tx, iovec_t *iov, int iovcnt) { struct attr *attr = tx->opaque; int sent = 0; if (tx_deflate_debugging(9)) { g_debug("TX %s: (%s) (buffer #%d, nagle %s, unflushed %zu) [%c%c]", G_STRFUNC, gnet_host_to_string(&tx->host), attr->fill_idx, (attr->flags & DF_NAGLE) ? "on" : "off", attr->unflushed, (attr->flags & DF_FLOWC) ? 'C' : '-', (attr->flags & DF_FLUSH) ? 'f' : '-'); } while (iovcnt-- > 0) { int ret; /* * If we're flow controlled or shut down, stop sending. */ if (attr->flags & (DF_FLOWC|DF_SHUTDOWN)) break; ret = deflate_add(tx, iovec_base(iov), iovec_len(iov)); if (-1 == ret) return -1; sent += ret; if (UNSIGNED(ret) < iovec_len(iov)) { /* Could not write all, flow-controlled */ break; } iov++; } if (tx_deflate_debugging(9)) { g_debug("TX %s: (%s) sent %lu bytes (buffer #%d, nagle %s, " "unflushed %zu) [%c%c]", G_STRFUNC, gnet_host_to_string(&tx->host), (ulong) sent, attr->fill_idx, (attr->flags & DF_NAGLE) ? "on" : "off", attr->unflushed, (attr->flags & DF_FLOWC) ? 'C' : '-', (attr->flags & DF_FLUSH) ? 'f' : '-'); } return sent; }