SUMO - Simulation of Urban MObility
|
#include <socket.h>
Public Member Functions | |
void | accept () throw ( SocketException ) |
Wait for a incoming connection to port_. | |
void | close () |
void | connect () throw ( SocketException ) |
Connects to host_:port_. | |
bool | has_client_connection () const |
bool | is_blocking () throw () |
int | port () |
std::vector< unsigned char > | receive (int bufSize=2048) throw ( SocketException ) |
Receive up to bufSize available bytes from Socket::socket_. | |
bool | receiveExact (Storage &) throw ( SocketException ) |
Receive a complete TraCI message from Socket::socket_. | |
void | send (const std::vector< unsigned char > &buffer) throw ( SocketException ) |
void | sendExact (const Storage &) throw ( SocketException ) |
void | set_blocking (bool) throw ( SocketException ) |
void | set_verbose (bool newVerbose) |
Socket (std::string host, int port) | |
Constructor that prepare to connect to host:port. | |
Socket (int port) | |
Constructor that prepare for accepting a connection on given port. | |
bool | verbose () |
~Socket () | |
Destructor. | |
Protected Member Functions | |
void | printBufferOnVerbose (const std::vector< unsigned char > buffer, const std::string &label) const |
Print label and buffer to stderr if Socket::verbose_ is set. | |
void | receiveComplete (unsigned char *const buffer, std::size_t len) const |
Receive len bytes from Socket::socket_. | |
size_t | recvAndCheck (unsigned char *const buffer, std::size_t len) const |
Receive up to len available bytes from Socket::socket_. | |
Static Protected Attributes | |
static const int | lengthLen = 4 |
Length of the message length part of a TraCI message. | |
Private Member Functions | |
bool | atoaddr (std::string, struct in_addr &addr) |
void | BailOnSocketError (std::string) const throw ( SocketException ) |
bool | datawaiting (int sock) const throw () |
void | init () |
Private Attributes | |
bool | blocking_ |
std::string | host_ |
int | port_ |
int | server_socket_ |
int | socket_ |
bool | verbose_ |
Friends | |
class | Response |
tcpip::Socket::Socket | ( | std::string | host, |
int | port | ||
) |
Constructor that prepare to connect to host:port.
Definition at line 74 of file socket.cpp.
References init().
tcpip::Socket::Socket | ( | int | port | ) |
Constructor that prepare for accepting a connection on given port.
Definition at line 87 of file socket.cpp.
References init().
Destructor.
Definition at line 118 of file socket.cpp.
References close(), server_socket_, and socket_.
void tcpip::Socket::accept | ( | ) | throw ( SocketException ) |
Wait for a incoming connection to port_.
Definition at line 223 of file socket.cpp.
References BailOnSocketError(), blocking_, port_, server_socket_, set_blocking(), and socket_.
Referenced by traci::TraCIServer::TraCIServer().
bool tcpip::Socket::atoaddr | ( | std::string | address, |
struct in_addr & | addr | ||
) | [private] |
Definition at line 197 of file socket.cpp.
Referenced by connect().
void tcpip::Socket::BailOnSocketError | ( | std::string | context | ) | const throw ( SocketException ) [private] |
Definition at line 148 of file socket.cpp.
Referenced by accept(), connect(), init(), and recvAndCheck().
void tcpip::Socket::close | ( | ) |
Definition at line 347 of file socket.cpp.
References socket_.
Referenced by testclient::TraCITestClient::close(), OutputDevice_Network::~OutputDevice_Network(), ~Socket(), and traci::TraCIServer::~TraCIServer().
void tcpip::Socket::connect | ( | ) | throw ( SocketException ) |
Connects to host_:port_.
Definition at line 316 of file socket.cpp.
References atoaddr(), BailOnSocketError(), host_, port_, and socket_.
Referenced by testclient::TraCITestClient::connect(), and OutputDevice_Network::OutputDevice_Network().
bool tcpip::Socket::datawaiting | ( | int | sock | ) | const throw () [private] |
Definition at line 172 of file socket.cpp.
bool tcpip::Socket::has_client_connection | ( | ) | const |
Definition at line 528 of file socket.cpp.
References socket_.
void tcpip::Socket::init | ( | ) | [private] |
bool tcpip::Socket::is_blocking | ( | ) | throw () |
Definition at line 537 of file socket.cpp.
References blocking_.
Definition at line 163 of file socket.cpp.
References port_.
void tcpip::Socket::printBufferOnVerbose | ( | const std::vector< unsigned char > | buffer, |
const std::string & | label | ||
) | const [protected] |
Print label
and buffer
to stderr if Socket::verbose_ is set.
Definition at line 451 of file socket.cpp.
References verbose_.
vector< unsigned char > tcpip::Socket::receive | ( | int | bufSize = 2048 | ) | throw ( SocketException ) |
Receive up to bufSize
available bytes from Socket::socket_.
Definition at line 469 of file socket.cpp.
void tcpip::Socket::receiveComplete | ( | unsigned char *const | buffer, |
std::size_t | len | ||
) | const [protected] |
Receive len
bytes from Socket::socket_.
Definition at line 436 of file socket.cpp.
References recvAndCheck().
bool tcpip::Socket::receiveExact | ( | Storage & | msg | ) | throw ( SocketException ) |
Receive a complete TraCI message from Socket::socket_.
Definition at line 495 of file socket.cpp.
References tcpip::Storage::readInt().
Referenced by testclient::TraCITestClient::commandClose(), testclient::TraCITestClient::commandDistanceRequest(), testclient::TraCITestClient::commandGetVariable(), testclient::TraCITestClient::commandGetVariablePlus(), testclient::TraCITestClient::commandPositionConversion(), testclient::TraCITestClient::commandSetValue(), testclient::TraCITestClient::commandSimulationStep2(), testclient::TraCITestClient::commandSubscribeVariable(), and traci::TraCIServer::processCommandsUntilSimStep().
size_t tcpip::Socket::recvAndCheck | ( | unsigned char *const | buffer, |
std::size_t | len | ||
) | const [protected] |
Receive up to len
available bytes from Socket::socket_.
Definition at line 416 of file socket.cpp.
References BailOnSocketError(), and socket_.
Referenced by receiveComplete().
void tcpip::Socket::send | ( | const std::vector< unsigned char > & | buffer | ) | throw ( SocketException ) |
Definition at line 365 of file socket.cpp.
Referenced by OutputDevice_Network::postWriteHook().
void tcpip::Socket::sendExact | ( | const Storage & | b | ) | throw ( SocketException ) |
Definition at line 396 of file socket.cpp.
References tcpip::Storage::begin(), tcpip::Storage::end(), and tcpip::Storage::writeInt().
Referenced by testclient::TraCITestClient::commandClose(), testclient::TraCITestClient::commandDistanceRequest(), testclient::TraCITestClient::commandGetVariable(), testclient::TraCITestClient::commandGetVariablePlus(), testclient::TraCITestClient::commandPositionConversion(), testclient::TraCITestClient::commandSetValue(), testclient::TraCITestClient::commandSimulationStep2(), testclient::TraCITestClient::commandSubscribeVariable(), and traci::TraCIServer::processCommandsUntilSimStep().
void tcpip::Socket::set_blocking | ( | bool | blocking | ) | throw ( SocketException ) |
Definition at line 288 of file socket.cpp.
Referenced by accept().
void tcpip::Socket::set_verbose | ( | bool | newVerbose | ) | [inline] |
bool tcpip::Socket::verbose | ( | ) | [inline] |
bool tcpip::Socket::blocking_ [private] |
Definition at line 137 of file socket.h.
Referenced by accept(), and is_blocking().
std::string tcpip::Socket::host_ [private] |
const int tcpip::Socket::lengthLen = 4 [static, protected] |
int tcpip::Socket::port_ [private] |
int tcpip::Socket::server_socket_ [private] |
int tcpip::Socket::socket_ [private] |
Definition at line 135 of file socket.h.
Referenced by accept(), close(), connect(), has_client_connection(), recvAndCheck(), and ~Socket().
bool tcpip::Socket::verbose_ [private] |
Definition at line 139 of file socket.h.
Referenced by printBufferOnVerbose(), set_verbose(), and verbose().