![]() |
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_. More... | |
void | close () |
void | connect () |
Connects to host_:port_. More... | |
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_. More... | |
bool | receiveExact (Storage &) |
Receive a complete TraCI message from Socket::socket_. More... | |
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. More... | |
Socket (std::string host, int port) | |
Constructor that prepare to connect to host:port. More... | |
bool | verbose () |
~Socket () | |
Destructor. More... | |
Static Public Member Functions | |
static int | getFreeSocketPort () |
Returns an free port on the system. More... | |
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. More... | |
void | receiveComplete (unsigned char *const buffer, std::size_t len) const |
Receive len bytes from Socket::socket_. More... | |
size_t | recvAndCheck (unsigned char *const buffer, std::size_t len) const |
Receive up to len available bytes from Socket::socket_. More... | |
Static Protected Attributes | |
static const int | lengthLen = 4 |
Length of the message length part of a TraCI message. More... | |
Private Member Functions | |
bool | atoaddr (std::string, struct sockaddr_in &addr) |
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 78 of file socket.cpp.
tcpip::Socket::Socket | ( | int | port | ) |
Constructor that prepare for accepting a connection on given port.
Definition at line 91 of file socket.cpp.
tcpip::Socket::~Socket | ( | ) |
Socket * tcpip::Socket::accept | ( | const bool | create = false | ) |
Wait for a incoming connection to port_.
Definition at line 265 of file socket.cpp.
Referenced by TraCIServer::TraCIServer().
|
private |
Definition at line 230 of file socket.cpp.
|
staticprivate |
Definition at line 182 of file socket.cpp.
Referenced by init(), and set_blocking().
void tcpip::Socket::close | ( | ) |
Definition at line 387 of file socket.cpp.
Referenced by TraCIAPI::closeSocket(), OutputDevice_Network::~OutputDevice_Network(), and ~Socket().
void tcpip::Socket::connect | ( | ) |
Connects to host_:port_.
Definition at line 363 of file socket.cpp.
Referenced by TraCIAPI::connect(), and OutputDevice_Network::OutputDevice_Network().
|
private |
Definition at line 205 of file socket.cpp.
|
static |
Returns an free port on the system.
Definition at line 123 of file socket.cpp.
bool tcpip::Socket::has_client_connection | ( | ) | const |
Definition at line 564 of file socket.cpp.
References blocking_.
|
private |
Definition at line 105 of file socket.cpp.
References BailOnSocketError().
bool tcpip::Socket::is_blocking | ( | ) |
Definition at line 573 of file socket.cpp.
int tcpip::Socket::port | ( | ) |
Definition at line 196 of file socket.cpp.
|
protected |
Print label
and buffer
to stderr if Socket::verbose_ is set.
Definition at line 489 of file socket.cpp.
std::vector< unsigned char > tcpip::Socket::receive | ( | int | bufSize = 2048 | ) |
Receive up to bufSize
available bytes from Socket::socket_.
Definition at line 507 of file socket.cpp.
|
protected |
Receive len
bytes from Socket::socket_.
Definition at line 474 of file socket.cpp.
bool tcpip::Socket::receiveExact | ( | Storage & | msg | ) |
Receive a complete TraCI message from Socket::socket_.
Definition at line 532 of file socket.cpp.
Referenced by TraCIAPI::check_resultState().
|
protected |
Receive up to len
available bytes from Socket::socket_.
Definition at line 454 of file socket.cpp.
void tcpip::Socket::send | ( | const std::vector< unsigned char > & | buffer | ) |
Definition at line 405 of file socket.cpp.
Referenced by OutputDevice_Network::postWriteHook().
void tcpip::Socket::sendExact | ( | const Storage & | b | ) |
Definition at line 435 of file socket.cpp.
Referenced by TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), TraCIAPI::load(), TraCIAPI::processGet(), TraCIAPI::processSet(), TraCIAPI::send_commandClose(), TraCIAPI::send_commandSetOrder(), TraCIAPI::send_commandSimulationStep(), TraCIAPI::send_commandSubscribeObjectContext(), TraCIAPI::send_commandSubscribeObjectVariable(), and TraCIAPI::setOrder().
void tcpip::Socket::set_blocking | ( | bool | blocking | ) |
Definition at line 336 of file socket.cpp.
References BailOnSocketError(), blocking_, and server_socket_.
|
inline |
|
private |
Definition at line 122 of file socket.h.
Referenced by has_client_connection(), and set_blocking().
|
staticprotected |
|
private |
Definition at line 121 of file socket.h.
Referenced by set_blocking(), and ~Socket().
|
private |
Definition at line 124 of file socket.h.
Referenced by set_verbose().