stream: Add byte counters
parent
e862347ab5
commit
e1c0923915
|
@ -18,6 +18,8 @@
|
||||||
#include "sys/queue.h"
|
#include "sys/queue.h"
|
||||||
#include "rcbuf.h"
|
#include "rcbuf.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef ENABLE_TLS
|
#ifdef ENABLE_TLS
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -73,6 +75,9 @@ struct stream {
|
||||||
#ifdef ENABLE_TLS
|
#ifdef ENABLE_TLS
|
||||||
gnutls_session_t tls_session;
|
gnutls_session_t tls_session;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint32_t bytes_sent;
|
||||||
|
uint32_t bytes_received;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stream* stream_new(int fd, stream_event_fn on_event, void* userdata);
|
struct stream* stream_new(int fd, stream_event_fn on_event, void* userdata);
|
||||||
|
|
10
src/stream.c
10
src/stream.c
|
@ -136,6 +136,8 @@ static int stream__flush_plain(struct stream* self)
|
||||||
return bytes_sent;
|
return bytes_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->bytes_sent += bytes_sent;
|
||||||
|
|
||||||
ssize_t bytes_left = bytes_sent;
|
ssize_t bytes_left = bytes_sent;
|
||||||
|
|
||||||
struct stream_req* tmp;
|
struct stream_req* tmp;
|
||||||
|
@ -181,6 +183,8 @@ static int stream__flush_tls(struct stream* self)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->bytes_sent += rc;
|
||||||
|
|
||||||
ssize_t remaining = req->payload->size - rc;
|
ssize_t remaining = req->payload->size - rc;
|
||||||
|
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
|
@ -336,6 +340,8 @@ static ssize_t stream__read_plain(struct stream* self, void* dst, size_t size)
|
||||||
ssize_t rc = read(self->fd, dst, size);
|
ssize_t rc = read(self->fd, dst, size);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
stream__remote_closed(self);
|
stream__remote_closed(self);
|
||||||
|
if (rc > 0)
|
||||||
|
self->bytes_received += rc;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,8 +349,10 @@ static ssize_t stream__read_plain(struct stream* self, void* dst, size_t size)
|
||||||
static ssize_t stream__read_tls(struct stream* self, void* dst, size_t size)
|
static ssize_t stream__read_tls(struct stream* self, void* dst, size_t size)
|
||||||
{
|
{
|
||||||
ssize_t rc = gnutls_record_recv(self->tls_session, dst, size);
|
ssize_t rc = gnutls_record_recv(self->tls_session, dst, size);
|
||||||
if (rc >= 0)
|
if (rc >= 0) {
|
||||||
|
self->bytes_received += rc;
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case GNUTLS_E_INTERRUPTED:
|
case GNUTLS_E_INTERRUPTED:
|
||||||
|
|
Loading…
Reference in New Issue