9 #ifndef __SHAWN_APPS_TCPIP_SOCKET_H
10 #define __SHAWN_APPS_TCPIP_SOCKET_H
13 #include <shawn_config.h>
14 #include "_apps_enable_cmake.h"
27 #include <apps/tcpip/storage.h>
34 {
class SimulationController; }
37 extern "C" void init_tcpip( shawn::SimulationController& );
42 #pragma warning( disable : 4290 )
70 virtual const char*
what()
const throw()
95 void accept() throw( SocketException );
97 void send( const
std::vector<
unsigned char> &buffer) throw( SocketException );
100 std::vector<
unsigned char>
receive(
int bufSize = 2048 ) throw( SocketException );
118 void receiveComplete(
unsigned char *
const buffer, std::size_t len)
const;
120 size_t recvAndCheck(
unsigned char *
const buffer, std::size_t len)
const;
122 void printBufferOnVerbose(
const std::vector<unsigned char> buffer,
const std::string &label)
const;
128 std::string GetWinsockErrorString(
int err)
const;
130 bool atoaddr(std::string,
struct in_addr& addr);
141 static bool init_windows_sockets_;
142 static bool windows_sockets_initialized_;
143 static int instance_count_;
149 #endif // BUILD_TCPIP
SocketException(std::string what)
bool receiveExact(Storage &)
Receive a complete TraCI message from Socket::socket_.
std::vector< unsigned char > receive(int bufSize=2048)
Receive up to bufSize available bytes from Socket::socket_.
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 accept()
Wait for a incoming connection to port_.
static const int lengthLen
Length of the message length part of a TraCI message.
Socket(std::string host, int port)
Constructor that prepare to connect to host:port.
void connect()
Connects to host_:port_.
bool datawaiting(int sock) const
bool atoaddr(std::string, struct in_addr &addr)
void BailOnSocketError(std::string) const
size_t recvAndCheck(unsigned char *const buffer, std::size_t len) const
Receive up to len available bytes from Socket::socket_.
virtual const char * what() const
void send(const std::vector< unsigned char > &buffer)
void sendExact(const Storage &)
void receiveComplete(unsigned char *const buffer, std::size_t len) const
Receive len bytes from Socket::socket_.
bool has_client_connection() const
void set_verbose(bool newVerbose)