Win32 implementation of IArchNetwork. More...
#include <CArchNetworkWinsock.h>
Inherits IArchNetwork.
Public Member Functions | |
virtual CArchSocket | newSocket (EAddressFamily, ESocketType) |
Create a new socket. | |
virtual CArchSocket | copySocket (CArchSocket s) |
Copy a socket object. | |
virtual void | closeSocket (CArchSocket s) |
Release a socket reference. | |
virtual void | closeSocketForRead (CArchSocket s) |
Close socket for further reads. | |
virtual void | closeSocketForWrite (CArchSocket s) |
Close socket for further writes. | |
virtual void | bindSocket (CArchSocket s, CArchNetAddress addr) |
Bind socket to address. | |
virtual void | listenOnSocket (CArchSocket s) |
Listen for connections on socket. | |
virtual CArchSocket | acceptSocket (CArchSocket s, CArchNetAddress *addr) |
Accept connection on socket. | |
virtual bool | connectSocket (CArchSocket s, CArchNetAddress name) |
Connect socket. | |
virtual int | pollSocket (CPollEntry[], int num, double timeout) |
Check socket state. | |
virtual void | unblockPollSocket (CArchThread thread) |
Unblock thread in pollSocket(). | |
virtual size_t | readSocket (CArchSocket s, void *buf, size_t len) |
Read data from socket. | |
virtual size_t | writeSocket (CArchSocket s, const void *buf, size_t len) |
Write data from socket. | |
virtual void | throwErrorOnSocket (CArchSocket) |
Check error on socket. | |
virtual bool | setNoDelayOnSocket (CArchSocket, bool noDelay) |
Turn Nagle algorithm on or off on socket. | |
virtual bool | setReuseAddrOnSocket (CArchSocket, bool reuse) |
Turn address reuse on or off on socket. | |
virtual std::string | getHostName () |
Return local host's name. | |
virtual CArchNetAddress | newAnyAddr (EAddressFamily) |
Create an "any" network address. | |
virtual CArchNetAddress | copyAddr (CArchNetAddress) |
Copy a network address. | |
virtual CArchNetAddress | nameToAddr (const std::string &) |
Convert a name to a network address. | |
virtual void | closeAddr (CArchNetAddress) |
Destroy a network address. | |
virtual std::string | addrToName (CArchNetAddress) |
Convert an address to a host name. | |
virtual std::string | addrToString (CArchNetAddress) |
Convert an address to a string. | |
virtual EAddressFamily | getAddrFamily (CArchNetAddress) |
Get an address's family. | |
virtual void | setAddrPort (CArchNetAddress, int port) |
Set the port of an address. | |
virtual int | getAddrPort (CArchNetAddress) |
Get the port of an address. | |
virtual bool | isAnyAddr (CArchNetAddress) |
Test for the "any" address. | |
virtual bool | isEqualAddr (CArchNetAddress, CArchNetAddress) |
Test addresses for equality. |
Win32 implementation of IArchNetwork.
Definition at line 51 of file CArchNetworkWinsock.h.
CArchSocket CArchNetworkWinsock::acceptSocket | ( | CArchSocket | s, | |
CArchNetAddress * | addr | |||
) | [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.
Implements IArchNetwork.
Definition at line 297 of file CArchNetworkWinsock.cpp.
void CArchNetworkWinsock::bindSocket | ( | CArchSocket | s, | |
CArchNetAddress | addr | |||
) | [virtual] |
Bind socket to address.
Binds socket s
to the address addr
.
Implements IArchNetwork.
Definition at line 275 of file CArchNetworkWinsock.cpp.
void CArchNetworkWinsock::closeSocket | ( | CArchSocket | s | ) | [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.
Implements IArchNetwork.
Definition at line 226 of file CArchNetworkWinsock.cpp.
void CArchNetworkWinsock::closeSocketForRead | ( | CArchSocket | s | ) | [virtual] |
Close socket for further reads.
Calling this disallows future reads on socket s
.
Implements IArchNetwork.
Definition at line 251 of file CArchNetworkWinsock.cpp.
void CArchNetworkWinsock::closeSocketForWrite | ( | CArchSocket | s | ) | [virtual] |
Close socket for further writes.
Calling this disallows future writes on socket s
.
Implements IArchNetwork.
Definition at line 263 of file CArchNetworkWinsock.cpp.
bool CArchNetworkWinsock::connectSocket | ( | CArchSocket | s, | |
CArchNetAddress | addr | |||
) | [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.
Implements IArchNetwork.
Definition at line 345 of file CArchNetworkWinsock.cpp.
CArchSocket CArchNetworkWinsock::copySocket | ( | CArchSocket | s | ) | [virtual] |
Copy a socket object.
Returns a reference to to socket referred to by s
.
Implements IArchNetwork.
Definition at line 214 of file CArchNetworkWinsock.cpp.
bool CArchNetworkWinsock::isAnyAddr | ( | CArchNetAddress | addr | ) | [virtual] |
Test for the "any" address.
Returns true if addr
is the "any" address. newAnyAddr()
returns an "any" address.
Implements IArchNetwork.
Definition at line 819 of file CArchNetworkWinsock.cpp.
References getAddrFamily().
void CArchNetworkWinsock::listenOnSocket | ( | CArchSocket | s | ) | [virtual] |
Listen for connections on socket.
Causes the socket s
to begin listening for incoming connections.
Implements IArchNetwork.
Definition at line 286 of file CArchNetworkWinsock.cpp.
CArchSocket CArchNetworkWinsock::newSocket | ( | EAddressFamily | , | |
ESocketType | ||||
) | [virtual] |
Create a new socket.
The socket is an opaque data type.
Implements IArchNetwork.
Definition at line 189 of file CArchNetworkWinsock.cpp.
int CArchNetworkWinsock::pollSocket | ( | CPollEntry | [], | |
int | num, | |||
double | timeout | |||
) | [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)
Implements IArchNetwork.
Definition at line 364 of file CArchNetworkWinsock.cpp.
References IArchNetwork::kPOLLERR, IArchNetwork::kPOLLIN, IArchNetwork::kPOLLNVAL, IArchNetwork::kPOLLOUT, IArchNetwork::CPollEntry::m_revents, IArchNetwork::CPollEntry::m_socket, and CArchMultithreadWindows::newCurrentThread().
size_t CArchNetworkWinsock::readSocket | ( | CArchSocket | s, | |
void * | buf, | |||
size_t | len | |||
) | [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.
Implements IArchNetwork.
Definition at line 526 of file CArchNetworkWinsock.cpp.
bool CArchNetworkWinsock::setNoDelayOnSocket | ( | CArchSocket | , | |
bool | noDelay | |||
) | [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.
Implements IArchNetwork.
Definition at line 592 of file CArchNetworkWinsock.cpp.
bool CArchNetworkWinsock::setReuseAddrOnSocket | ( | CArchSocket | , | |
bool | reuse | |||
) | [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.
Implements IArchNetwork.
Definition at line 616 of file CArchNetworkWinsock.cpp.
void CArchNetworkWinsock::throwErrorOnSocket | ( | CArchSocket | s | ) | [virtual] |
Check error on socket.
If the socket s
is in an error state then throws an appropriate XArchNetwork exception.
Implements IArchNetwork.
Definition at line 562 of file CArchNetworkWinsock.cpp.
void CArchNetworkWinsock::unblockPollSocket | ( | CArchThread | thread | ) | [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.
Implements IArchNetwork.
Definition at line 515 of file CArchNetworkWinsock.cpp.
size_t CArchNetworkWinsock::writeSocket | ( | CArchSocket | s, | |
const void * | buf, | |||
size_t | len | |||
) | [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.
Implements IArchNetwork.
Definition at line 542 of file CArchNetworkWinsock.cpp.