SockIt
|
#include <UdpEvent.h>
Public Member Functions | |
UdpEvent (Udp *udp, boost::shared_ptr< udp::socket > socket, boost::shared_ptr< udp::endpoint > endpoint, string data) | |
virtual | ~UdpEvent () |
virtual void | send (const string &data) |
virtual void | send_bytes (const vector< byte > &bytes) |
virtual string | read () const |
virtual FB::VariantList | read_bytes () const |
virtual string | get_host () |
virtual unsigned short | get_port () |
Private Attributes | |
string | data |
bool | failed |
string | host |
int | port |
boost::shared_ptr< udp::socket > | socket |
boost::shared_ptr< udp::endpoint > | endpoint |
Udp * | udp_object |
A UDP implementation of a event to allow javascript to respond to data on a UDP connection.
Definition at line 21 of file UdpEvent.h.
UdpEvent::UdpEvent | ( | Udp * | udp, |
boost::shared_ptr< udp::socket > | socket, | ||
boost::shared_ptr< udp::endpoint > | endpoint, | ||
string | data | ||
) |
Constructs a new UdpEvent
object containing the UDP connection on which to reply.
udp | The UDP server or client associated with this event |
socket | The UDP connection on which to reply |
endpoint | The remote endpoint for this UDP event, from which we can find information about the remote host |
data | The data this event was fired from |
Definition at line 10 of file UdpEvent.cpp.
References Logger::error(), failed, host, and port.
: port(-1), socket(socket), endpoint(endpoint), udp_object(udp_object), failed(false), data(data) { // Check to see if any the parameters are null, and log and fail if this occurs if (endpoint && udp_object) { // Initialize only if it's safe host = boost::lexical_cast<string>(endpoint->address()); port = endpoint->port(); } else { // Fail permanently and log it failed = true; string message("UDP Event was not properly initialized, permanently failed."); Logger::error(message, port, host); fire_error(message); } }
UdpEvent::~UdpEvent | ( | ) | [virtual] |
Deconstructs the UDP event object, after a single reply.
Definition at line 31 of file UdpEvent.cpp.
{
// do not free socket, endpoint or udp here
}
string UdpEvent::get_host | ( | void | ) | [virtual] |
unsigned short UdpEvent::get_port | ( | void | ) | [virtual] |
string UdpEvent::read | ( | ) | const [virtual] |
Reads the string data that belongs to this event.
Implements Event.
Definition at line 76 of file UdpEvent.cpp.
References data.
{ return data; }
FB::VariantList UdpEvent::read_bytes | ( | ) | const [virtual] |
Reads the byte data that belongs to this event
Implements Event.
Definition at line 81 of file UdpEvent.cpp.
References data.
void UdpEvent::send | ( | const string & | data | ) | [virtual] |
Replies on the UDP connection with some data.
data | The data with which to reply |
Implements Event.
Definition at line 48 of file UdpEvent.cpp.
References endpoint, Logger::error(), Udp::failed, failed, host, Udp::pending_sends, port, Udp::send_handler(), socket, and udp_object.
Referenced by send_bytes().
{ // Don't send if we've permanently failed if (failed) { string message("UDP event failed to send, Event already failed permanently"); Logger::error(message, port, host); fire_error(message); return; } if (udp_object && udp_object->failed) { // Log & fire an error string message("UDP event failed trying to reply to a UDP object that has permanently failed!"); Logger::error(message, port, host); fire_error(message); return; } if (socket && endpoint) { udp_object->pending_sends++; socket->async_send_to(boost::asio::buffer(data.data(), data.size()), *endpoint, boost::bind(&Udp::send_handler, udp_object, _1, _2, data, host, endpoint->port())); } }
void UdpEvent::send_bytes | ( | const vector< byte > & | bytes | ) | [virtual] |
Replies on the UDP connection with some data.
bytes | The bytes of data with which to reply |
Implements Event.
Definition at line 36 of file UdpEvent.cpp.
string UdpEvent::data [private] |
The data received when this event was fired
Definition at line 88 of file UdpEvent.h.
Referenced by read(), read_bytes(), send_bytes(), and UdpClient::send_bytes().
boost::shared_ptr<udp::endpoint> UdpEvent::endpoint [private] |
bool UdpEvent::failed [private] |
A flag to prevent this event from blowing up if was initialized improperly
Definition at line 93 of file UdpEvent.h.
Referenced by send(), and UdpEvent().
string UdpEvent::host [private] |
The remote hostname of the UDP connection for this UdpEvent
Definition at line 98 of file UdpEvent.h.
Referenced by get_host(), send(), and UdpEvent().
int UdpEvent::port [private] |
The remote port of the UDP connection for this UdpEvent
Definition at line 103 of file UdpEvent.h.
Referenced by get_port(), send(), and UdpEvent().
boost::shared_ptr<udp::socket> UdpEvent::socket [private] |
The socket corresponding to this UDP 'connection', on which to reply
Definition at line 108 of file UdpEvent.h.
Referenced by send().
Udp* UdpEvent::udp_object [private] |
The UDP server or client associated with this event
Definition at line 118 of file UdpEvent.h.
Referenced by send().