Commit Graph
132 Commits
Author SHA1 Message Date
Fred Nicolson 32767786af Moving enums to enum classes 2019-05-01 17:06:09 +01:00
Fred Nicolson abd6dbebad Fix ODR violations 2019-05-01 10:27:44 +01:00
Fred Nicolson c23a77d4cc Cleaned up code. Updated documentation. 2019-04-30 17:29:03 +01:00
Fred Nicolson 7f1c25a73b Don't set SO_REUSEADDR on Windows 2019-04-26 09:59:57 +01:00
Fred Nicolson 00f13e41e7 Added the ability to set write timeouts
Similar to read timeouts.
2019-04-02 10:34:31 +01:00
Fred Nicolson 6814219cbb Bug fixes. fr::Socket::send_raw now behaves like receive_raw.
Added missing virtual destructors in abstract classes.
2019-03-21 16:24:22 +00:00
Fred Nicolson 7343529302 Add support for extracting std::vector<bool> from packets 2019-01-17 11:51:18 +00:00
Fred Nicolson 992fbc885e Added NoRouteToHost error. Fixed Disconnect not being returned by Socket 2019-01-15 11:09:11 +00:00
Fred Nicolson d53cc86fb9 Fixed Windows build 2019-01-14 15:57:39 +00:00
Fred Nicolson cb532d41b2 Improvements to error reporting 2019-01-14 13:33:08 +00:00
Fred Nicolson 16bb072c12 Remove unused variable from HttpRequest. Remove redundant noexcept. 2018-12-11 16:02:42 +00:00
Fred Nicolson 8ee8e264b9 Remove Opaque object on failure to add to EPOLL
delete shouldn't have been used.
2018-11-28 21:51:22 +00:00
Fred Nicolson 60316be04c Fix Windows build error 2018-11-28 13:32:41 +00:00
Fred Nicolson 8ea8eafdd8 SocketSelector fixes. Set SO_REUSEPORT. 2018-11-28 13:21:50 +00:00
Fred Nicolson 87f8ee21b1 Fix missing \r after Connection:keep-alive header in HTTP requests 2018-11-26 16:40:18 +00:00
Fred Nicolson dd1322385b Return opaque data when socket is removed 2018-11-23 15:59:53 +00:00
Fred Nicolson dc247c556d Fix fr::Socket receive_all bug
Introduced with disconnect tweaking a few days ago.
2018-11-19 17:01:57 +00:00
Fred Nicolson 697573cbaf Don't throw an exception if epoll_wait is interrupted 2018-11-19 16:02:07 +00:00
Fred Nicolson 252a4788b5 Added ability to set/get HTTP response/request version
+ Additional tests
2018-11-19 15:23:10 +00:00
Fred Nicolson 9b22eb4604 SocketSelector bug fixes. Don't disconnect socket on read/write error. 2018-11-16 16:45:18 +00:00
Fred Nicolson 5aecba03ef URL Parse fix 2018-10-25 10:41:21 +01:00
Fred Nicolson 322f53841b Removed SocketReactor. Switched SocketSelector implementation to EPOLL
Should result in better performance, although a Windows implementation is not yet ready.
2018-10-01 15:36:13 +01:00
Fred Nicolson f5d8dd201b Add additional fr::Packet utility functions. Fixed some build warnings.
Fixed some sign comparison warnings.

Added utility functions to fr::Packet's for:

Getting read cursor position.
Relative read cursor seeking.
Asserting that data remains in the packet
Getting the amount of data remaining
Getting the size of the packet
2018-08-22 16:18:11 +01:00
Fred Nicolson 257e918646 Fix Windows build error 2018-08-16 11:42:22 +01:00
Fred Nicolson 6a0cf23519 Don't reconfigure socket if not connected 2018-08-16 11:37:48 +01:00
Fred Nicolson 8a4ee937b1 Added ability to set/get recv timeouts. Fixed HTTP receive bug.
Recv timeouts can now be specified for sockets, which is the maximum amount of time to wait before returning during a receive. They will return WouldBlock if no data was received during the wait time.

Receiving a HTTP request in non-blocking mode will no longer fail.
2018-08-16 11:24:52 +01:00
Fred Nicolson decb0b10f9 Fixed broken get_remote_address() for sockets accepted over SSL
+ A few other correctness fixes.
2018-08-13 12:35:52 +01:00
Fred Nicolson db738e9503 Bug fixes
Added missing move/copy constructor deletors to SSLSocket, to prevent the object from becoming invalid.

Removed noexcept specifier from some constructors where valid exceptions can be thrown.

Exceptions are now thrown from the SSLSocket constructor if it fails to initialise properly, rather than printing something out to stderr and continuing.
2018-08-08 11:04:23 +01:00
Fred Nicolson 5a790e4caa Added version file. Moved things into correct namespace.
Added version file for getting library info.

Some stuff, like Base64/Sha1 wasn't in the fr namespace. Has been moved into it.
2018-07-12 12:10:55 +01:00
Fred Nicolson fb28a03c2b Fixed Windows connect() bug for TcpSocket
The socket is put into non-blocking mode prior to connecting. Previously, errno was being checked after connecting to see if the socket would block. This is the correct behaviour on Linux. On Windows however, errno remains 0, and WSAGetLastError() needs to be compared against WSAEWOULDBLOCK instead.
2018-07-12 11:46:59 +01:00
Unknown 79d2037bc4 Moving network encoding functions into the fr namespace
To prevent collision with msvc.
2018-04-11 19:36:18 +01:00
Fred Nicolson 27d02ca055 fr::Packet optimisations & marking Sendable::send() as const
Replaced instances of resize&memcpy with append, which gives a noticeable performance boost.

