Commit 200921dc authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

Refactor users of buf_datalen to bufferevent-friendly version.

parent 57e7b54b
Loading
Loading
Loading
Loading
+2 −5
Changes for src/or/connection.c: 2 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -36,10 +36,6 @@
#include "router.h"
#include "routerparse.h"

#ifdef USE_BUFFEREVENTS
#include <event2/bufferevent.h>
#endif

static connection_t *connection_create_listener(
                               struct sockaddr *listensockaddr,
                               socklen_t listensocklen, int type,
@@ -381,7 +377,8 @@ _connection_free(connection_t *conn)
             "bytes on inbuf, %d on outbuf.",
             conn_type_to_string(conn->type),
             conn_state_to_string(conn->type, conn->state),
             (int)buf_datalen(conn->inbuf), (int)buf_datalen(conn->outbuf));
             (int)connection_get_inbuf_len(conn),
             (int)connection_get_outbuf_len(conn));
  }

  if (!connection_is_listener(conn)) {
+28 −0
Changes for src/or/connection.h: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,11 @@
#ifndef _TOR_CONNECTION_H
#define _TOR_CONNECTION_H

#ifndef USE_BUFFEREVENTS
/* XXXX For buf_datalen in inline function */
#include "buffers.h"
#endif

const char *conn_type_to_string(int type);
const char *conn_state_to_string(int type, int state);

@@ -73,6 +78,29 @@ connection_write_to_buf_zlib(const char *string, size_t len,
  _connection_write_to_buf_impl(string, len, TO_CONN(conn), done ? -1 : 1);
}

static size_t connection_get_inbuf_len(connection_t *conn);
static size_t connection_get_outbuf_len(connection_t *conn);

static INLINE size_t
connection_get_inbuf_len(connection_t *conn)
{
  IF_HAS_BUFFEREVENT(conn, {
    return evbuffer_get_length(bufferevent_get_input(conn->bufev));
  }) ELSE_IF_NO_BUFFEREVENT {
    return buf_datalen(conn->inbuf);
  }
}

static INLINE size_t
connection_get_outbuf_len(connection_t *conn)
{
  IF_HAS_BUFFEREVENT(conn, {
    return evbuffer_get_length(bufferevent_get_output(conn->bufev));
  }) ELSE_IF_NO_BUFFEREVENT {
    return buf_datalen(conn->outbuf);
  }
}

connection_t *connection_get_by_global_id(uint64_t id);

connection_t *connection_get_by_type(int type);
+1 −1
Changes for src/or/connection_edge.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason,
int
connection_edge_reached_eof(edge_connection_t *conn)
{
  if (buf_datalen(conn->_base.inbuf) &&
  if (connection_get_inbuf_len(TO_CONN(conn)) &&
      connection_state_is_open(TO_CONN(conn))) {
    /* it still has stuff to process. don't let it die yet. */
    return 0;
+4 −4
Changes for src/or/connection_or.c: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ connection_or_process_inbuf(or_connection_t *conn)
int
connection_or_flushed_some(or_connection_t *conn)
{
  size_t datalen = buf_datalen(conn->_base.outbuf);
  size_t datalen = connection_get_outbuf_len(TO_CONN(conn));
  /* If we're under the low water mark, add cells until we're just over the
   * high water mark. */
  if (datalen < OR_CONN_LOWWATER) {
@@ -1277,7 +1277,7 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
  while (1) {
    log_debug(LD_OR,
              "%d: starting, inbuf_datalen %d (%d pending in tls object).",
              conn->_base.s,(int)buf_datalen(conn->_base.inbuf),
              conn->_base.s,(int)connection_get_inbuf_len(TO_CONN(conn)),
              tor_tls_get_pending_bytes(conn->tls));
    if (connection_fetch_var_cell_from_buf(conn, &var_cell)) {
      if (!var_cell)
@@ -1288,8 +1288,8 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
    } else {
      char buf[CELL_NETWORK_SIZE];
      cell_t cell;
      if (buf_datalen(conn->_base.inbuf) < CELL_NETWORK_SIZE) /* whole response
                                                                 available? */
      if (connection_get_inbuf_len(TO_CONN(conn))
          < CELL_NETWORK_SIZE) /* whole response available? */
        return 0; /* not yet */

      circuit_build_times_network_is_live(&circ_times);
+1 −1
Changes for src/or/cpuworker.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ connection_cpu_process_inbuf(connection_t *conn)
  tor_assert(conn);
  tor_assert(conn->type == CONN_TYPE_CPUWORKER);

  if (!buf_datalen(conn->inbuf))
  if (!connection_get_inbuf_len(conn))
    return 0;

  if (conn->state == CPUWORKER_STATE_BUSY_ONION) {
Loading