#include <rock.h>

Public Member Functions | |
| rock_datagram_message (size_t alloc_size, rock *parent) | |
| Create a new object for receiving a message into. | |
| rock_datagram_message (size_t alloc_size, const text &ip, int port, rock *parent) | |
| Create a new message to send. | |
| datagram_message * | clone (size_t alloc_size=0) const |
| Create a copy of this message. | |
| datagram_message * | clone (int port, size_t alloc_size=0) const |
| Create a copy of this message. | |
| size_t | getReadPos () const |
| Get the current position (offset from start of buffer) where the mesage will next be reading from. | |
| void | resetReadPos (size_t pos=0) |
| reset the read pos to zero, so that the message can be parsed again from the beginning. | |
| size_t | available () |
| get the number of bytes remaining in thebuffer and available for reading | |
| void | write (const void *data, size_t size) |
| Write data to the message buffer. | |
| void | read (void *data, size_t size) |
| Read data from the message buffer. | |
| void | accomodate (size_t bytes) |
| Attempt to resize the buffer so that it can fit more bytes after its current size value. | |
| uint32_t | getType () |
| convenience method for getting the type from the message | |
| uint64_t | getSequence () |
| convenience method for getting the sequence from the message | |
| int32_t | getSourcePort () |
| convenience method for getting the port from the message | |
| text | getName () |
| convenience method for getting the sender's name from the message | |
| void | setReply (rock_datagram_reply *reply) |
| set the reply pebble which will be run when the ACK is received. | |
| rock_datagram_reply * | getReply () |
| Get the reply pebble. | |
| text | getHost () const |
| Get the host address. | |
| int32_t | getPort () const |
| Get the port. | |
| void | run () |
| This will be automatically called from the output_queue for all incoming messages. | |
| void | setRecipientName (const text &recipient_name) |
| Set the recipient rock's name. | |
| text | getRecipientName () const |
| Get the recipient rock's name. | |
Protected Member Functions | |
| size_t | readFrom (void *data, size_t size, size_t p) const |
| read the message, from a certain position, for a certain number of bytes. | |
Protected Attributes | |
| size_t | pos |
| the read position in the buffer | |
| rock * | parent |
| the rock that owns this message | |
| rock_datagram_reply * | reply |
| if this is set, then if this rock_datagram_message is sent, when the ACK comes in, then the reply will be run in the general_pool. | |
| text | recipient_name |
| The recipient rock's name. | |
| karoo::rock_datagram_message::rock_datagram_message | ( | size_t | alloc_size, | |
| rock * | parent | |||
| ) |
Create a new object for receiving a message into.
| alloc_size | the size of the buffer for reading into | |
| parent | the rock that owns this message. |
| karoo::rock_datagram_message::rock_datagram_message | ( | size_t | alloc_size, | |
| const text & | ip, | |||
| int | port, | |||
| rock * | parent | |||
| ) |
Create a new message to send.
| alloc_size | the size of the buffer for reading into | |
| ip | the IP address (either in domain name format, or xxx.yyy.zzz.xyz format) | |
| port | the port to send the datagram to. | |
| parent | the rock that owns this message. |
| bad_alloc | describing the error. |
| void karoo::rock_datagram_message::accomodate | ( | size_t | bytes | ) | [virtual] |
Attempt to resize the buffer so that it can fit more bytes after its current size value.
Note that if the buffer is already large enough, nothing will happen.
| bytes | the number of extra bytes to resize the buffer to |
| bad_alloc | if the buffer could not be resized |
Implements karoo::rock_data.
| datagram_message* karoo::rock_datagram_message::clone | ( | int | port, | |
| size_t | alloc_size = 0 | |||
| ) | const [virtual] |
Create a copy of this message.
This clones everything, except the message itself. It clones the address, but uses the port number you supply. This is useful for creatiing a message buffer al¶eady addressed to reply to the sender.
| port | the port number which will replace the port number in the nessage, | |
| alloc_size | if this is non-zero, then it will use this size for allocating the buffer. |
| bad_address | if the address is invalid |
Implements karoo::datagram_message.
| datagram_message* karoo::rock_datagram_message::clone | ( | size_t | alloc_size = 0 |
) | const [virtual] |
Create a copy of this message.
This clones everything, except the message itself. It clones even the address and port.
| alloc_size | if this is non-zero, then it will use this size for allocating the buffer. |
Implements karoo::datagram_message.
| text karoo::rock_datagram_message::getHost | ( | ) | const |
Get the host address.
This will be the address of the sender (if this message has just been received), or of the recipient (if this message has been constructed and ready to send. At present if the family is not AF_INET, it will return a zero length string
| bad_address | describing the error if the address was not compatible (AF_INET is required) |
| text karoo::rock_datagram_message::getName | ( | ) |
convenience method for getting the sender's name from the message
| rock_exception_read | when there is an exception while reading the data The first few bytes in every message are the type (32 bit unsigned ineteger), then the sequence number (64 bit unsigned ineteger). Ack messages don't have the port number, but all other messages do; it is the next 32 bit signed integer after the sequence number. Then (in all messages except ACKs, there is a string, the sender's rock name. |
| int32_t karoo::rock_datagram_message::getPort | ( | ) | const |
Get the port.
| bad_address | describing the error if the address was not compatible (AF_INET is required) |
| text karoo::rock_datagram_message::getRecipientName | ( | ) | const [inline] |
| rock_datagram_reply* karoo::rock_datagram_message::getReply | ( | ) |
Get the reply pebble.
This reply is usually run when the ACK is received, but it is also run (to indicate NACK) when the recipient is not responding.
| uint64_t karoo::rock_datagram_message::getSequence | ( | ) |
convenience method for getting the sequence from the message
| rock_exception_read | when there is an exception while reading the data The first few bytes in every message are the type (32 bit unsigned ineteger), then the sequence number (64 bit unsigned ineteger). Ack messages don't have the port number, but all other messages do; it is the next 32 bit signed integer after the sequence number. Then (in all messages except ACKs, there is a string, the sender's rock name. |
| int32_t karoo::rock_datagram_message::getSourcePort | ( | ) |
convenience method for getting the port from the message
| rock_exception_read | when there is an exception while reading the data The first few bytes in every message are the type (32 bit unsigned ineteger), then the sequence number (64 bit unsigned ineteger). Ack messages don't have the port number, but all other messages do; it is the next 32 bit signed integer after the sequence number. Then (in all messages except ACKs, there is a string, the sender's rock name. |
| uint32_t karoo::rock_datagram_message::getType | ( | ) |
convenience method for getting the type from the message
| rock_exception_read | when there is an exception while reading the data The first few bytes in every message are the type (32 bit unsigned ineteger), then the sequence number (64 bit unsigned ineteger). Ack messages don't have the port number, but all other messages do; it is the next 32 bit signed integer after the sequence number. Then (in all messages except ACKs, there is a string, the sender's rock name. |
| void karoo::rock_datagram_message::read | ( | void * | data, | |
| size_t | size | |||
| ) | [virtual] |
Read data from the message buffer.
| data | the data buffer to read in to | |
| size | how much data to read |
| rock_exception_read | when there is an exception while reading the data Note that the pos of the datagram buffer will increase after calling this method, and each successive call moves the pos further towards the end of the data. |
Implements karoo::rock_data.
| size_t karoo::rock_datagram_message::readFrom | ( | void * | data, | |
| size_t | size, | |||
| size_t | p | |||
| ) | const [protected] |
read the message, from a certain position, for a certain number of bytes.
| data | the buffer to read in to | |
| size | the number of bytes to read | |
| p | the position to start reading from |
| rock_exception_read | if there is any sort of error while reading. Note this does not modify the message's pos variable. |
| void karoo::rock_datagram_message::resetReadPos | ( | size_t | pos = 0 |
) | [inline] |
reset the read pos to zero, so that the message can be parsed again from the beginning.
References pos.
| void karoo::rock_datagram_message::run | ( | ) |
This will be automatically called from the output_queue for all incoming messages.
It handles the message. Its actually very simple, it just calls
parent->handle(this);
| void karoo::rock_datagram_message::setRecipientName | ( | const text & | recipient_name | ) | [inline] |
Set the recipient rock's name.
This is used by the rock::sendMessage() method, to first find a rock's host:port.
| void karoo::rock_datagram_message::setReply | ( | rock_datagram_reply * | reply | ) |
set the reply pebble which will be run when the ACK is received.
This only applies when the message is sent, rather than received.
| void karoo::rock_datagram_message::write | ( | const void * | data, | |
| size_t | size | |||
| ) | [virtual] |
Write data to the message buffer.
| data | the data buffer to write | |
| size | the size of the data buffer |
| bad_alloc | when there is an exception while writing the data Note that the size of the datagram buffer (not the allocated size) will increase after calling this method, and each successive call appends data to the end of the datagram message. |
Implements karoo::rock_data.
text karoo::rock_datagram_message::recipient_name [protected] |
1.5.8