SockIt
|
#include <TcpEvent.h>
Public Member Functions | |
TcpEvent (Tcp *tcp, boost::shared_ptr< tcp::socket > connection, string data) | |
virtual | ~TcpEvent () |
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 |
Tcp * | tcp_object |
string | host |
int | port |
boost::shared_ptr< tcp::socket > | connection |
A TCP implementation of a event to allow javascript to respond to data on a TCP connection.
Definition at line 25 of file TcpEvent.h.
TcpEvent::TcpEvent | ( | Tcp * | tcp, |
boost::shared_ptr< tcp::socket > | connection, | ||
string | data | ||
) |
Constructs a new TcpEvent
object containing the TCP connection on which to reply.
tcp | The TCP server or client associated with this event |
connection | The TCP connection on which to reply |
data | The data received when this event was fired |
Definition at line 12 of file TcpEvent.cpp.
References Logger::error(), failed, host, and port.
: tcp_object(tcp_object), connection(connection), failed(false), data(data) { // Check to see if any the parameters are null, and log and fail if this occurs if(tcp_object && connection) { // Initialize only if it's safe port = connection->remote_endpoint().port(); host = connection->remote_endpoint().address().to_string(); } else { // Fail permanently and log it failed = true; string message("TCP event was not properly initialized, permanently failed."); Logger::error(message, port, host); fire_error(message); } }
TcpEvent::~TcpEvent | ( | ) | [virtual] |
Deconstructs the TCP event object, after a single reply.
Definition at line 33 of file TcpEvent.cpp.
{
// do not free socket, endpoint or tcp here
}
string TcpEvent::get_host | ( | void | ) | [virtual] |
unsigned short TcpEvent::get_port | ( | void | ) | [virtual] |
string TcpEvent::read | ( | ) | const [virtual] |
Reads the string data that belongs to this event.
Implements Event.
Definition at line 74 of file TcpEvent.cpp.
References data.
{ return data; }
FB::VariantList TcpEvent::read_bytes | ( | ) | const [virtual] |
Reads the byte data that belongs to this event
Implements Event.
Definition at line 79 of file TcpEvent.cpp.
References data.
void TcpEvent::send | ( | const string & | data | ) | [virtual] |
Replies on the TCP connection with some data.
data | The data with which to reply |
Implements Event.
Definition at line 50 of file TcpEvent.cpp.
References Tcp::active_jobs, connection, Logger::error(), Tcp::failed, failed, host, port, Tcp::send_handler(), and tcp_object.
Referenced by send_bytes().
{ // Don't send if we've permanently failed if(failed) { string message("TCP event failed to send, event already failed permanently"); Logger::error(message, port, host); fire_error(message); } if(!tcp_object->failed) { tcp_object->active_jobs++; connection->async_send(boost::asio::buffer(data.data(), data.size()), boost::bind(&Tcp::send_handler, tcp_object, _1, _2, data, host, port, connection)); } else { string message("TCP event failed trying to reply on a permanently failed TCP object"); Logger::error(message, port, host); fire_error(message); } }
void TcpEvent::send_bytes | ( | const vector< byte > & | bytes | ) | [virtual] |
Replies on the TCP connection with some data.
bytes | The bytes of data with which to reply |
Implements Event.
Definition at line 38 of file TcpEvent.cpp.
boost::shared_ptr<tcp::socket> TcpEvent::connection [private] |
The TCP connection on which to reply
Definition at line 115 of file TcpEvent.h.
Referenced by send().
string TcpEvent::data [private] |
The data received when this event was fired
Definition at line 90 of file TcpEvent.h.
Referenced by TcpClient::flush(), read(), read_bytes(), send_bytes(), and TcpClient::send_bytes().
bool TcpEvent::failed [private] |
A flag to prevent this event from blowing up if was initialized improperly
Definition at line 95 of file TcpEvent.h.
Referenced by send(), and TcpEvent().
string TcpEvent::host [private] |
The remote hostname of the TCP connection for this TcpEvent
Definition at line 105 of file TcpEvent.h.
Referenced by get_host(), send(), and TcpEvent().
int TcpEvent::port [private] |
The remote port of the TCP connection for this TcpEvent
.
Definition at line 110 of file TcpEvent.h.
Referenced by get_port(), send(), and TcpEvent().
Tcp* TcpEvent::tcp_object [private] |
The TCP server or client associated with this event
Definition at line 100 of file TcpEvent.h.
Referenced by send().