queue.c
来自「srtp 1.0.1 比较适用于头一次看。其他版本的有需要也可以传上来。」· C语言 代码 · 共 62 行
C
62 行
/* * queue.c * * a byte queue, for buffering keystream and other data * * David A. McGrew * Cisco Systems, Inc. * */#include "err.h"/* * An octet_queue_t is a circular buffer holding some data. There * are four pointers: * * start the start of the buffer * end the end of the buffer * input the position of the next data to be input to the queue * output the position of the next data to be output from the queue * * Here's a diagram, with Xs indicating data in the buffer: * * +---------------+--------------------------------+---------------+ * |XXXXXXXXXXXXXXX| |XXXXXXXXXXXXXXX| * +---------------+--------------------------------+---------------+ * ^ ^ ^ ^ * | | | | * start input output end * * * Any number of octets can be output, but at least QUEUE_INPUT_MIN * octets must be entered at a time. * * */typedef struct { octet_t *start, *end, *input, *output; int length, data;} octet_queue_t;err_status_toctet_queue_alloc(octet_queue_t **queue, int len_octets) { octet_t *pointer; octet_queue_t *q; pointer = malloc(len_octets + sizeof(octet_queue_t)); if (!pointer) return err_status_alloc_err; q = (octet_queue_t *)pointer; q->start = pointer + sizeof(octet_queue_t); q->end = q->start + len_octets; q->input = q->start; q->output = NULL; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?