![]() |
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 (std::string host, int port) | |
Constructor that prepare to connect to host:port. More... | |
Socket (int port) | |
Constructor that prepare for accepting a connection on given 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 73 of file socket.cpp.
References init().
Referenced by accept().
tcpip::Socket::Socket | ( | int | port | ) |
Constructor that prepare for accepting a connection on given port.
Definition at line 86 of file socket.cpp.
References init().
tcpip::Socket::~Socket | ( | ) |
Destructor.
Definition at line 147 of file socket.cpp.
References BailOnSocketError(), close(), server_socket_, and socket_.
Referenced by getFreeSocketPort().
Socket * tcpip::Socket::accept | ( | const bool | create = false | ) |
Wait for a incoming connection to port_.
Definition at line 260 of file socket.cpp.
References BailOnSocketError(), blocking_, port_, server_socket_, set_blocking(), Socket(), and socket_.
Referenced by atoaddr(), and TraCIServer::TraCIServer().
|
private |
Definition at line 225 of file socket.cpp.
References accept(), and port_.
Referenced by connect(), and datawaiting().
|
staticprivate |
Definition at line 177 of file socket.cpp.
References port(), and strict_fstream::strerror().
Referenced by accept(), connect(), datawaiting(), getFreeSocketPort(), init(), recvAndCheck(), send(), set_blocking(), and ~Socket().
void tcpip::Socket::close | ( | ) |
Definition at line 382 of file socket.cpp.
References send(), and socket_.
Referenced by TraCIAPI::closeSocket(), connect(), getFreeSocketPort(), OutputDevice_Network::~OutputDevice_Network(), and ~Socket().
void tcpip::Socket::connect | ( | ) |
Connects to host_:port_.
Definition at line 358 of file socket.cpp.
References atoaddr(), BailOnSocketError(), close(), host_, and socket_.
Referenced by TraCIAPI::connect(), OutputDevice_Network::OutputDevice_Network(), receive(), and set_blocking().
|
private |
Definition at line 200 of file socket.cpp.
References atoaddr(), and BailOnSocketError().
|
static |
Returns an free port on the system.
Definition at line 118 of file socket.cpp.
References BailOnSocketError(), close(), port(), and ~Socket().
Referenced by init().
bool tcpip::Socket::has_client_connection | ( | ) | const |
Definition at line 559 of file socket.cpp.
References is_blocking(), and socket_.
Referenced by receiveExact().
|
private |
Definition at line 100 of file socket.cpp.
References BailOnSocketError(), and getFreeSocketPort().
Referenced by Socket().
bool tcpip::Socket::is_blocking | ( | ) |
Definition at line 568 of file socket.cpp.
References blocking_.
Referenced by has_client_connection().
int tcpip::Socket::port | ( | ) |
Definition at line 191 of file socket.cpp.
References datawaiting(), and port_.
Referenced by BailOnSocketError(), and getFreeSocketPort().
|
protected |
Print label
and buffer
to stderr if Socket::verbose_ is set.
Definition at line 484 of file socket.cpp.
References receive(), and verbose_.
Referenced by receive(), receiveComplete(), 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 502 of file socket.cpp.
References connect(), datawaiting(), printBufferOnVerbose(), receiveExact(), recvAndCheck(), and socket_.
Referenced by printBufferOnVerbose().
|
protected |
Receive len
bytes from Socket::socket_.
Definition at line 469 of file socket.cpp.
References printBufferOnVerbose(), and recvAndCheck().
Referenced by receiveExact(), and recvAndCheck().
bool tcpip::Socket::receiveExact | ( | Storage & | msg | ) |
Receive a complete TraCI message from Socket::socket_.
Definition at line 527 of file socket.cpp.
References has_client_connection(), lengthLen, printBufferOnVerbose(), tcpip::Storage::readInt(), receiveComplete(), tcpip::Storage::reset(), and tcpip::Storage::writePacket().
Referenced by TraCIAPI::check_resultState(), and receive().
|
protected |
Receive up to len
available bytes from Socket::socket_.
Definition at line 449 of file socket.cpp.
References BailOnSocketError(), receiveComplete(), and socket_.
Referenced by receive(), receiveComplete(), and sendExact().
void tcpip::Socket::send | ( | const std::vector< unsigned char > & | buffer | ) |
Definition at line 400 of file socket.cpp.
References BailOnSocketError(), printBufferOnVerbose(), sendExact(), and socket_.
Referenced by close(), OutputDevice_Network::postWriteHook(), and sendExact().
void tcpip::Socket::sendExact | ( | const Storage & | b | ) |
Definition at line 430 of file socket.cpp.
References tcpip::Storage::begin(), tcpip::Storage::end(), lengthLen, recvAndCheck(), send(), tcpip::Storage::size(), and tcpip::Storage::writeInt().
Referenced by TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), TraCIAPI::load(), TraCIAPI::processGet(), TraCIAPI::processSet(), send(), 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 331 of file socket.cpp.
References BailOnSocketError(), blocking_, connect(), and server_socket_.
Referenced by accept().
|
private |
Definition at line 123 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 122 of file socket.h.
Referenced by accept(), set_blocking(), and ~Socket().
|
private |
Definition at line 121 of file socket.h.
Referenced by accept(), close(), connect(), has_client_connection(), receive(), recvAndCheck(), send(), and ~Socket().
|
private |
Definition at line 125 of file socket.h.
Referenced by printBufferOnVerbose().