golib
0.5
|
#include <goconnection.h>
Public Member Functions | |
void | setRemoteName (goString &name) |
Sets remote computer name. | |
void | setRemoteName (const goString &name) |
Sets remote computer name. | |
void | setRemoteAddress (struct in_addr addr) |
void | setRemoteAddress (goString &addr) |
Sets remote adress NOT YET IMPLEMENTED. | |
void | setRemoteAddress (const char *addr) |
Sets remote adress NOT YET IMPLEMENTED. | |
void | setRemotePort (unsigned short pn) |
Sets remote port number. | |
void | setMyAddress (struct in_addr addr) |
Sets my address. | |
void | setMyAddress (goString &addr) |
Sets my address. | |
void | setMyAddress (const char *addr) |
Sets my address. | |
void | setMyPort (unsigned short pn) |
Sets my portnumber. | |
int | getSocket () |
Returns this connections socket. | |
int | getCurrentConnections () |
gets the current number of connections | |
bool | link (int maxconn=0) |
bool | close () |
bool | fail () |
True if the last operation failed. | |
bool | send (const void *msg, int length, int remote=0, unsigned int flags=0) |
bool | recv (void *buffer, int length, int remote=0, unsigned int flags=0) |
![]() | |
goObjectBase () | |
Constructor. | |
virtual | ~goObjectBase () |
Destructor. More... | |
const char * | getClassName () const |
Returns the class name. More... | |
int | getClassID () const |
virtual goSize_t | memoryUsage () const |
Returns the size of this object or some measure of its memory consumption. More... | |
void | setObjectName (const char *name) |
Set name string for an object. More... | |
void | setObjectName (const goString &name) |
Set name string for an object. More... | |
const goString & | getObjectName () const |
Get the object name. More... | |
virtual bool | writeObjectFile (FILE *) const |
Write object to a file. More... | |
virtual bool | readObjectFile (FILE *) |
Read object from a file. More... | |
void | connectObject (goObjectBase *object) |
Connects an object to this object. More... | |
void | disconnectObject (const goObjectBase *object) |
Disconnects an object from this object. | |
virtual bool | callObjectMethod (int methodID, goObjectMethodParameters *param=NULL) |
Call an object method by identifier. More... | |
virtual bool | queueObjectMethod (int methodID, goObjectMethodParameters *param=NULL, bool blocking=false) |
Enqueue a method call to an internal list of methods. More... | |
bool | callQueuedMethods () |
Call all queued methods. More... | |
Protected Attributes | |
int | maxConnections |
int | currentConnections |
bool | lastFailed |
goString | remoteName |
int | socketDescriptor |
struct sockaddr_in * | remoteSockAddr |
struct hostent * | remoteHostEnt |
needed only if acting as the connecting computer. | |
goArray< int > | remoteSockets |
struct sockaddr_in * | mySockAddr |
Additional Inherited Members | |
![]() | |
void | setClassID (int id) |
Sets the class name. | |
void | printClassMessage (const char *msg) |
Sets the class name. More... | |
void | printClassMessage (goString &msg) |
Prints an informational message to the calling console. More... | |
void | sendObjectMessage (int messageID, void *data=NULL) |
Sends a message to all connected objects. | |
void | sendObjectMessage (goObjectBase *object, int messageID, void *data=NULL) |
Sends a message to a specific object. | |
virtual void | receiveObjectMessage (const goObjectMessage &message) |
Receive a message. More... | |
Provides a TCP/IP connection. Protocol is TCP, the mode is SOCK_STREAM, so this class should result in a reliable connection. This can be used to act as a client (link(0)) or as a server (link(n>0)). When acting as a server (i.e. waiting for requesting connections) you have to use {\ttsetMyPort()} to set the port this computer accepts connections on. The "clients" have to set their remote port numbers using {\ttsetRemotePort()} to the same value (who would have thought ...). Currently, \underline{all actions are blocking}. Thread safety has to be implemented if needed by the user.
bool goNet::goConnection::link | ( | int | maxconn = 0 | ) |
Tries to esablish a link. If maxconn = 0 it assumes to be connecting to a waiting computer. If maxconn > 0 it waits for maxconn computers to connect to it.
bool goNet::goConnection::recv | ( | void * | buffer, |
int | length, | ||
int | remote = 0 , |
||
unsigned int | flags = 0 |
||
) |
Receives a bulk of data in {\tt buffer} of length {\tt length} from the remote host number {\tt remote}. If {\tt maxconn} was larger than zero in {\tt link()}, you have to supply a remote host number you want to receive from.
bool goNet::goConnection::send | ( | const void * | msg, |
int | length, | ||
int | remote = 0 , |
||
unsigned int | flags = 0 |
||
) |
Sends a bulk of data in {\tt msg} of length {\tt length} to the remote host number {\tt remote}. If {\tt maxconn} was larger than zero in {\tt link()}, you have to supply a remote host number you want to send to.
void goNet::goConnection::setRemoteAddress | ( | struct in_addr | addr | ) |
Sets remote adress. The current status is that {\ttlink()} always looks for the name set by {\ttsetRemoteName()} and never uses the raw address (who needs that anyway..).