Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Socket Class Reference

#include <Socket.h>

Inheritance diagram for Socket:

Inheritance graph
[legend]
List of all members.

Detailed Description

Tekkotsu wireless Socket class.

For more information on using wireless, please read the following tutorials:

The networking interface needs more documentation. It also needs a cleanup. In the mean time, take a look at the TekkotsuMon objects in Tekkotsu/Behaviors/Mon. They all listen for new connections. Unfortunately, at the momement there are no examples of outgoing connections, but it should give you a pretty good idea how to start moving.

Definition at line 79 of file Socket.h.

Public Member Functions

 Socket (int sockn)
 constructor
virtual ~Socket ()
 destructor
byte * getWriteBuffer (int bytesreq)
void write (int size)
 writes the specified number of bytes starting at the pointer returned.
int read ()
 Blocking read. NOT IMPLEMENTED.
byte * getReadBuffer ()
 getReadBuffer is used with blocking read's NOT IMPLEMENTED
unsigned int getMaxSendSize () const
 returns the maximum buffer size for a send
unsigned int getMaxReceiveSize () const
 returns the maximum buffer size for a receive
unsigned int getAvailableSendSize () const
 returns the maximum *currently available* buffer size for a send
unsigned int getAvailableReceiveSize () const
 returns the maximum *currently available* buffer size for a receive
void init ()
 initialize socket member variables. This is different from the constructor since sockets are reused
int setFlushType (FlushType_t fType)
 Chooses between blocking and non-blocking input, output.
FlushType_t getFlushType () const
 returns flush mode
int setTransport (TransportType_t tr)
 can choose between different transports; will reset the socket
TransportType_t getTransport () const
 returns the transport in use
void setTextForward ()
 causes this socket to forward output to stdout if it is not connected, call setForward(NULL) to unset
void setForward (Socket *forsock)
 causes this socket to forward output to sock if it is not connected, pass NULL to unset
void setVerbosity (int verbose)
 Picks a level of verbosity for filtering pprintf commands.
int write (const byte *buf, int size)
int read (byte *buf, int size)
 Blocking read (NOT IMPLEMENTED).
