41 Commits

Author SHA1 Message Date
Fred Nicolson
32767786af
Moving enums to enum classes 2019-05-01 17:06:09 +01:00
Fred Nicolson
c23a77d4cc
Cleaned up code. Updated documentation. 2019-04-30 17:29:03 +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
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
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
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
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
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
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
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
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
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
84382cad0b Made some changes recommended by Clang-Tidy. 2017-07-20 15:02:43 +01:00
Fred Nicolson
e748fde121 API changes, and lots of fixes.
fr::HttpSocket has been removed.

fr::Sendable has been added. Classes can inherit this if they want to be sendable through sockets. Both fr::Http (which is inherited by fr::HttpRequest and fr::HttpResponse), and fr::Packet inherit this, to allow them to be sent through fr::Socket::send()/fr::Socket::receive().

Fixed broken fr::SocketSelector and fr::SocketReactor, as they no longer accepted fr::Listener's due to fr::Listener no longer inheriting fr::Socket.
2017-07-18 17:34:49 +01:00
Fred Nicolson
1f957649b0 Set SO_EXCLUSIVEADDRUSE option on Windows
This should prevent potential port hijacking.
2017-06-09 09:42:53 +01:00
Unknown
eec983c8b7 Added fr::Socket::set_max_packet_size
Can be used to limit the size of packets being received, to prevent malicious attacks.
2017-06-03 14:39:49 +01:00
Unknown
5778310798 Fixed incompatabilities between GCC and MSCV
Build errors have been fixed, but there are build warnings remaining about unsafe conversions, because Visual C++'s network conversion functions have a differing return type to mine. To be fixed in the future.
2017-05-28 18:09:29 +01:00
Fred Nicolson
ae61464aee Removed is_connected flag in fr::Socket
The socket descriptor is now checked, to see if it's greater than 0, instead. This means that the flag doesn't have to be manually updated.
2017-05-25 16:21:39 +01:00
Fred Nicolson
9646d72e74 Added ability to set address family for sockets. Improved sslcontext.
Certs can now either be loaded from memory or disk.

You can specify if you want to use ipv4/ipv6/either when connecting or accepting.
2017-05-11 11:43:01 +01:00
Cloaked9000
8ec22b7c56 Windows compatability fixes 2017-02-15 14:29:05 +00:00
Cloaked9000
9c520c3a0b Disable SIGPIPE, should disconnect socket now instead 2017-02-14 17:04:21 +00:00
Fred Nicolson
24195e402f Bug fixes
Fixed deadlock in fr::Socket::receive.

Fixed fr::Packet's second constructor not delegating to first, causing it's intenal buffer to remain unitialised.
2017-01-26 21:58:20 +00:00
Fred Nicolson
2abe108d57 Merge fix 2017-01-25 22:59:56 +00:00
Fred Nicolson
fad7d0b81f Packet and socket optimisations
Sending/receiving data on a socket is roughly 5.5x faster, after removing data copies and buffer re-allocations.
2017-01-25 22:57:11 +00:00
Cloaked9000
657c8e21ad Mutex changes 2017-01-23 09:15:40 +00:00
Cloaked9000
e60d961fb0 Windows compatibility fixes 2017-01-06 15:22:22 +00:00
Cloaked9000
1594d4babf Added signed types to packet 2017-01-03 18:10:26 +00:00
Fred Nicolson
e0e956cf78 Socket::reconfigure_socket called on connection to apply options
'TCP_NODELAY' is set automatically on connection now.
2016-12-31 11:14:26 +00:00
Cloaked9000
8a54e8994a Fixed read_raw buffer issues (properly this time).
Also added '<<' overload on Packet for char*
2016-12-21 17:57:39 +00:00
Cloaked9000
f74f1f1a94 Bug fixes. Better syntax.
SocketReactor actually calls callbacks.

receive_all no longer tries to access out of bound array indexes.

fr::Packet constructor can now take as many arguments as you like and they'll be added to it automatically.

Added bool fr::Packet<< operator overload.
2016-12-20 18:02:59 +00:00
Cloaked9000
70779fbe9c Added SocketReactor & fixes
Sockets will immediately return fr::Socket::Status::Disconnected if an attempt to send/receive data is made whilst the connection is closed.

Added SocketReactor, which is effectively a little wrapper around fr::SocketSelector, but can automatically call a callback for a socket when data is received on it.
2016-12-20 11:33:31 +00:00
Cloaked9000
7017b64a15 Moved fr::TcpSocket::shutdown to fr::Socket::shutdown 2016-12-20 10:12:13 +00:00
Cloaked9000
2de9540819 Added windows support. Updated build system.
CMake build system builds as a library, not an executable now.

Windows is now supported and should work fine.
2016-12-19 12:10:39 +00:00
Cloaked9000
69d183ed18 Code refactoring 2016-12-15 14:57:01 +00:00
Fred Nicolson
4f9502df23 Pushed code across 2016-12-06 23:07:54 +00:00