#include <sockets.h>


Public Member Functions | |
| INConnect (const AddressList &addr) | |
| void | init (SOCKET socket) |
| operator SOCKET () | |
| void | connect (const AddressList &addr) |
| void | bind (const AddressList &addr) |
| void | close () |
| int | receive (char *buffer, size_t len, int flags=0) |
| int | receive_fragmented (char *buffer, int len, int flags=0) |
| int | send (const char *buffer, size_t len, int flags=0) |
Protected Attributes | |
| SOCKET | _sock |
Definition at line 477 of file sockets.h.
| INConnect::INConnect | ( | const AddressList & | addr ) | [inline] |
Definition at line 479 of file sockets.h.
References Socket::connect().
{
Socket::connect(addr);
}

| void Socket::bind | ( | const AddressList & | addr ) | [inline, inherited] |
Definition at line 237 of file sockets.h.
References Socket::_sock, closesocket, AddressList::get_first(), INVALID_SOCKET, and SOCKET_ERROR.
Referenced by HttpServer::register_url().
{
assert(_sock==INVALID_SOCKET);
// create and bind a socket to one of the given addresses
for(const addrinfo*pai=addr.get_first(); pai; pai=pai->ai_next) {
_sock = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if (_sock != INVALID_SOCKET)
if (::bind(_sock, pai->ai_addr, pai->ai_addrlen) != SOCKET_ERROR)
return;
else
::closesocket(_sock);
}
throw LWSE();
}


| void Socket::close | ( | ) | [inline, inherited] |
Definition at line 255 of file sockets.h.
References Socket::_sock, closesocket, and INVALID_SOCKET.
Referenced by HttpServer::handle_request(), HttpServer::send(), HttpServer::unregister_url(), and Socket::~Socket().
{
if (_sock != INVALID_SOCKET) {
/*
The Winsock Programmer's FAQ recommends explicitly shutdown down the socket before closing it,
but it considerably slows down the message processing when not using persistsnt connections.
if (shutdown(_sock, SD_SEND) != SOCKET_ERROR) {
char buffer[1024];
do {
} while(recv(_sock, (char*)buffer, sizeof(buffer), 0) > 0); // != SOCKET_ERROR
}
*/
::closesocket(_sock);
_sock = INVALID_SOCKET;
}
}

| void Socket::connect | ( | const AddressList & | addr ) | [inline, inherited] |
Definition at line 219 of file sockets.h.
References Socket::_sock, closesocket, AddressList::get_first(), INVALID_SOCKET, and SOCKET_ERROR.
Referenced by INConnect().
{
assert(_sock==INVALID_SOCKET);
// create and connect a new socket to one of the given addresses
for(const addrinfo*pai=addr.get_first(); pai; pai=pai->ai_next) {
_sock = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if (_sock != INVALID_SOCKET)
if (::connect(_sock, pai->ai_addr, pai->ai_addrlen) != SOCKET_ERROR)
return;
else
::closesocket(_sock);
}
throw LWSE();
}


| void Socket::init | ( | SOCKET | socket ) | [inline, inherited] |
Definition at line 207 of file sockets.h.
References Socket::_sock.
Referenced by HttpServer::receive_request(), and Socket::Socket().
{
_sock = socket;
}

| Socket::operator SOCKET | ( | ) | [inline, inherited] |
| int Socket::receive | ( | char * | buffer, |
| size_t | len, | ||
| int | flags = 0 |
||
| ) | [inline, inherited] |
Definition at line 275 of file sockets.h.
References Socket::receive_fragmented().
Referenced by SocketReader::read().
{
int sum = 0;
while(len > 0) {
int rcvd = receive_fragmented(buffer, len, flags);
if (rcvd <= 0)
break;
buffer += rcvd;
len -= rcvd;
sum += rcvd;
}
return sum;
}


| int Socket::receive_fragmented | ( | char * | buffer, |
| int | len, | ||
| int | flags = 0 |
||
| ) | [inline, inherited] |
Definition at line 293 of file sockets.h.
References Socket::_sock, SOCKET_ERROR, WSAEWOULDBLOCK, and WSAGetLastError.
Referenced by SocketReader::fetch(), Socket::receive(), and SocketReader::receive_all().
{
int ret = ::recv(_sock, (char*)buffer, len, flags);
if (ret == SOCKET_ERROR) {
int error = WSAGetLastError();
if (error == WSAEWOULDBLOCK)
ret = 0;
else
throw LWSE();
}
return ret;
}

| int Socket::send | ( | const char * | buffer, |
| size_t | len, | ||
| int | flags = 0 |
||
| ) | [inline, inherited] |
Definition at line 310 of file sockets.h.
References Socket::_sock, and SOCKET_ERROR.
Referenced by HttpServer::send().
{
int ret = ::send(_sock, buffer, len, flags);
if (ret == SOCKET_ERROR)
throw LWSE();
return ret;
}

SOCKET Socket::_sock [protected, inherited] |
Definition at line 321 of file sockets.h.
Referenced by Socket::bind(), Socket::close(), Socket::connect(), Socket::init(), Socket::operator SOCKET(), Socket::receive_fragmented(), and Socket::send().
1.7.2