int printf (const char *fmt,...) __attribute__((format(printf
int int vprintf (const char *fmt, va_list al) __attribute__((format(printf
int int int pprintf (int vlevel, const char *fmt,...) __attribute__((format(printf
 Similar to printf, except it takes an extra first argument.
int int int void flush ()
bool getDaemon () const
 returns daemon
int getPeerAddress () const
 returns the address of the remote host in local host byte order
std::string getPeerAddressAsString () const
 returns the address of the remote host as a human-readable string
int getPeerPort () const
 returns the port number that the remote host's socket is on

Public Attributes

int sock
 unique non-negative integer representing socket. Serves as index into socket Objects array

Protected Types

typedef antSharedBuffer buf_t
 the Aibo Networking Toolkit buffer data structure
typedef antModuleRef endp_t
 the Aibo Networking Toolkit endpoint data structure

Protected Member Functions

 Socket (const Socket &)
 copy constructor, don't call
Socketoperator= (const Socket &)
 assignment operator, don't call

Protected Attributes

TransportType_t trType
 stores choice between transports (UDP or TCP (aka Datagram or Stream))
FlushType_t flType
 blocking or non-blocking flushes... note that blocking flushes only block on the handoff to the system, not actual transmission (at least under aperios)
int verbosity
 can be used to filter calls to pprintf
endp_t endpoint
 holds the endpoint data structure for the host OS
ConnectionState state
 an enum representing the current state of the socket
int sendBufSize
 the size of the buffer for sendData and writeData
int recvBufSize
 the size of the buffer for readData and recvData
int sendSize
 the size of sendData (total amount of data from last flush)
int sentSize
 the sent portion of sendData (amount of data which has been sent to system so far)
int recvSize
 the size of recvData (total amount of data returned by system)
int writeSize
 the size of writeData (amount of data so far ready to be flushed)
int readSize
 the size of readData (not used)
bool tx
 a flag set when sendData is in the process of being sent to the system
bool rx
 not used, see readData
buf_t sendBuffer
 under aperios, a pointer to a shared region with the ip stack; under other OS, a pointer to a normal char * buffer
byte * sendData
 a region within sendBuffer, holding data in the process of being sent
byte * writeData
 a region within sendBuffer, holds data still being filled in by user code, not yet flushed
buf_t recvBuffer
 under aperios, a pointer to a shared region with the ip stack; under other OS, a pointer to a normal char * buffer
byte * recvData
 a region within recvBuffer, holding data either just filled in by ip stack (during call to rcvcbckfn), or in the process of being filled in (any other time)
byte * readData
 not used (available for double buffering, but not implemented)
int server_port
 if the socket is a server socket, this is the port it is listening on
int(* rcvcbckfn )(char *, int)
 pointer to callback function, called after recvData has been filled in
int peer_addr
 inet address of peer (if connected) or last message sender (if udp and bound); -1 otherwise (in host byte-order, not network byte-order!)
int peer_port
 port of peer (if connected) or last message sender (if udp and bound); -1 otherwise
bool textForward
 if true, when data is sent to the socket and the socket is not current connected, the data will be sent to stdout (overridden by forwardSock)
char * textForwardBuf
 temporary buffer allocated in getWriteBuffer() and freed in write(), if the output is destined for stdout (textForward)
SocketforwardSock
 if non-NULL, output will be sent to this socket if the current socket is not otherwise connected (overrides textForward)
bool daemon
 if true, the socket will automatically be reopened after any closure (manual or otherwise)
SocketListenersckListener

Friends

class Wireless


Member Function Documentation

void Socket::flush (  ) 

All write commands on the socket will implicity call this. You don't need to call it, unless you're implementing your own write

Reimplemented in DummySocket.

Definition at line 156 of file Socket.cc.

Referenced by flush(), Wireless::SendCont(), vprintf(), and write().

byte * Socket::getReadBuffer (  ) 

getReadBuffer is used with blocking read's NOT IMPLEMENTED

The read(void) and getReadBuffer combo eliminates one buffer copy. You don't need to use getReadBuffer with read(byte*, int)

Blocking read is currently broken - it will be fixed in the next release

Returns:
pointer to the buffer the previous call to blocking read wrote into or NULL if no data was read

Reimplemented in DummySocket.

Definition at line 102 of file Socket.cc.

byte * Socket::getWriteBuffer ( int  bytesreq  ) 

The getWriteBuffer-write(int) combo eliminates one buffer copy. You don't need to use getWriteBuffer with write(byte*, int)

Returns:
pointer to the current position in the current write buffer for this socket or NULL on error
Parameters:
bytesreq maximum number of bytes the caller intends to set before the write method is called

Reimplemented in DummySocket.

Definition at line 45 of file Socket.cc.

Referenced by LGmixin::displayHtmlText(), EventLogger::dumpNode(), getWriteBuffer(), SegCamBehavior::openPacket(), RegionCamBehavior::openPacket(), RawCamBehavior::openPacket(), WorldStateSerializerBehavior::processEvent(), MicrophoneServer::processEvent(), EventLogger::processEvent(), WMMonitorBehavior::report(), DumpFileControl::selectedFile(), SegCamBehavior::sendCloseConnectionPacket(), RawCamBehavior::sendCloseConnectionPacket(), CameraStreamBehavior::sendSensors(), LGmixin::uploadCameraImage(), LGmixin::uploadFile(), and write().

int Socket::pprintf ( int  vlevel,
const char *  fmt,
  ... 
)

Similar to printf, except it takes an extra first argument.

If vlevel is than or equal to the current verbosity level, the string will be printed else it will be ignored.

Parameters:
vlevel if (vlevel<=verbosity) print, else ignore
fmt same as the standard printf's format string

Reimplemented in DummySocket.

Definition at line 185 of file Socket.cc.

int Socket::printf ( const char *  fmt,
  ... 
)

It's standard stuff. man 3 printf on most systems should give you more information

Reimplemented in DummySocket.

Definition at line 199 of file Socket.cc.

Referenced by ProfilerCheckControl::activate(), HelpControl::activate(), BehaviorReportControl::activate(), BatteryCheckControl::activate(), WalkCalibration::addSample(), PNGGenerator::calcImage(), JPEGGenerator::calcImage(), StewartPlatformBehavior::callback(), SensorObserverControl::checkLogFile(), EventLogger::checkLogFile(), ControlBase::clearMenu(), StewartPlatformBehavior::closeComm(), Controller::closeGUI(), ProjectInterface::displayException(), LGmixin::displayHtmlFile(), LGmixin::displayHtmlText(), LGmixin::displayImageFile(), ControlBase::doReadStdIn(), WalkCalibration::doSelect(), ValueEditControl< T >::doSelect(), ControlBase::doSelect(), StateNode::DoStart(), StateNode::DoStop(), Controller::DoStop(), HeadPointerMC::ensureValidJoint(), WalkCalibration::err(), FreeMemReportControl::freeMem(), PNGGenerator::getBinSize(), JPEGGenerator::getBinSize(), Kinematics::getInterestPoint(), EventLogger::indent(), Controller::init(), Kinematics::initStatics(), ControlBase::invalidInput(), PostureMC::isAlive(), HeadPointerMC::isAlive(), StewartPlatformBehavior::isConnected(), WalkMC::loadBuffer(), SegmentedColorGenerator::loadBuffer(), RLEGenerator::loadBuffer(), RegionGenerator::loadBuffer(), RawCameraGenerator::loadBuffer(), PNGGenerator::loadBuffer(), JPEGGenerator::loadBuffer(), InterleavedYUVGenerator::loadBuffer(), CDTGenerator::loadBuffer(), SegmentedColorGenerator::loadColorInfo(), WalkCalibration::loadData(), SegmentedColorGenerator::loadThresholdMap(), Kinematics::lookup(), Kinematics::newChain(), MotionSequenceMC< MAXMOVE >::newKeyFrame(), ValueEditControl< T >::pause(), Controller::pop(), pprintf(), EchoBehavior::processCallback(), WalkCalibration::processEvent(), ValueEditControl< T >::processEvent(), SensorObserverControl::processEvent(), SegCamBehavior::processEvent(), RegionGenerator::processEvent(), RawCameraGenerator::processEvent(), RawCamBehavior::processEvent(), PostureEditor::processEvent(), FreeMemReportControl::processEvent(), FilterBankGenerator::processEvent(), EventLogger::processEvent(), EStopControllerBehavior::processEvent(), EchoBehavior::processEvent(), CDTGenerator::processEvent(), BallDetectionGenerator::processEvent(), EventLogger::processStateMachineEvent(), Controller::push(), LoadCalibration::readData(), LoadCalibration::readMaxs(), CameraStreamBehavior::receiveData(), TorqueCalibrate::record(), WaypointWalkControl::refresh(), WalkCalibration::refresh(), ValueEditControl< T >::refresh(), TorqueCalibrate::refresh(), NetworkStatusControl::refresh(), FilterBankGenerator::refresh(), ControlBase::refresh(), ConfigurationEditor::NamedEnumerationEditor::refresh(), RegionGenerator::RegionGenerator(), WMMonitorBehavior::registerData(), WMMonitorBehavior::report(), WalkCalibration::report(), HelpControl::report(), FreeMemReportControl::report(), BatteryCheckControl::report(), EventLogger::runCommand(), EStopControllerBehavior::runCommand(), SegmentedColorGenerator::saveBuffer(), RLEGenerator::saveBuffer(), RegionGenerator::saveBuffer(), RawCameraGenerator::saveBuffer(), PNGGenerator::saveBuffer(), JPEGGenerator::saveBuffer(), InterleavedYUVGenerator::saveBuffer(), CDTGenerator::saveBuffer(), WalkCalibration::saveData(), RawCameraGenerator::saveFileStream(), StewartPlatformBehavior::sax_error(), StewartPlatformBehavior::sax_fatal_error(), StewartPlatformBehavior::sax_start_element(), StewartPlatformBehavior::sax_warning(), LoadWalkControl::selectedFile(), DumpFileControl::selectedFile(), LGmixin::sendCommand(), CameraStreamBehavior::sendSensors(), StewartPlatformBehavior::setParam(), WalkCalibration::setupMoving(), SegCamBehavior::setupServer(), RegionCamBehavior::setupServer(), RawCamBehavior::setupServer(), BatteryMonitorBehavior::startWarning(), BatteryMonitorBehavior::stopWarning(), SaveWalkControl::takeInput(), ControlBase::takeInput(), Controller::takeLine(), EmergencyStopMC::trigger(), LGmixin::uploadCameraImage(), LGmixin::uploadFile(), write(), and StateNode::~StateNode().

int Socket::read ( byte *  buf,
int  size 
)

Blocking read (NOT IMPLEMENTED).

You might want to consider the read(void) and getReadBuffer combo if you call this often

Blocking read is currently broken - it will be fixed in the next release

Parameters:
buf buffer to write from
size number of bytes to write
Returns:
number of bytes actually read

Reimplemented in DummySocket.

Definition at line 257 of file Socket.cc.

int Socket::read (  ) 

Blocking read. NOT IMPLEMENTED.

Tries to read upto receive buffer size worth of data from this socket.

Blocking read is currently broken - it will be fixed in the next release

Returns:
number of bytes read or -1 on error

Reimplemented in DummySocket.

Definition at line 96 of file Socket.cc.

int Socket::setFlushType ( FlushType_t  fType  ) 

Chooses between blocking and non-blocking input, output.

This function can only be called when a socket is disconnected, since it is a bad idea to mix blocking and non-blocking input, output. The default for a socket is non-blocking

Returns:
0 on success

Reimplemented in DummySocket.

Definition at line 148 of file Socket.cc.

void Socket::setVerbosity ( int  verbose  )  [inline]

Picks a level of verbosity for filtering pprintf commands.

The higher the verbosity, the more the number of messages printed. This is useful for filtering out non-important messages with very little processor cost. Default is 0.

Parameters:
verbose the higher the value of verbose, the more the output

Reimplemented in DummySocket.

Definition at line 174 of file Socket.h.

int Socket::vprintf ( const char *  fmt,
va_list  al 
)

It's standard stuff. man 3 printf on most systems should give you more information

Reimplemented in DummySocket.

Definition at line 209 of file Socket.cc.

Referenced by printf(), StewartPlatformBehavior::sax_error(), StewartPlatformBehavior::sax_fatal_error(), StewartPlatformBehavior::sax_warning(), and vprintf().

int Socket::write ( const byte *  buf,
int  size 
)

You might want to consider the getWriteBuffer-write(int) combo if you call this often

Parameters:
buf buffer to write from
size number of bytes to write
Returns:
the number of bytes actually written or -1 on error

Reimplemented in DummySocket.

Definition at line 236 of file Socket.cc.


The documentation for this class was generated from the following files:

Tekkotsu v3.0
Generated Fri May 11 20:08:48 2007 by Doxygen 1.4.7