fr::Packet::operator<<(const char *str) no longer converts str into an std::string before adding it, removing an unneeded copy.

fr::Packet::clear no longer calls erase, should result in more of the internal buffer remaining allocated.

Framing for std::vector's has been changed from a uint64_t to a uint32_t (breaking change for packet framing!)
2018-03-27 12:03:55 +01:00
Unknown fa843b57c8 Added experimental WebSocket support.
Added Sha1 hash, and Base64 encode implementations which are optionally compiled if websock support is enabled, to assist in the WebSock handshake.

Added WebSocket to manage the WebSock protocol during connections.

Added WebFrame to allow for sending/receiving data through the WebSock protocol easily.
2018-03-01 23:03:05 +00:00
Fred Nicolson 103e0faaae Bug fixes. HTTP parsing improvements. More tests.
Fixed TcpSocket::set_descriptor(nullptr) causing an invalid read from address 0x0.

Improved HTTP response/request parsing so that they report a parse failure if the first few bytes of the HTTP request don't match the expected format rather than continuing to look for an end of header.

Fixed broken fr::Http::url_encode() implementation.

Optimised fr::Http::url_decode() implementation.

Added fr::Http unit tests.
2018-03-01 15:51:57 +00:00
Unknown 62d8b7ba63 Bug fixes. Documentation improvements.
Fixed SSLListener failing to accept SSLSockets properly (not setting the descriptor properly).

TcpSocket::receive_raw and SSLSocket::receive_raw now behave the same, rather than SSLSocket acting more like Socket::receive_all.

Documented specific return values from Socket::receive_all().

Socket::receive_all now returns WouldBlock if the socket is in blocking mode and the first read returns no data, so it doesn't behave like a blocking socket.

Disabled copying/moving of sockets. Copying shouldn't have been enabled, but might add move constructors in the future.

Added Socket::disconnect, which internally just calls close_socket, to allow for protocol-specific disconnect sequences in the future (WebSockets).
2018-02-28 23:44:31 +00:00
Unknown 0840c07e24 Improving build system
Instead of #ifdefing files out, they are no longer included by CMake instead.
2018-02-24 21:14:43 +00:00
Fred Nicolson ff25d11089 Removed socket mutexes. Added more tests. Improved examples.
Socket mutexes are no longer really required, and so have been removed.

Added more tests for network encoding functions, and the URL parser.

The URL parser now returns a path preceeded with a '/' instead of cutting it out. Added get_uri() to URL, for getting the whole URI, so users don't have to concat it themselves from the more specialised functions.

Fixed default socket connect timeout checking for the wrong value.

Fixed request_type_strings not containing all of the possible request types.

Fixed README using old socket close syntax.

Cleaned up the examples a bit.
2018-02-01 11:56:34 +00:00
Fred Nicolson ad847f0052 HTTP parsing bug fixes, added tests
Fixed HTTP request parse failing if the URI was too short. 

Fixed HTTP parser not converting POST/GET data to lowercase before storing it, making post and get data which contained capitals impossible to access.
2018-01-26 13:18:45 +00:00
Fred Nicolson 30354f15bc Added support for connect timeouts.
Both fr::TcpSocket and fr::SSLSocket can have timeouts specified when connecting. This works by putting the socket into non-blocking mode, making a connect, and then selecting on the socket for the requested timeout. If the select times out then we've failed to connect, if it didn't time out then we've connected.
2018-01-10 17:08:16 +00:00
Unknown 2215d068af Added the ability to specify listen queue depth through CMake
Rather than defaulting to 10
2017-12-24 12:05:16 +00:00
Fred Nicolson b574800a0a Fixed compile warnings and a memory leak
Fixed -fPIC warnings and unused function warnings on GCC. 

Fixed fr::TcpSocket not calling freeaddrinfo() on failure to connect, causing a small leak.
2017-12-01 10:59:00 +00:00
Fred Nicolson c8e03f2df8 Added more tests. Tweaks.
Receiving an http request/response will now return errors like HttpHeaderTooBig, instead of the type being set to that.

Added fr::Socket::status_to_string for converting status values into English strings.
2017-09-25 16:19:47 +01:00
Fred Nicolson abb3655739 Bug fixes and socket improvements
Added the ability to disable certificate verification for SSL sockets which is useful for testing.

Added the ability to specify maximum HTTP request header/body sizes in the CMake build config to prevent a malicious client from causing OOM errors.

Fixed a bug in HttpResponse and HttpRequest parse causing it to abort if the request is invalid in some cases.
2017-09-25 12:29:52 +01:00
Fred Nicolson 5c2b6c3a8d Fixed request parse issues on Windows
Tests on Windows now passing.

For some reason, std::string::find was not returning std::string::npos despite not finding anything on MinGW.
2017-08-23 11:50:57 +01:00
Fred Nicolson 5e5117ff3f Merge remote-tracking branch 'origin/master' 2017-08-23 11:23:06 +01:00
Fred Nicolson 987becd8d0 Fixed WSAInit not being called by fr::Listener
This would mean that if a listener was created before a socket, then it would fail to bind.
2017-08-23 11:23:00 +01:00
Unknown b85924b801 Fixed Windows build error 2017-08-22 16:09:28 +01:00
Fred Nicolson f1db713069 Made POST/GET/HEADER members case insensitive again
It broke things. Bad.
2017-08-22 13:57:08 +01:00
Fred Nicolson 0bd41ec6bd get_remote_address() now works on SSL sockets accepted through SSLListener
Post/get/... data is no longer case insensitive.
2017-08-02 17:32:16 +01:00
Fred Nicolson cfda0f969e Specified default move/copy constructors/operators to Http/Response/Request 2017-08-01 16:15:43 +01:00