Tor
0.4.7.0-alpha-dev
|
Read and write data on a buf_t object. More...
#include "lib/net/buffers_net.h"
#include "lib/buf/buffers.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/net/nettypes.h"
#include <stdlib.h>
Go to the source code of this file.
Macros | |
#define | BUFFERS_PRIVATE |
#define | check() STMT_NIL |
Functions | |
static int | read_to_chunk (buf_t *buf, chunk_t *chunk, tor_socket_t fd, size_t at_most, int *reached_eof, int *error, bool is_socket) |
static int | buf_read_from_fd (buf_t *buf, int fd, size_t at_most, int *reached_eof, int *socket_error, bool is_socket) |
static int | flush_chunk (tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz, bool is_socket) |
static int | buf_flush_to_fd (buf_t *buf, int fd, size_t sz, bool is_socket) |
int | buf_flush_to_socket (buf_t *buf, tor_socket_t s, size_t sz) |
int | buf_read_from_socket (buf_t *buf, tor_socket_t s, size_t at_most, int *reached_eof, int *socket_error) |
int | buf_flush_to_pipe (buf_t *buf, int fd, size_t sz) |
int | buf_read_from_pipe (buf_t *buf, int fd, size_t at_most, int *reached_eof, int *socket_error) |
Read and write data on a buf_t object.
Definition in file buffers_net.c.
|
static |
Write data from buf to the file descriptor fd. Write at most sz bytes, and remove the written bytes from the buffer. Return the number of bytes written on success, -1 on failure. Return 0 if write() would block.
Definition at line 182 of file buffers_net.c.
Referenced by buf_flush_to_pipe(), and buf_flush_to_socket().
int buf_flush_to_pipe | ( | buf_t * | buf, |
int | fd, | ||
size_t | sz | ||
) |
Write data from buf to the pipe fd. Write at most sz bytes, decrement *buf_flushlen by the number of bytes actually written, and remove the written bytes from the buffer. Return the number of bytes written on success, -1 on failure. Return 0 if write() would block.
Definition at line 249 of file buffers_net.c.
int buf_flush_to_socket | ( | buf_t * | buf, |
tor_socket_t | s, | ||
size_t | sz | ||
) |
Write data from buf to the socket s. Write at most sz bytes, decrement *buf_flushlen by the number of bytes actually written, and remove the written bytes from the buffer. Return the number of bytes written on success, -1 on failure. Return 0 if write() would block.
Definition at line 224 of file buffers_net.c.
|
static |
Read from file descriptor fd, writing onto end of buf. Read at most at_most bytes, growing the buffer as necessary. If recv() returns 0 (because of EOF), set *reached_eof to 1 and return 0. Return -1 on error; else return the number of bytes read.
Definition at line 91 of file buffers_net.c.
Referenced by buf_read_from_pipe(), and buf_read_from_socket().
int buf_read_from_pipe | ( | buf_t * | buf, |
int | fd, | ||
size_t | at_most, | ||
int * | reached_eof, | ||
int * | socket_error | ||
) |
Read from pipe fd, writing onto end of buf. Read at most at_most bytes, growing the buffer as necessary. If read() returns 0 (because of EOF), set *reached_eof to 1 and return 0. Return -1 on error; else return the number of bytes read.
Definition at line 260 of file buffers_net.c.
Referenced by process_unix_read_handle().
int buf_read_from_socket | ( | buf_t * | buf, |
tor_socket_t | s, | ||
size_t | at_most, | ||
int * | reached_eof, | ||
int * | socket_error | ||
) |
Read from socket s, writing onto end of buf. Read at most at_most bytes, growing the buffer as necessary. If recv() returns 0 (because of EOF), set *reached_eof to 1 and return 0. Return -1 on error; else return the number of bytes read.
Definition at line 235 of file buffers_net.c.
|
inlinestatic |
Helper for buf_flush_to_socket(): try to write sz bytes from chunk chunk of buffer buf onto file descriptor fd. Return the number of bytes written on success, 0 on blocking, -1 on failure.
Definition at line 144 of file buffers_net.c.
|
inlinestatic |
Read up to at_most bytes from the file descriptor fd into chunk (which must be on buf). If we get an EOF, set *reached_eof to 1. Uses tor_socket_recv() iff is_socket is true, otherwise it uses read(). Return -1 on error (and sets *error to errno), 0 on eof or blocking, and the number of bytes read otherwise.
Definition at line 44 of file buffers_net.c.