About
This is a GPL licensed C++ class library wrapping the berkeley
sockets C API, and therefore works on most unixes and also win32.
The library is in use in a number of real world applications, both commercial and open source.
Features include, but are not limited to, SSL support, IPv6 support,
tcp and udp sockets, sctp sockets, http protocol,
highly customizable error handling.
Testing has been done on Linux and Windows 2000, and to some part on Solaris
and Mac OS X.
The source code is released under the terms of the
GNU GPL,
but is also available under an
alternative license.
History
When making this library, there were a few things I wanted to achieve.
I did not want to end up with C++ code that had to be used in the same
way as the berkeley socket C API are being used ( connect/bind/accept -
check result, write - check result, read - check result, etc, etc ).
Another thing was the ability to manage multiple sockets in the same thread;
the library should be singlethreaded - but not limited to one thread.
So.. I never wanted to manage a fd_set for a select() call ever again, no
more writing code for accepting a connection - this has already been done
again and again in every single networking project ever made.
One decision made early on was to treat one socket as one object. And so was
the Socket class born. The socket class, by itself, has all the functions
needed for address translation (hostname to ip, ip to hostname etc). It
owns the file descriptor / SOCKET handle. But it can't do anything.
Code for actually doing something with the socket is implemented in other,
Socket derived classes.
The approach; A list of active sockets are monitored using the
select() system call.
Events resulting from the select()
call and surrounding logic (read/write/connect/timeout etc) are
reported to each socket using callback methods such as:
- Socket::OnRead()
- Socket::OnWrite()
- Socket::OnConnect()
- Socket::OnAccept()
The list of sockets are contained in a SocketHandler class.
To monitor the sockets, repeated calls to the Select() method are made.
|