The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Typedefs | Enumerations | Functions
mem.h File Reference

Binary IO abstractions for memory buffers. More...

Go to the source code of this file.

Typedefs

typedef fr_bio_verify_action_t(* fr_bio_verify_t) (fr_bio_t *bio, void *verify_ctx, void *packet_ctx, const void *buffer, size_t *size)
 Verifies the packet. More...
 

Enumerations

enum  fr_bio_verify_action_t {
  FR_BIO_VERIFY_OK = 0 ,
  FR_BIO_VERIFY_DISCARD ,
  FR_BIO_VERIFY_WANT_MORE ,
  FR_BIO_VERIFY_ERROR_CLOSE
}
 Status returned by the verification callback. More...
 

Functions

fr_bio_tfr_bio_mem_alloc (TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next)
 Allocate a memory buffer bio. More...
 
void fr_bio_mem_read_discard (fr_bio_t *bio, size_t size)
 Discard data from the read buffer. More...
 
uint8_t const * fr_bio_mem_read_peek (fr_bio_t *bio, size_t *size)
 Peek at the data in the read buffer. More...
 
int fr_bio_mem_set_verify (fr_bio_t *bio, fr_bio_verify_t verify, void *verify_ctx, bool datagram)
 Set the verification function for memory bios. More...
 
fr_bio_tfr_bio_mem_sink_alloc (TALLOC_CTX *ctx, size_t buffer_size)
 Allocate a memory buffer which sinks data from a bio system into the callers application. More...
 
fr_bio_tfr_bio_mem_source_alloc (TALLOC_CTX *ctx, size_t buffer_size, fr_bio_t *next)
 Allocate a memory buffer which sources data from the callers application into the bio system. More...
 
int fr_bio_mem_write_resume (fr_bio_t *bio)
 See if we can resume writes to the memory bio. More...
 

Detailed Description

Binary IO abstractions for memory buffers.

Id
a3f9468b7a5322728113a0f13b0c4b814ee3ace3

Allow reads and writes from memory buffers

Definition in file mem.h.

Typedef Documentation

◆ fr_bio_verify_t

typedef fr_bio_verify_action_t(* fr_bio_verify_t) (fr_bio_t *bio, void *verify_ctx, void *packet_ctx, const void *buffer, size_t *size)

Verifies the packet.

If the packet is a dup, then this function can return DISCARD, or update the packet_ctx to say "dup", and then return OK.

Parameters
biothe bio to read
verify_ctxdata specific for verifying
packet_ctxas passed in to fr_bio_read()
bufferpointer to the raw data
[in,out]sizein: size of data in the buffer. out: size of the packet to return, or data to discard.
Returns
action to take

Definition at line 51 of file mem.h.

Enumeration Type Documentation

◆ fr_bio_verify_action_t

Status returned by the verification callback.

Enumerator
FR_BIO_VERIFY_OK 

packet is OK

FR_BIO_VERIFY_DISCARD 

the packet should be discarded

FR_BIO_VERIFY_WANT_MORE 

not enough data for one packet

FR_BIO_VERIFY_ERROR_CLOSE 

fatal error, the bio should be closed.

Definition at line 32 of file mem.h.

Function Documentation

◆ fr_bio_mem_alloc()

fr_bio_t* fr_bio_mem_alloc ( TALLOC_CTX *  ctx,
size_t  read_size,
size_t  write_size,
fr_bio_t next 
)

Allocate a memory buffer bio.

The "read buffer" will cache reads from the next bio in the chain. If the next bio returns more data than the caller asked for, the extra data is cached in the read buffer.

The "write buffer" will buffer writes to the next bio in the chain. If the caller writes more data than the next bio can process, the extra data is cached in the write buffer.

When the bio is closed (or freed) any pending data in the buffers is lost. The same happens if the next bio returns a fatal error.

At some point during a read, the next bio may return EOF. When that happens, the caller should not rely on the next FD being readable or writable. Instead, it should keep reading from the memory bio until it returns EOF. See fr_bio_fd_eof() for details.

Parameters
ctxthe talloc ctx
read_sizesize of the read buffer. Must be 1024..1^20
write_sizesize of the write buffer. Can be zero. If non-zero, must be 1024..1^20
nextthe next bio which will perform the underlying reads and writes.
  • NULL on error, memory allocation failed
  • !NULL the bio

Definition at line 727 of file mem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_mem_read_discard()

void fr_bio_mem_read_discard ( fr_bio_t bio,
size_t  size 
)

Discard data from the read buffer.

Discarding allows the caller to silently omit packets, so that they are not passed up to previous bios.

Definition at line 604 of file mem.c.

+ Here is the call graph for this function:

◆ fr_bio_mem_read_peek()

uint8_t const* fr_bio_mem_read_peek ( fr_bio_t bio,
size_t size 
)

Peek at the data in the read buffer.

Peeking at the data allows us to avoid many memory copies.

Definition at line 586 of file mem.c.

+ Here is the call graph for this function:

◆ fr_bio_mem_set_verify()

int fr_bio_mem_set_verify ( fr_bio_t bio,
fr_bio_verify_t  verify,
void *  verify_ctx,
bool  datagram 
)

Set the verification function for memory bios.

It is possible to add a verification function. It is not currently possible to remove one.

Parameters
biothe binary IO handler
verifythe verification function
datagramwhether or not this bio is a datagram one.
Returns
  • <0 on error
  • 0 on success

Definition at line 880 of file mem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_mem_sink_alloc()

fr_bio_t* fr_bio_mem_sink_alloc ( TALLOC_CTX *  ctx,
size_t  read_size 
)

Allocate a memory buffer which sinks data from a bio system into the callers application.

The caller reads data from this bio, but never writes to it. Upstream BIOs will source the data.

Definition at line 845 of file mem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_mem_source_alloc()

fr_bio_t* fr_bio_mem_source_alloc ( TALLOC_CTX *  ctx,
size_t  write_size,
fr_bio_t next 
)

Allocate a memory buffer which sources data from the callers application into the bio system.

The caller writes data to the buffer, but never reads from it. This bio will call the "next" bio to sink the data.

Definition at line 772 of file mem.c.

+ Here is the call graph for this function:

◆ fr_bio_mem_write_resume()

int fr_bio_mem_write_resume ( fr_bio_t bio)

See if we can resume writes to the memory bio.

Note that there is no equivalent fr_bio_mem_write_blocked(), as that function wouldn't do anything. Perhaps it could swap the write function to fr_bio_mem_write_buffer(), but the fr_bio_mem_write_next() function should automatically do that when the write to the next bio only writes part of the data, or if it returns fr_bio_error(IO_WOULD_BLOCK)

Definition at line 926 of file mem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: