Socket Class Reference#include <Socket.h>
Inheritance diagram for Socket:
[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
|
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.
|
int | setTransport (TransportType_t tr) |
| can choose between different transports; will reset the socket
|
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
|
Socket & | operator= (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)
|
Socket * | forwardSock |
| 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)
|
Friends |
class | Wireless |
Member Typedef Documentation
|
the Aibo Networking Toolkit buffer data structure
Definition at line 225 of file Socket.h. |
|
the Aibo Networking Toolkit endpoint data structure
Definition at line 226 of file Socket.h. |
Constructor & Destructor Documentation
Socket::Socket |
( |
int |
sockn |
) |
[inline, explicit] |
|
|
constructor
Definition at line 87 of file Socket.h. |
Socket::~Socket |
( |
|
) |
[virtual] |
|
Socket::Socket |
( |
const Socket & |
|
) |
[protected] |
|
|
copy constructor, don't call
|
Member Function Documentation
bool Socket::getDaemon |
( |
|
) |
const [inline] |
|
int Socket::getPeerAddress |
( |
|
) |
const [inline] |
|
|
returns the address of the remote host in local host byte order
Definition at line 214 of file Socket.h. |
std::string Socket::getPeerAddressAsString |
( |
|
) |
const |
|
|
returns the address of the remote host as a human-readable string
Definition at line 239 of file Socket.cc. |
int Socket::getPeerPort |
( |
|
) |
const [inline] |
|
|
returns the port number that the remote host's socket is on
Definition at line 216 of file Socket.h. |
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 83 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 44 of file Socket.cc.
Referenced by getWriteBuffer(), EventLogger::logImage(), EventLogger::logMessage(), EventLogger::logWebcam(), SegCamBehavior::openPacket(), RegionCamBehavior::openPacket(), RawCamBehavior::openPacket(), WorldStateSerializerBehavior::processEvent(), MicrophoneServer::processEvent(), EventLogger::processEvent(), WMMonitorBehavior::report(), DumpFileControl::selectedFile(), SegCamBehavior::sendCloseConnectionPacket(), RawCamBehavior::sendCloseConnectionPacket(), and write(). |
|
assignment operator, don't call
|
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 160 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 174 of file Socket.cc.
Referenced by ProfilerCheckControl::activate(), HelpControl::activate(), BehaviorReportControl::activate(), BatteryCheckControl::activate(), EventRouter::addListener(), WalkCalibration::addSample(), JPEGGenerator::calcImage(), StewartPlatformBehavior::callback(), SensorObserverControl::checkLogFile(), EventLogger::checkLogFile(), ControlBase::clearMenu(), StewartPlatformBehavior::closeComm(), Controller::closeGUI(), ProjectInterface::displayException(), ControlBase::doReadStdIn(), WalkCalibration::doSelect(), ValueEditControl< T >::doSelect(), ControlBase::doSelect(), StateNode::DoStart(), StareAtPawBehavior2::DoStart(), SegCamBehavior::DoStart(), RegionCamBehavior::DoStart(), RawCamBehavior::DoStart(), HelloWorldBehavior::DoStart(), FreezeTestBehavior::DoStart(), CrashTestBehavior::DoStart(), StateNode::DoStop(), Controller::DoStop(), EmergencyStopMC::EmergencyStopMC(), HeadPointerMC::ensureValidJoint(), WalkCalibration::err(), FreeMemReportControl::freeMem(), Kinematics::getInterestPoint(), CameraBehavior::getNextName(), SpiderMachineBehavior::indent(), Kinematics::init(), Controller::init(), CameraBehavior::initIndex(), PostureMC::isAlive(), HeadPointerMC::isAlive(), StewartPlatformBehavior::isConnected(), WalkMC::LoadBuffer(), SegmentedColorGenerator::LoadBuffer(), RLEGenerator::LoadBuffer(), RegionGenerator::LoadBuffer(), RawCameraGenerator::LoadBuffer(), JPEGGenerator::LoadBuffer(), InterleavedYUVGenerator::LoadBuffer(), CDTGenerator::LoadBuffer(), BufferedImageGenerator::LoadBuffer(), SegmentedColorGenerator::loadColorInfo(), WalkCalibration::loadData(), SegmentedColorGenerator::loadThresholdMap(), Kinematics::lookup(), MotionSequenceMC< MAXMOVE >::newKeyFrame(), CameraBehavior::openNextFile(), ValueEditControl< T >::pause(), Controller::pop(), pprintf(), EchoBehavior::processCallback(), WalkCalibration::processEvent(), ValueEditControl< T >::processEvent(), StepTest::processEvent(), StareAtPawBehavior2::processEvent(), SpiderMachineBehavior::processEvent(), SensorObserverControl::processEvent(), RegionGenerator::processEvent(), RawCameraGenerator::processEvent(), RawCamBehavior::processEvent(), PostureEditor::processEvent(), KinematicSampleBehavior2::processEvent(), KinematicSampleBehavior::processEvent(), FreeMemReportControl::processEvent(), FlashIPAddrBehavior::processEvent(), FilterBankGenerator::processEvent(), EventLogger::processEvent(), EStopControllerBehavior::processEvent(), EchoBehavior::processEvent(), CDTGenerator::processEvent(), CameraBehavior::processEvent(), BufferedImageGenerator::processEvent(), BallDetectionGenerator::processEvent(), ASCIIVisionBehavior::processEvent(), Controller::push(), LoadCalibration::readData(), LoadCalibration::readMaxs(), WaypointWalkControl::refresh(), WalkCalibration::refresh(), ValueEditControl< T >::refresh(), NetworkStatusControl::refresh(), FilterBankGenerator::refresh(), ControlBase::refresh(), WMMonitorBehavior::registerData(), EventRouter::removeListener(), WMMonitorBehavior::report(), WalkCalibration::report(), HelpControl::report(), FreeMemReportControl::report(), BatteryCheckControl::report(), SpiderMachineBehavior::runCommand(), EStopControllerBehavior::runCommand(), SegmentedColorGenerator::SaveBuffer(), RLEGenerator::SaveBuffer(), RegionGenerator::SaveBuffer(), RawCameraGenerator::SaveBuffer(), JPEGGenerator::SaveBuffer(), InterleavedYUVGenerator::SaveBuffer(), CDTGenerator::SaveBuffer(), BufferedImageGenerator::SaveBuffer(), WalkCalibration::saveData(), RawCameraGenerator::SaveFileStream(), BufferedImageGenerator::SaveFileStream(), StewartPlatformBehavior::sax_error(), StewartPlatformBehavior::sax_fatal_error(), StewartPlatformBehavior::sax_start_element(), StewartPlatformBehavior::sax_warning(), LoadWalkControl::selectedFile(), DumpFileControl::selectedFile(), StewartPlatformBehavior::setParam(), ExploreMachine::setup(), WalkCalibration::setupMoving(), SpiderMachineBehavior::spider(), BatteryMonitorBehavior::startWarning(), BatteryMonitorBehavior::stopWarning(), SaveWalkControl::takeInput(), ControlBase::takeInput(), Controller::takeLine(), EmergencyStopMC::trigger(), 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 232 of file Socket.cc. |
|
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 77 of file Socket.cc. |
|
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 123 of file Socket.cc. |
void Socket::setForward |
( |
Socket * |
forsock |
) |
[inline] |
|
|
causes this socket to forward output to sock if it is not connected, pass NULL to unset
Definition at line 156 of file Socket.h. |
void Socket::setTextForward |
( |
|
) |
[inline] |
|
|
causes this socket to forward output to stdout if it is not connected, call setForward(NULL) to unset
Reimplemented in DummySocket.
Definition at line 153 of file Socket.h. |
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 165 of file Socket.h. |
int Socket::vprintf |
( |
const char * |
fmt, |
|
|
va_list |
al |
|
) |
|
|
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 211 of file Socket.cc. |
void Socket::write |
( |
int |
size |
) |
|
|
|
writes the specified number of bytes starting at the pointer returned.
in a (prior) call to getWriteBufer - Parameters:
-
| size | number of bytes to be sent from the current write buffer |
Reimplemented in DummySocket.
Definition at line 62 of file Socket.cc.
Referenced by SegCamBehavior::closePacket(), RegionCamBehavior::closePacket(), RawCamBehavior::closePacket(), StringInputControl::doReadStdIn(), Controller::loadGUI(), EventLogger::logImage(), EventLogger::logMessage(), EventLogger::logWebcam(), EchoBehavior::processCallback(), WorldStateSerializerBehavior::processEvent(), MicrophoneServer::processEvent(), EventLogger::processEvent(), ControlBase::refresh(), BatteryCheckControl::refresh(), WMMonitorBehavior::report(), DumpFileControl::selectedFile(), SegCamBehavior::sendCloseConnectionPacket(), RawCamBehavior::sendCloseConnectionPacket(), and write(). |
Friends And Related Function Documentation
Member Data Documentation
|
blocking or non-blocking flushes... note that blocking flushes only block on the handoff to the system, not actual transmission (at least under aperios)
Definition at line 220 of file Socket.h.
Referenced by flush(), and setFlushType(). |
|
the sent portion of sendData (amount of data which has been sent to system so far)
Definition at line 238 of file Socket.h. |
|
unique non-negative integer representing socket. Serves as index into socket Objects array
Definition at line 83 of file Socket.h.
Referenced by Wireless::close(), Wireless::connect(), Controller::console_callback(), StringInputControl::doReadStdIn(), ControlBase::doReadStdIn(), WMMonitorBehavior::DoStart(), WalkControllerBehavior::DoStart(), UPennWalkControllerBehavior::DoStart(), StewartPlatformBehavior::DoStart(), SpiderMachineBehavior::DoStart(), SpeakerServer::DoStart(), MicrophoneServer::DoStart(), HeadPointControllerBehavior::DoStart(), EStopControllerBehavior::DoStart(), Controller::DoStart(), Aibo3DControllerBehavior::DoStart(), SegCamBehavior::DoStop(), RegionCamBehavior::DoStop(), RawCamBehavior::DoStop(), flush(), Wireless::getDaemon(), Wireless::listen(), EventLogger::logImage(), EventLogger::logMessage(), EventLogger::logWebcam(), SpiderMachineBehavior::processEvent(), SegCamBehavior::processEvent(), RegionCamBehavior::processEvent(), RawCamBehavior::processEvent(), MicrophoneServer::processEvent(), EventLogger::processEvent(), EchoBehavior::processEvent(), ConnectionMadeTrans::processEvent(), WalkCalibration::refresh(), ValueEditControl< T >::refresh(), ControlBase::refresh(), BatteryCheckControl::refresh(), Wireless::setDaemon(), Wireless::setReceiver(), and EchoBehavior::setupNetwork(). |
|
an enum representing the current state of the socket
Definition at line 233 of file Socket.h.
Referenced by Wireless::BindCont(), Wireless::close(), Wireless::CloseCont(), Wireless::connect(), Wireless::ConnectCont(), flush(), getWriteBuffer(), Wireless::isConnected(), Wireless::listen(), Wireless::ListenCont(), Wireless::ReceiveCont(), Wireless::SendCont(), setFlushType(), vprintf(), and write(). |
The documentation for this class was generated from the following files:
|