Public Member Functions | Protected Attributes

INConnect Struct Reference

#include <sockets.h>

Inheritance diagram for INConnect:
Inheritance graph
[legend]
Collaboration diagram for INConnect:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

Definition at line 477 of file sockets.h.


Constructor & Destructor Documentation

INConnect::INConnect ( const AddressList addr ) [inline]

Definition at line 479 of file sockets.h.

References Socket::connect().

    {
        Socket::connect(addr);
    }

Here is the call graph for this function:


Member Function Documentation

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();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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;
        }
    }

Here is the caller graph for this function:

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();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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;
    }

Here is the caller graph for this function:

Socket::operator SOCKET (  ) [inline, inherited]

Definition at line 217 of file sockets.h.

References Socket::_sock.

{return _sock;}
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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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;
    }

Here is the caller graph for this function:

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;
    }

Here is the caller graph for this function:


Member Data Documentation

SOCKET Socket::_sock [protected, inherited]

The documentation for this struct was generated from the following file: