Interface for architecture dependent networking. More...
#include <IArchNetwork.h>
Inherits IInterface.
Inherited by CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Classes | |
class | CPollEntry |
A socket query for poll() . More... | |
Public Types | |
enum | EAddressFamily { kUNKNOWN, kINET } |
Supported address families. | |
enum | ESocketType { kDGRAM, kSTREAM } |
Supported socket types. | |
enum | { kPOLLIN = 1, kPOLLOUT = 2, kPOLLERR = 4, kPOLLNVAL = 8 } |
Events for | |
Public Member Functions | |
manipulators | |
virtual CArchSocket | newSocket (EAddressFamily, ESocketType)=0 |
Create a new socket. | |
virtual CArchSocket | copySocket (CArchSocket s)=0 |
Copy a socket object. | |
virtual void | closeSocket (CArchSocket s)=0 |
Release a socket reference. | |
virtual void | closeSocketForRead (CArchSocket s)=0 |
Close socket for further reads. | |
virtual void | closeSocketForWrite (CArchSocket s)=0 |
Close socket for further writes. | |
virtual void | bindSocket (CArchSocket s, CArchNetAddress addr)=0 |
Bind socket to address. | |
virtual void | listenOnSocket (CArchSocket s)=0 |
Listen for connections on socket. | |
virtual CArchSocket | acceptSocket (CArchSocket s, CArchNetAddress *addr)=0 |
Accept connection on socket. | |
virtual bool | connectSocket (CArchSocket s, CArchNetAddress addr)=0 |
Connect socket. | |
virtual int | pollSocket (CPollEntry[], int num, double timeout)=0 |
Check socket state. | |
virtual void | unblockPollSocket (CArchThread thread)=0 |
Unblock thread in pollSocket(). | |
virtual size_t | readSocket (CArchSocket s, void *buf, size_t len)=0 |
Read data from socket. | |
virtual size_t | writeSocket (CArchSocket s, const void *buf, size_t len)=0 |
Write data from socket. | |
virtual void | throwErrorOnSocket (CArchSocket s)=0 |
Check error on socket. | |
virtual bool | setNoDelayOnSocket (CArchSocket, bool noDelay)=0 |
Turn Nagle algorithm on or off on socket. | |
virtual bool | setReuseAddrOnSocket (CArchSocket, bool reuse)=0 |
Turn address reuse on or off on socket. | |
virtual std::string | getHostName ()=0 |
Return local host's name. | |
virtual CArchNetAddress | newAnyAddr (EAddressFamily)=0 |
Create an "any" network address. | |
virtual CArchNetAddress | copyAddr (CArchNetAddress)=0 |
Copy a network address. | |
virtual CArchNetAddress | nameToAddr (const std::string &)=0 |
Convert a name to a network address. | |
virtual void | closeAddr (CArchNetAddress)=0 |
Destroy a network address. | |
virtual std::string | addrToName (CArchNetAddress)=0 |
Convert an address to a host name. | |
virtual std::string | addrToString (CArchNetAddress)=0 |
Convert an address to a string. | |
virtual EAddressFamily | getAddrFamily (CArchNetAddress)=0 |
Get an address's family. | |
virtual void | setAddrPort (CArchNetAddress, int port)=0 |
Set the port of an address. | |
virtual int | getAddrPort (CArchNetAddress)=0 |
Get the port of an address. | |
virtual bool | isEqualAddr (CArchNetAddress, CArchNetAddress)=0 |
Test addresses for equality. | |
virtual bool | isAnyAddr (CArchNetAddress addr)=0 |
Test for the "any" address. |
Interface for architecture dependent networking.
This interface defines the networking operations required by synergy. Each architecture must implement this interface.
Definition at line 58 of file IArchNetwork.h.
anonymous enum |
Events for poll()
.
Events for poll()
are bitmasks and can be combined using the bitwise operators.
kPOLLIN |
Socket is readable. |
kPOLLOUT |
Socket is writable. |
kPOLLERR |
The socket is in an error state. |
kPOLLNVAL |
The socket is invalid. |
Definition at line 77 of file IArchNetwork.h.
virtual CArchSocket IArchNetwork::acceptSocket | ( | CArchSocket | s, | |
CArchNetAddress * | addr | |||
) | [pure virtual] |
Accept connection on socket.
Accepts a connection on socket s
, returning a new socket for the connection and filling in addr
with the address of the remote end. addr
may be NULL if the remote address isn't required. The original socket s
is unaffected and remains in the listening state. The new socket shares most of the properties of s
except it's not in the listening state and it's connected. Returns NULL if there are no pending connection requests.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::acceptSocket().
virtual void IArchNetwork::bindSocket | ( | CArchSocket | s, | |
CArchNetAddress | addr | |||
) | [pure virtual] |
Bind socket to address.
Binds socket s
to the address addr
.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::bindSocket().
virtual void IArchNetwork::closeSocket | ( | CArchSocket | s | ) | [pure virtual] |
Release a socket reference.
Deletes the given socket object. This does not destroy the socket the object referred to until there are no remaining references for the socket.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::closeSocket().
virtual void IArchNetwork::closeSocketForRead | ( | CArchSocket | s | ) | [pure virtual] |
Close socket for further reads.
Calling this disallows future reads on socket s
.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::closeSocketForRead().
virtual void IArchNetwork::closeSocketForWrite | ( | CArchSocket | s | ) | [pure virtual] |
Close socket for further writes.
Calling this disallows future writes on socket s
.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::closeSocketForWrite().
virtual bool IArchNetwork::connectSocket | ( | CArchSocket | s, | |
CArchNetAddress | addr | |||
) | [pure virtual] |
Connect socket.
Connects the socket s
to the remote address addr
. Returns true if the connection succeed immediately, false if the connection is in progress, and throws if the connection failed immediately. If it returns false, pollSocket()
can be used to wait on the socket for writing to detect when the connection finally succeeds or fails.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::connectSocket().
virtual CArchSocket IArchNetwork::copySocket | ( | CArchSocket | s | ) | [pure virtual] |
Copy a socket object.
Returns a reference to to socket referred to by s
.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::copySocket().
virtual bool IArchNetwork::isAnyAddr | ( | CArchNetAddress | addr | ) | [pure virtual] |
Test for the "any" address.
Returns true if addr
is the "any" address. newAnyAddr()
returns an "any" address.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::isAnyAddr().
virtual void IArchNetwork::listenOnSocket | ( | CArchSocket | s | ) | [pure virtual] |
Listen for connections on socket.
Causes the socket s
to begin listening for incoming connections.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::listenOnSocket().
virtual CArchSocket IArchNetwork::newSocket | ( | EAddressFamily | , | |
ESocketType | ||||
) | [pure virtual] |
Create a new socket.
The socket is an opaque data type.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::newSocket().
virtual int IArchNetwork::pollSocket | ( | CPollEntry | [], | |
int | num, | |||
double | timeout | |||
) | [pure virtual] |
Check socket state.
Tests the state of num
sockets for readability and/or writability. Waits up to timeout
seconds for some socket to become readable and/or writable (or indefinitely if timeout
< 0). Returns the number of sockets that were readable (if readability was being queried) or writable (if writablility was being queried) and sets the m_revents
members of the entries. kPOLLERR
and kPOLLNVAL
are set in m_revents
as appropriate. If a socket indicates kPOLLERR
then throwErrorOnSocket()
can be used to determine the type of error. Returns 0 immediately regardless of the timeout
if no valid sockets are selected for testing.
(Cancellation point)
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::pollSocket().
virtual size_t IArchNetwork::readSocket | ( | CArchSocket | s, | |
void * | buf, | |||
size_t | len | |||
) | [pure virtual] |
Read data from socket.
Read up to len
bytes from socket s
in buf
and return the number of bytes read. The number of bytes can be less than len
if not enough data is available. Returns 0 if the remote end has disconnected and/or there is no more queued received data.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::readSocket().
virtual bool IArchNetwork::setNoDelayOnSocket | ( | CArchSocket | , | |
bool | noDelay | |||
) | [pure virtual] |
Turn Nagle algorithm on or off on socket.
Set socket to send messages immediately (true) or to collect small messages into one packet (false). Returns the previous state.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::setNoDelayOnSocket().
virtual bool IArchNetwork::setReuseAddrOnSocket | ( | CArchSocket | , | |
bool | reuse | |||
) | [pure virtual] |
Turn address reuse on or off on socket.
Allows the address this socket is bound to to be reused while in the TIME_WAIT state. Returns the previous state.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::setReuseAddrOnSocket().
virtual void IArchNetwork::throwErrorOnSocket | ( | CArchSocket | s | ) | [pure virtual] |
Check error on socket.
If the socket s
is in an error state then throws an appropriate XArchNetwork exception.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::throwErrorOnSocket().
virtual void IArchNetwork::unblockPollSocket | ( | CArchThread | thread | ) | [pure virtual] |
Unblock thread in pollSocket().
Cause a thread that's in a pollSocket() call to return. This call may return before the thread is unblocked. If the thread is not in a pollSocket() call this call has no effect.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::unblockPollSocket().
virtual size_t IArchNetwork::writeSocket | ( | CArchSocket | s, | |
const void * | buf, | |||
size_t | len | |||
) | [pure virtual] |
Write data from socket.
Write up to len
bytes to socket s
from buf
and return the number of bytes written. The number of bytes can be less than len
if the remote end disconnected or the internal buffers fill up.
Implemented in CArch, CArchNetworkBSD, and CArchNetworkWinsock.
Referenced by CArch::writeSocket().