50 Commits

Author SHA1 Message Date
d3f8f3a92b Fix incomplete move construction of SSLSocket. Add move constructor to Socket and TcpSocket 2021-06-25 14:34:32 -07:00
Fred Nicolson
5b2b92835e
Add support for chunked HTTP response parsing 2019-11-25 16:29:06 +00:00
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
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
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
9b22eb4604 SocketSelector bug fixes. Don't disconnect socket on read/write error. 2018-11-16 16:45:18 +00: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
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
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
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
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
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
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
84382cad0b Made some changes recommended by Clang-Tidy. 2017-07-20 15:02:43 +01:00
Fred Nicolson
ec95d0ac36 fr::TcpSocket bug fix
Recv's return value was being checked to see if it was greater or equal to 0, if everything was okay. 0 indicates connection closed, and so the socket should have disconnected instead of returning Success.
2017-07-19 10:46:07 +01:00
Fred Nicolson
df509a42f5 Socket and HTTP Response bug fixes
fr::TcpSocket checked if the recv response was greater than 0, which created issues as 0 is a valid result if no data was received and no error occurred.

fr::HttpResponse::construct() now adds in a content-length header.

fr::HttpResponse::parse trims the body if it's larger than content length.

fr::Http::set_uri() now prepends a '/' if one's not provided.

Fixed fr::Http::parse_header from cutting off the end of headers.
2017-07-07 11:05:19 +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
Fred Nicolson
4512bd49e7 Made a few read/write tweaks 2017-03-24 20:18:08 +00:00
Cloaked9000
8ec22b7c56 Windows compatability fixes 2017-02-15 14:29:05 +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
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
Fred Nicolson
2a5d960e56 Added fr::Socket::has_data to check if recv buffer is empty
If using a SocketSelector, you should keep accepting data from the socket until has_data returns false, indicating that you've read everything.
2016-12-27 21:58:39 +00:00
Fred Nicolson
8638b70fb8 Thread safety for send/receive on both Tcp & SSL sockets
Send/Recv often needs to be called multiple times to transfer all of the data. send_raw/receive_raw are now mutex protected and so both send & receive can be called simultaneously.
2016-12-23 18:23:25 +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
7017b64a15 Moved fr::TcpSocket::shutdown to fr::Socket::shutdown 2016-12-20 10:12:13 +00:00
Cloaked9000
9db918c7c2 Added fr::TcpSocket::shutdown to shutdown a socket 2016-12-20 10:07:40 +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
7d3e0fe5c8 Bug fixes & updated SocketSelector example. 2016-12-15 15:47:19 +00:00
Cloaked9000
69d183ed18 Code refactoring 2016-12-15 14:57:01 +00:00
Fred Nicolson
27a88febfa Added ability to toggle socket blocking mode 2016-12-11 20:45:13 +00:00
Fred Nicolson
3b890972d1 Fixed 'host' HTTP header not being sent 2016-12-11 15:14:23 +00:00
Fred Nicolson
fdee42e300 Added ability to both send AND receive HTTP requests and responses. 2016-12-10 16:50:02 +00:00
Fred Nicolson
7aced77a00 Added support for sending and receiving HTTP requests.
Added 'HttpSocket', which inherits TcpSocket and adds a receive and send functions for WebRequest objects.

WebRequest objects can be used to parse, construct and extract HTTP requests. They can be sent through HttpSocket's.
2016-12-10 15:11:01 +00:00
Fred Nicolson
a3eb2ccd0a Added raw send and receive. Fixed TcpSocket close bug.
Can now send and receive raw data over TcpSockets for communicating with other protocols, such as HTTP.

Fixed TcpSocket::close only calling close() if the connection isn't open (gg wp)
2016-12-10 12:59:07 +00:00
Fred Nicolson
9cbe2aa8e8 Fixed some dumb bugs. Think I may have been asleep for last push. 2016-12-09 22:04:37 +00:00
Cloaked9000
d36a98b9b2 Send/Receive works on TcpSocket now 2016-12-09 16:55:53 +00:00
Fred Nicolson
533412d3d0 Work on TcpListener and TcpSocket. 2016-12-08 23:01:01 +00:00
Fred Nicolson
4f9502df23 Pushed code across 2016-12-06 23:07:54 +00:00