CarobNS::JavaSocket Class Reference

Generic socket wrapper class to exchange data with Java world. More...

#include <JavaSocket.hpp>

Inheritance diagram for CarobNS::JavaSocket:

CarobNS::DriverSocket List of all members.

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(.

Detailed Description

Generic socket wrapper class to exchange data with Java world.

This class can read and write basic Java types over a socket. It does *not* follow any protocol but java pure serialization.

See also:
DriverSocket class for sequoia protocol.


Constructor & Destructor Documentation

virtual CarobNS::JavaSocket::~JavaSocket (  )  throw (SocketIOException, UnexpectedException) [virtual]

Destructor for disconnection - closes the socket.

Exceptions:
SocketIOException 


Member Function Documentation

bool CarobNS::JavaSocket::isValid (  )  const [inline]

Gives socket validity status.

Returns:
true if the socket is valid (has been created), so connectTo(const std::wstring& host, in_port_t port) can be called

bool CarobNS::JavaSocket::isConnected (  )  const [inline]

Gives connection status.

Returns:
true if the socket is connected to a host

bool CarobNS::JavaSocket::create ( bool  blocking = true  )  throw (ConnectionException, UnexpectedException)

Creates the socket.

Parameters:
blocking whether or not socket operations must be blocking (default is true, blocking socket)
Returns:
true upon successfull creation, false otherwise
Exceptions:
ConnectionException 

bool CarobNS::JavaSocket::connectTo ( const std::wstring &  host,
in_port_t  port 
) throw (ConnectionException, UnexpectedException)

Connects to the given host/port.

Parameters:
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)
Returns:
true upon successfull connection, false otherwise
Exceptions:
ConnectionException 

virtual bool CarobNS::JavaSocket::closeSocket (  )  throw (SocketIOException, UnexpectedException) [virtual]

Closes connection.

Returns:
true if the socket was successfully closed
Exceptions:
SocketIOException 

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.

Parameters:
str string to write
Returns:
the number of bytes send
Exceptions:
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.

Parameters:
str string to read
Returns:
the length read in bytes
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::writeJavaInt ( int32_t  i  )  const throw (SocketIOException, UnexpectedException)

Writes 32bits-integer to socket.

Parameters:
i integer to send
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::readJavaInt ( int32_t &  i  )  const throw (SocketIOException, UnexpectedException)

Reads 32bits-integer from socket.

Parameters:
i resulting integer read from stream
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::writeJavaLong ( int64_t  l  )  const throw (SocketIOException, UnexpectedException)

Writes 64bits-long to socket.

Parameters:
l long to send
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::readJavaLong ( int64_t &  l  )  const throw (SocketIOException, UnexpectedException)

Reads 64bits-long from socket.

Parameters:
l resulting long read from stream
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::writeJavaBool ( bool  b  )  const throw (SocketIOException, UnexpectedException)

Writes a boolean (as a byte) to the socket.

Parameters:
b the boolean to send
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::readJavaBool ( bool &  b  )  const throw (SocketIOException, UnexpectedException)

Reads a boolean (byte) from the socket.

Parameters:
b resulting boolean to read from stream
Exceptions:
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 !

Parameters:
length number of bytes to read
data allocated array of (at least) length bytes
Exceptions:
SocketIOException 

void CarobNS::JavaSocket::writeJavaBytes ( int32_t  length,
java_byte *  data 
) const throw (SocketIOException, UnexpectedException)

Writes an array of bytes to the socket.

Parameters:
length number of bytes to write
data array of (at least) length bytes
Exceptions:
SocketIOException 

int CarobNS::JavaSocket::getFd (  )  const [inline]

Gets the socket file descriptor.

Returns:
the 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.

Parameters:
buf data to send
len full buffer length
flags send options, see recv man page
Returns:
the total number of bytes send, -1 in case of failure

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

Parameters:
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
Exceptions:
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

Parameters:
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
Exceptions:
SocketIOException in case of error


The documentation for this class was generated from the following file:
Generated on Tue Oct 24 09:05:38 2006 for Carob by  doxygen 1.5.0