298
Platforms
©2000-2008 Tibbo Technology Inc.
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 for 10%.
There is a small overhead for each buffer. Meaning, not 100% of the memory
allocated to a buffer is actually available for use. 16 bytes of each buffer are
reserved for variables needed to administer this buffer, such as various pointers
etc.
Thus, if we requested (and received) a buffer with 2 pages (256 * 2 = 512), we
actually have 496 bytes in which to store data (512 - 16).
If you are changing the size of any buffer for a socket using sys.
buffalloc, and this socket is not closed (
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.
Using Buffers in TCP Mode
Once you have allocated memory for the TX and RX buffers you can start sending
and receiving data through them. Since TCP is a stream-oriented protocol this is
what buffers store- a stream of data being sent and received, without any
separation into individual packets. Even for the outgoing data, you have no control
over how it will be split into packets for transmission over the network.
Sending Data
Sending data a two-step process. First, you put the data in the TX buffer using the
method, and then you perform the actual sending (commit the
data) using the
method. For example:
sock.setdata (
"Foo"
)
' Placed our data in the TX buffer - not being sent
out yet.
' ... more code...
sock.setdata (
"Bar"
)
' Added even more data to the TX buffer, waiting to
be sent.
sock.send
' Now data will actually start going out. Data sent will be
'FooBar'.
Since this is a two-step process, you may gradually fill the buffer to capacity, and
only then send its contents.
TiOS features non-blocking operation. This means that on sock.send,
for example, the program does not halt and wait until the data is
completely sent. In fact, execution resumes immediately, even before
the first byte goes out. Your program will not freeze just because you
ordered it to send a large chunk of data.
The data can be stored in the TX buffer at any time but it will only be sent out if
and when the
is established. Storing the data in the TX
buffer won't cause the socket to establish any connection automatically.
Receiving Data
358
353
353
277