#include <datagram.h>

Public Member Functions | |
| datagram_server (int port, size_t message_size, exeque *output_queue, exeque *run_queue, datagram_message_factory *factory) | |
| void | setLogger (const log &logger) |
| Set the logger object. | |
| datagram_status | create () |
| Create the server and bind the socket. | |
| void | run () |
| this implements the "receive loop". | |
| void | start () |
| Start the server's receive loop. | |
| void | stop () |
| Stop the server's receive loop. | |
| datagram_status | getStatus () const |
| Get the status of the server. | |
Protected Member Functions | |
| void | close () |
| Close the datagram socket. | |
| datagram_status | read (datagram_message *message) |
| read one datagram from the socket. | |
Protected Attributes | |
| int | port |
| the listening port | |
| struct sockaddr_in | addr |
| the address structure. | |
| int | sock |
| the socket file handle | |
| datagram_status | status |
| the current sttaus of the server, should be DATAGRAM_OK if all is working normally. | |
| size_t | message_size |
| the number of bytes to pre-allocat to buffer an incoming datagram | |
| exeque * | output_queue |
| the queue to use for dispatching datagram messages that have been received. | |
| exeque * | run_queue |
| the queue to use for runnning this server. | |
| datagram_message_factory * | factory |
| this factory is used for creating datagrams suitable for buffering incoming messages, and then handling them. | |
| karoo_mutex | running_sem |
| used to keep accesses to the running varaible thread-safe | |
| bool | running |
| true while the server is still running. | |
| unsigned | fail_count |
| counts the number of consecutive failures in the receive loop | |
| log | logger |
| This must be set up in order for errors, debugs, etc to to displayed or logged somewhere. | |
Note that a datagram_server does not have provision for sending a datagram.
| void karoo::datagram_server::close | ( | ) | [protected] |
Close the datagram socket.
This method is only ever called from in the receive loop and also in the destructer.
| datagram_status karoo::datagram_server::create | ( | ) |
Create the server and bind the socket.
| datagram_status karoo::datagram_server::getStatus | ( | ) | const [inline] |
| datagram_status karoo::datagram_server::read | ( | datagram_message * | message | ) | [protected] |
read one datagram from the socket.
This is a blocking call. It should only ever be called from inside the receive loop.
| message | a pointer to the new datagram_message object that will buffer and then handle the message. |
| void karoo::datagram_server::run | ( | ) |
this implements the "receive loop".
if the status of the server is DATAGRAM_OK, then it will get a new datagram_message from the factory, and call read(). If the status remains DATAGRAM_OK, then it will set up the message to destroy itself after being run (datagram_message inherits from pebble), and then will add the datagram_message to the output_queue. When the datagram_message::run() is called in the output_queue, it will presumably do something to handle the message (but thats up to whoever implemented the datagram_message_factory. In the case of a rock_datagram_factory and rock_datagram_message, it calls the parent's rock::handle() method.
| void karoo::datagram_server::setLogger | ( | const log & | logger | ) |
Set the logger object.
| logger | the log object for sending warnings, errors etc... to |
struct sockaddr_in karoo::datagram_server::addr [read, protected] |
the address structure.
This is initialised to allow the server to receive from any internet address.
exeque* karoo::datagram_server::output_queue [protected] |
the queue to use for dispatching datagram messages that have been received.
This queue typically will only be lightly utilised by the server unless messages are coming in very quickly. Note that rock_datagram_message::run() calls rock::handle(this), which in turn calls all the handlers that therock is configured with, until one returns true to indicate that it has handled it. This may be time consuming, depending on the design of your handlers. ... but it is reasonably safe to assume that you could run other tasks in the same queue.
exeque* karoo::datagram_server::run_queue [protected] |
the queue to use for runnning this server.
This is used for the (blocking) receive loop, so it will be 100% utilised. Any task you add to this queue will only be executed after a datagram is received, which (if not many messages are being received) could be after a long delay. It would make sense though to perhaps put some statistics gathering, or housekeeping task into this queue.
bool karoo::datagram_server::running [protected] |
true while the server is still running.
Once set to false, the server receive loop will exit.
1.5.8