Eclipse SUMO - Simulation of Urban MObility
|
#include <socket.h>
Public Member Functions | |
Socket * | accept (const bool create=false) |
Wait for a incoming connection to port_. | |
void | close () |
void | connect () |
Connects to host_:port_. | |
bool | has_client_connection () const |
bool | is_blocking () |
int | port () |
std::vector< unsigned char > | receive (int bufSize=2048) |
Receive up to bufSize available bytes from Socket::socket_. | |
bool | receiveExact (Storage &) |
Receive a complete TraCI message from Socket::socket_. | |
void | send (const std::vector< unsigned char > &buffer) |
void | sendExact (const Storage &) |
void | set_blocking (bool) |
void | set_verbose (bool newVerbose) |
Socket (int port) | |
Constructor that prepare for accepting a connection on given port. | |
Socket (std::string host, int port) | |
Constructor that prepare to connect to host:port. | |
bool | verbose () |
~Socket () | |
Destructor. | |
Static Public Member Functions | |
static int | getFreeSocketPort () |
Returns an free port on the system. | |
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 | datawaiting (int sock) const |
void | init () |
Static Private Member Functions | |
static void | BailOnSocketError (std::string context) |
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 72 of file socket.cpp.
References init().
tcpip::Socket::Socket | ( | int | port | ) |
Constructor that prepare for accepting a connection on given port.
Definition at line 85 of file socket.cpp.
References init().
tcpip::Socket::~Socket | ( | ) |
Destructor.
Definition at line 147 of file socket.cpp.
References close(), server_socket_, and socket_.
Socket * tcpip::Socket::accept | ( | const bool | create = false | ) |
Wait for a incoming connection to port_.
Definition at line 233 of file socket.cpp.
References accept(), BailOnSocketError(), blocking_, port_, server_socket_, set_blocking(), and socket_.
Referenced by accept(), and TraCIServer::TraCIServer().
|
staticprivate |
Definition at line 177 of file socket.cpp.
Referenced by accept(), connect(), datawaiting(), getFreeSocketPort(), init(), recvAndCheck(), send(), and set_blocking().
void tcpip::Socket::close | ( | ) |
Definition at line 364 of file socket.cpp.
References close(), and socket_.
Referenced by close(), libtraci::Connection::close(), TraCIAPI::closeSocket(), connect(), libtraci::Connection::Connection(), getFreeSocketPort(), OutputDevice_Network::postWriteHook(), OutputDevice_Network::~OutputDevice_Network(), and ~Socket().
void tcpip::Socket::connect | ( | ) |
Connects to host_:port_.
Definition at line 331 of file socket.cpp.
References BailOnSocketError(), close(), connect(), host_, port_, and socket_.
Referenced by connect(), TraCIAPI::connect(), libtraci::Connection::Connection(), OutputDevice_Network::OutputDevice_Network(), and receive().
|
private |
Definition at line 205 of file socket.cpp.
References BailOnSocketError().
Referenced by receive().
|
static |
Returns an free port on the system.
Definition at line 117 of file socket.cpp.
References BailOnSocketError(), close(), and port().
bool tcpip::Socket::has_client_connection | ( | ) | const |
Definition at line 541 of file socket.cpp.
References socket_.
Referenced by libtraci::Connection::close(), libtraci::Connection::createCommand(), OutputDevice_Network::postWriteHook(), and libtraci::Connection::subscribe().
|
private |
Definition at line 99 of file socket.cpp.
References BailOnSocketError().
Referenced by Socket(), and Socket().
bool tcpip::Socket::is_blocking | ( | ) |
Definition at line 550 of file socket.cpp.
References blocking_.
int tcpip::Socket::port | ( | ) |
Definition at line 191 of file socket.cpp.
References port_.
Referenced by getFreeSocketPort().
|
protected |
Print label
and buffer
to stderr if Socket::verbose_ is set.
Definition at line 466 of file socket.cpp.
References verbose_.
Referenced by receive(), receiveExact(), and send().
std::vector< unsigned char > tcpip::Socket::receive | ( | int | bufSize = 2048 | ) |
Receive up to bufSize
available bytes from Socket::socket_.
Definition at line 484 of file socket.cpp.
References connect(), datawaiting(), printBufferOnVerbose(), recvAndCheck(), and socket_.
|
protected |
Receive len
bytes from Socket::socket_.
Definition at line 451 of file socket.cpp.
References recvAndCheck().
Referenced by receiveExact().
bool tcpip::Socket::receiveExact | ( | Storage & | msg | ) |
Receive a complete TraCI message from Socket::socket_.
Definition at line 509 of file socket.cpp.
References lengthLen, printBufferOnVerbose(), tcpip::Storage::readInt(), receiveComplete(), tcpip::Storage::reset(), and tcpip::Storage::writePacket().
Referenced by libtraci::Connection::check_resultState(), and TraCIAPI::check_resultState().
|
protected |
Receive up to len
available bytes from Socket::socket_.
Definition at line 431 of file socket.cpp.
References BailOnSocketError(), and socket_.
Referenced by receive(), and receiveComplete().
void tcpip::Socket::send | ( | const std::vector< unsigned char > & | buffer | ) |
Definition at line 382 of file socket.cpp.
References BailOnSocketError(), printBufferOnVerbose(), send(), and socket_.
Referenced by OutputDevice_Network::postWriteHook(), send(), and sendExact().
void tcpip::Socket::sendExact | ( | const Storage & | b | ) |
Definition at line 412 of file socket.cpp.
References tcpip::Storage::begin(), tcpip::Storage::end(), lengthLen, send(), tcpip::Storage::size(), and tcpip::Storage::writeInt().
Referenced by libtraci::Connection::addFilter(), libtraci::Connection::close(), TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), libtraci::Connection::doCommand(), TraCIAPI::getVersion(), TraCIAPI::load(), TraCIAPI::processGet(), TraCIAPI::processSet(), TraCIAPI::send_commandClose(), TraCIAPI::send_commandSetOrder(), TraCIAPI::send_commandSimulationStep(), TraCIAPI::send_commandSubscribeObjectContext(), TraCIAPI::send_commandSubscribeObjectVariable(), libtraci::Connection::setOrder(), TraCIAPI::setOrder(), libtraci::Connection::simulationStep(), and libtraci::Connection::subscribe().
void tcpip::Socket::set_blocking | ( | bool | blocking | ) |
Definition at line 304 of file socket.cpp.
References BailOnSocketError(), blocking_, and server_socket_.
Referenced by accept().
|
inline |
|
private |
Definition at line 122 of file socket.h.
Referenced by accept(), is_blocking(), and set_blocking().
|
private |
|
staticprotected |
Length of the message length part of a TraCI message.
Definition at line 101 of file socket.h.
Referenced by receiveExact(), and sendExact().
|
private |
|
private |
Definition at line 121 of file socket.h.
Referenced by accept(), set_blocking(), and ~Socket().
|
private |
Definition at line 120 of file socket.h.
Referenced by accept(), close(), connect(), has_client_connection(), receive(), recvAndCheck(), send(), and ~Socket().
|
private |
Definition at line 124 of file socket.h.
Referenced by printBufferOnVerbose(), set_verbose(), and verbose().