#include <JavaSocket.hpp>
Inheritance diagram for CarobNS::JavaSocket:
Public Member Functions | |
JavaSocket () | |
Default constructor - No connection here, just creates and empty socket. | |
virtual | ~JavaSocket () throw (SocketIOException, UnexpectedException) |
Destructor for disconnection - closes the socket. | |
bool | isValid () const |
Gives socket validity status. | |
bool | isConnected () const |
Gives connection status. | |
bool | create (bool blocking=true) throw (ConnectionException, UnexpectedException) |
Creates the socket. | |
bool | connectTo (const std::wstring &host, in_port_t port) throw (ConnectionException, UnexpectedException) |
Connects to the given host/port. | |
virtual bool | closeSocket () throw (SocketIOException, UnexpectedException) |
Closes connection. | |
size_t | writeJavaUTF (const std::wstring &str) const throw (SocketIOException, CodecException, UnexpectedException) |
Writes a UTF-8 encoded wstring to the socket. | |
size_t | readJavaUTF (std::wstring &str) const throw (SocketIOException, CodecException, UnexpectedException) |
Reads UTF-8 encoded string from socket. | |
void | writeJavaInt (int32_t i) const throw (SocketIOException, UnexpectedException) |
Writes 32bits-integer to socket. | |
void | readJavaInt (int32_t &i) const throw (SocketIOException, UnexpectedException) |
Reads 32bits-integer from socket. | |
void | writeJavaLong (int64_t l) const throw (SocketIOException, UnexpectedException) |
Writes 64bits-long to socket. | |
void | readJavaLong (int64_t &l) const throw (SocketIOException, UnexpectedException) |
Reads 64bits-long from socket. | |
void | writeJavaBool (bool b) const throw (SocketIOException, UnexpectedException) |
Writes a boolean (as a byte) to the socket. | |
void | readJavaBool (bool &b) const throw (SocketIOException, UnexpectedException) |
Reads a boolean (byte) from the socket. | |
void | readJavaBytes (int32_t length, java_byte *data) const throw (SocketIOException, UnexpectedException) |
Reads an array of bytes from the socket. | |
void | writeJavaBytes (int32_t length, java_byte *data) const throw (SocketIOException, UnexpectedException) |
Writes an array of bytes to the socket. | |
int | getFd () const |
Gets the socket file descriptor. | |
Protected Member Functions | |
int32_t | recvFully (void *buf, const int len, const int flags) const |
Substitute for recv. | |
void | sendToSocket (const std::wstring &fctName, const std::wstring &objName, const void *buf, int len, int flags) const throw (SocketIOException, UnexpectedException) |
Wrapper over send(. | |
void | receiveFromSocket (const std::wstring &fctName, const std::wstring &objName, void *buf, int len, int flags) const throw (SocketIOException, UnexpectedException) |
Wrapper around recv(. |
This class can read and write basic Java types over a socket. It does *not* follow any protocol but java pure serialization.
virtual CarobNS::JavaSocket::~JavaSocket | ( | ) | throw (SocketIOException, UnexpectedException) [virtual] |
bool CarobNS::JavaSocket::isValid | ( | ) | const [inline] |
Gives socket validity status.
bool CarobNS::JavaSocket::isConnected | ( | ) | const [inline] |
Gives connection status.
bool CarobNS::JavaSocket::create | ( | bool | blocking = true |
) | throw (ConnectionException, UnexpectedException) |
Creates the socket.
blocking | whether or not socket operations must be blocking (default is true, blocking socket) |
ConnectionException |
bool CarobNS::JavaSocket::connectTo | ( | const std::wstring & | host, | |
in_port_t | port | |||
) | throw (ConnectionException, UnexpectedException) |
Connects to the given host/port.
host | the host to connect to as a string. Can be either numeric IP or fully qualified hostname | |
port | port as a in_addr_t (unsigned int) |
ConnectionException |
virtual bool CarobNS::JavaSocket::closeSocket | ( | ) | throw (SocketIOException, UnexpectedException) [virtual] |
size_t CarobNS::JavaSocket::writeJavaUTF | ( | const std::wstring & | str | ) | const throw (SocketIOException, CodecException, UnexpectedException) |
Writes a UTF-8 encoded wstring to the socket.
This is NOT Java's modified UTF-8, see SEQUOIA-133.
str | string to write |
SocketIOException |
size_t CarobNS::JavaSocket::readJavaUTF | ( | std::wstring & | str | ) | const throw (SocketIOException, CodecException, UnexpectedException) |
Reads UTF-8 encoded string from socket.
This is NOT Java's modified UTF-8, see SEQUOIA-133.
str | string to read |
SocketIOException |
void CarobNS::JavaSocket::writeJavaInt | ( | int32_t | i | ) | const throw (SocketIOException, UnexpectedException) |
void CarobNS::JavaSocket::readJavaInt | ( | int32_t & | i | ) | const throw (SocketIOException, UnexpectedException) |
Reads 32bits-integer from socket.
i | resulting integer read from stream |
SocketIOException |
void CarobNS::JavaSocket::writeJavaLong | ( | int64_t | l | ) | const throw (SocketIOException, UnexpectedException) |
void CarobNS::JavaSocket::readJavaLong | ( | int64_t & | l | ) | const throw (SocketIOException, UnexpectedException) |
Reads 64bits-long from socket.
l | resulting long read from stream |
SocketIOException |
void CarobNS::JavaSocket::writeJavaBool | ( | bool | b | ) | const throw (SocketIOException, UnexpectedException) |
Writes a boolean (as a byte) to the socket.
b | the boolean to send |
SocketIOException |
void CarobNS::JavaSocket::readJavaBool | ( | bool & | b | ) | const throw (SocketIOException, UnexpectedException) |
Reads a boolean (byte) from the socket.
b | resulting boolean to read from stream |
SocketIOException |
void CarobNS::JavaSocket::readJavaBytes | ( | int32_t | length, | |
java_byte * | data | |||
) | const throw (SocketIOException, UnexpectedException) |
Reads an array of bytes from the socket.
The array must be allocated !
length | number of bytes to read | |
data | allocated array of (at least) length bytes |
SocketIOException |
void CarobNS::JavaSocket::writeJavaBytes | ( | int32_t | length, | |
java_byte * | data | |||
) | const throw (SocketIOException, UnexpectedException) |
Writes an array of bytes to the socket.
length | number of bytes to write | |
data | array of (at least) length bytes |
SocketIOException |
int CarobNS::JavaSocket::getFd | ( | ) | const [inline] |
Gets the socket file descriptor.
int32_t CarobNS::JavaSocket::recvFully | ( | void * | buf, | |
const int | len, | |||
const int | flags | |||
) | const [protected] |
Substitute for recv.
Loops/blocks until full length has been received.
buf | data to send | |
len | full buffer length | |
flags | send options, see recv man page |
void CarobNS::JavaSocket::sendToSocket | ( | const std::wstring & | fctName, | |
const std::wstring & | objName, | |||
const void * | buf, | |||
int | len, | |||
int | flags | |||
) | const throw (SocketIOException, UnexpectedException) [protected] |
Wrapper over send(.
..) function to handle errors and throw exceptions
fctName | name of the calling function (for logging purposes) | |
objName | name of the object to be send (for logging purposes) | |
buf | data to be send | |
len | length of buf | |
flags | send option, see recv man page |
SocketIOException |
void CarobNS::JavaSocket::receiveFromSocket | ( | const std::wstring & | fctName, | |
const std::wstring & | objName, | |||
void * | buf, | |||
int | len, | |||
int | flags | |||
) | const throw (SocketIOException, UnexpectedException) [protected] |
Wrapper around recv(.
..) function to handle errors and throw exceptions
fctName | name of the calling function (for logging purposes) | |
objName | name of the object to be send (for logging purposes) | |
buf | buffer in which to put the received data in | |
len | length of buf | |
flags | send option, see send man page |
SocketIOException | in case of error |