1BIO_s_mem(3) OpenSSL BIO_s_mem(3)
2
3
4
6 BIO_s_mem, BIO_set_mem_eof_return, BIO_get_mem_data, BIO_set_mem_buf,
7 BIO_get_mem_ptr, BIO_new_mem_buf - memory BIO
8
10 #include <openssl/bio.h>
11
12 BIO_METHOD * BIO_s_mem(void);
13
14 BIO_set_mem_eof_return(BIO *b,int v)
15 long BIO_get_mem_data(BIO *b, char **pp)
16 BIO_set_mem_buf(BIO *b,BUF_MEM *bm,int c)
17 BIO_get_mem_ptr(BIO *b,BUF_MEM **pp)
18
19 BIO *BIO_new_mem_buf(const void *buf, int len);
20
22 BIO_s_mem() return the memory BIO method function.
23
24 A memory BIO is a source/sink BIO which uses memory for its I/O. Data
25 written to a memory BIO is stored in a BUF_MEM structure which is
26 extended as appropriate to accommodate the stored data.
27
28 Any data written to a memory BIO can be recalled by reading from it.
29 Unless the memory BIO is read only any data read from it is deleted
30 from the BIO.
31
32 Memory BIOs support BIO_gets() and BIO_puts().
33
34 If the BIO_CLOSE flag is set when a memory BIO is freed then the
35 underlying BUF_MEM structure is also freed.
36
37 Calling BIO_reset() on a read write memory BIO clears any data in it.
38 On a read only BIO it restores the BIO to its original state and the
39 read only data can be read again.
40
41 BIO_eof() is true if no data is in the BIO.
42
43 BIO_ctrl_pending() returns the number of bytes currently stored.
44
45 BIO_set_mem_eof_return() sets the behaviour of memory BIO b when it is
46 empty. If the v is zero then an empty memory BIO will return EOF (that
47 is it will return zero and BIO_should_retry(b) will be false. If v is
48 non zero then it will return v when it is empty and it will set the
49 read retry flag (that is BIO_read_retry(b) is true). To avoid ambiguity
50 with a normal positive return value v should be set to a negative
51 value, typically -1.
52
53 BIO_get_mem_data() sets *pp to a pointer to the start of the memory
54 BIOs data and returns the total amount of data available. It is
55 implemented as a macro.
56
57 BIO_set_mem_buf() sets the internal BUF_MEM structure to bm and sets
58 the close flag to c, that is c should be either BIO_CLOSE or
59 BIO_NOCLOSE. It is a macro.
60
61 BIO_get_mem_ptr() places the underlying BUF_MEM structure in *pp. It is
62 a macro.
63
64 BIO_new_mem_buf() creates a memory BIO using len bytes of data at buf,
65 if len is -1 then the buf is assumed to be nul terminated and its
66 length is determined by strlen. The BIO is set to a read only state and
67 as a result cannot be written to. This is useful when some data needs
68 to be made available from a static area of memory in the form of a BIO.
69 The supplied data is read directly from the supplied buffer: it is not
70 copied first, so the supplied area of memory must be unchanged until
71 the BIO is freed.
72
74 Writes to memory BIOs will always succeed if memory is available: that
75 is their size can grow indefinitely.
76
77 Every read from a read write memory BIO will remove the data just read
78 with an internal copy operation, if a BIO contains a lot of data and it
79 is read in small chunks the operation can be very slow. The use of a
80 read only memory BIO avoids this problem. If the BIO must be read write
81 then adding a buffering BIO to the chain will speed up the process.
82
84 There should be an option to set the maximum size of a memory BIO.
85
86 There should be a way to "rewind" a read write BIO without destroying
87 its contents.
88
89 The copying operation should not occur after every small read of a
90 large BIO to improve efficiency.
91
93 Create a memory BIO and write some data to it:
94
95 BIO *mem = BIO_new(BIO_s_mem());
96 BIO_puts(mem, "Hello World\n");
97
98 Create a read only memory BIO:
99
100 char data[] = "Hello World";
101 BIO *mem;
102 mem = BIO_new_mem_buf(data, -1);
103
104 Extract the BUF_MEM structure from a memory BIO and then free up the
105 BIO:
106
107 BUF_MEM *bptr;
108 BIO_get_mem_ptr(mem, &bptr);
109 BIO_set_close(mem, BIO_NOCLOSE); /* So BIO_free() leaves BUF_MEM alone */
110 BIO_free(mem);
111
113 TBA
114
115
116
1171.0.2o 2020-08-01 BIO_s_mem(3)