HTTP-Related Buffers

For the HTTP to work, you need to allocate some memory to the following buffers:


Actual memory allocation is done through the sys.buffalloc method, which applies to all buffers previously specified. Here is an example:

Tibbo BASIC
Dim f As Byte
 
...
'setup for other objects, sockets, etc.
 
'setup buffers of sockets 8-15 (will be used for HTTP)
For f=8 To 15
   sock.num=f
   sock.txbuffrq(1) 'you need this buffer for HTTP requests and replies
   sock.varbuffrq(1) 'you need this buffer to get HTTP variables
   sock.redir(PL_REDIR_SOCK0 + sock.num) 'this will allow us to avoid wasting memory on the RX buffer
Next f
 
....
 
sys.buffalloc ' Performs actual memory allocation, as per previous requests.

Memory allocation takes up to 100ms, so it is usually done just once, on boot, for all required buffers.

You may not always get the full amount of memory you have requested. Memory is not an infinite resource, and if you have already requested (and received) allocations for 95% of the memory for your platform, your next request will get up to 5% of memory, even if you requested 10%.

There is a small overhead for each buffer. Meaning, not 100% of the memory allocated to a buffer is actually available for use. A certain number of bytes in each buffer is reserved for variables needed to administer this buffer. This number is 17 for 16-bit platforms and 33 for 32-bit platforms. Platform type is specified in your platform documentation.

Thus, if we requested (and received) a buffer with 2 pages (256 * 2 = 512 bytes), then we can only store 512 - 17 or 512 - 33 bytes in this buffer, depending on the platform type.

A warning note icon.If you are changing the size of any buffer for a socket using sys.buffalloc and this socket is not closed (sock.statesimple is not PL_SSTS_CLOSED), the socket will be automatically closed. Whatever connection you had in progress will be discarded. The socket will not be closed if its buffer sizes remain unchanged.

A warning note icon.Note that, in most cases, you will need to reserve more than one socket for HTTP. The HTTP server may need to service multiple requests from different computers at the same time. Even for a single computer and a single HTML page, more than one socket may be needed. For example, if your HTML page contains a picture, the browser will establish two parallel connections to the sock. object — one to get the HTML page itself and another one to get the picture. We recommend that you reserve four to eight sockets for HTTP. It is better to have less buffer memory for each HTTP socket than to have fewer HTTP sockets!