Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
2149ac7ed6 | |||
0f21a20fe3 | |||
54db6ec8bb | |||
0e0a748037 | |||
3b19b0eeca | |||
dbfe3104e8 | |||
68fd8c20d6 |
2
.github/workflows/mkdocs.yml
vendored
2
.github/workflows/mkdocs.yml
vendored
@ -21,5 +21,7 @@ jobs:
|
|||||||
pip install pygments
|
pip install pygments
|
||||||
- name: Build doc
|
- name: Build doc
|
||||||
run: |
|
run: |
|
||||||
|
git clean -dfx .
|
||||||
|
git fetch
|
||||||
git pull
|
git pull
|
||||||
mkdocs gh-deploy
|
mkdocs gh-deploy
|
||||||
|
@ -24,6 +24,7 @@ A bad security bug affecting users compiling with SSL enabled and OpenSSL as the
|
|||||||
|
|
||||||
#include <ixwebsocket/IXNetSystem.h>
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
#include <ixwebsocket/IXWebSocket.h>
|
#include <ixwebsocket/IXWebSocket.h>
|
||||||
|
#include <ixwebsocket/IXUserAgent.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -34,6 +35,8 @@ int main()
|
|||||||
// Our websocket object
|
// Our websocket object
|
||||||
ix::WebSocket webSocket;
|
ix::WebSocket webSocket;
|
||||||
|
|
||||||
|
// Connect to a server with encryption
|
||||||
|
// See https://machinezone.github.io/IXWebSocket/usage/#tls-support-and-configuration
|
||||||
std::string url("wss://echo.websocket.org");
|
std::string url("wss://echo.websocket.org");
|
||||||
webSocket.setUrl(url);
|
webSocket.setUrl(url);
|
||||||
|
|
||||||
@ -53,6 +56,12 @@ int main()
|
|||||||
std::cout << "Connection established" << std::endl;
|
std::cout << "Connection established" << std::endl;
|
||||||
std::cout << "> " << std::flush;
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
|
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||||
|
{
|
||||||
|
// Maybe SSL is not configured properly
|
||||||
|
std::cout << "Connection error: " << msg->errorInfo.reason << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [11.2.6] - 2021-05-18
|
||||||
|
|
||||||
|
(Windows) move EINVAL (re)definition from IXSocket.h to IXNetSystem.h (fix #289)
|
||||||
|
|
||||||
|
## [11.2.5] - 2021-04-04
|
||||||
|
|
||||||
|
(http client) DEL is not an HTTP method name, but DELETE is
|
||||||
|
|
||||||
## [11.2.4] - 2021-03-25
|
## [11.2.4] - 2021-03-25
|
||||||
|
|
||||||
(cmake) install IXUniquePtr.h
|
(cmake) install IXUniquePtr.h
|
||||||
|
@ -374,13 +374,10 @@ The webSocket reference is guaranteed to be always valid ; by design the callbac
|
|||||||
// Bound host name, max connections and listen backlog can also be passed in as parameters.
|
// Bound host name, max connections and listen backlog can also be passed in as parameters.
|
||||||
ix::WebSocketServer server(port);
|
ix::WebSocketServer server(port);
|
||||||
|
|
||||||
server.setOnClientMessageCallback(std::shared_ptr<ConnectionState> connectionState,
|
server.setOnClientMessageCallback([](std::shared_ptr<ix::ConnectionState> connectionState, ix::WebSocket & webSocket, const ix::WebSocketMessagePtr & msg) {
|
||||||
WebSocket& webSocket,
|
|
||||||
const WebSocketMessagePtr& msg)
|
|
||||||
{
|
|
||||||
// The ConnectionState object contains information about the connection,
|
// The ConnectionState object contains information about the connection,
|
||||||
// at this point only the client ip address and the port.
|
// at this point only the client ip address and the port.
|
||||||
std::cout << "Remote ip: " << connectionState->getRemoteIp();
|
std::cout << "Remote ip: " << connectionState->getRemoteIp() << std::endl;
|
||||||
|
|
||||||
if (msg->type == ix::WebSocketMessageType::Open)
|
if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
@ -398,7 +395,7 @@ server.setOnClientMessageCallback(std::shared_ptr<ConnectionState> connectionSta
|
|||||||
std::cout << "Headers:" << std::endl;
|
std::cout << "Headers:" << std::endl;
|
||||||
for (auto it : msg->openInfo.headers)
|
for (auto it : msg->openInfo.headers)
|
||||||
{
|
{
|
||||||
std::cout << it.first << ": " << it.second << std::endl;
|
std::cout << "\t" << it.first << ": " << it.second << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
@ -407,9 +404,11 @@ server.setOnClientMessageCallback(std::shared_ptr<ConnectionState> connectionSta
|
|||||||
// All connected clients are available in an std::set. See the broadcast cpp example.
|
// All connected clients are available in an std::set. See the broadcast cpp example.
|
||||||
// Second parameter tells whether we are sending the message in binary or text mode.
|
// Second parameter tells whether we are sending the message in binary or text mode.
|
||||||
// Here we send it in the same mode as it was received.
|
// Here we send it in the same mode as it was received.
|
||||||
|
std::cout << "Received: " << msg->str << std::endl;
|
||||||
|
|
||||||
webSocket.send(msg->str, msg->binary);
|
webSocket.send(msg->str, msg->binary);
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
auto res = server.listen();
|
auto res = server.listen();
|
||||||
if (!res.first)
|
if (!res.first)
|
||||||
|
@ -137,7 +137,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
contentLength = std::stoi(headers["Content-Length"]);
|
contentLength = std::stoi(headers["Content-Length"]);
|
||||||
}
|
}
|
||||||
catch (std::exception)
|
catch(const std::exception&)
|
||||||
{
|
{
|
||||||
return std::make_tuple(
|
return std::make_tuple(
|
||||||
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
|
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
|
||||||
|
@ -20,10 +20,11 @@
|
|||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
|
||||||
const std::string HttpClient::kPost = "POST";
|
const std::string HttpClient::kPost = "POST";
|
||||||
const std::string HttpClient::kGet = "GET";
|
const std::string HttpClient::kGet = "GET";
|
||||||
const std::string HttpClient::kHead = "HEAD";
|
const std::string HttpClient::kHead = "HEAD";
|
||||||
const std::string HttpClient::kDel = "DEL";
|
const std::string HttpClient::kDelete = "DELETE";
|
||||||
const std::string HttpClient::kPut = "PUT";
|
const std::string HttpClient::kPut = "PUT";
|
||||||
const std::string HttpClient::kPatch = "PATCH";
|
const std::string HttpClient::kPatch = "PATCH";
|
||||||
|
|
||||||
@ -557,9 +558,9 @@ namespace ix
|
|||||||
return request(url, kHead, std::string(), args);
|
return request(url, kHead, std::string(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClient::del(const std::string& url, HttpRequestArgsPtr args)
|
HttpResponsePtr HttpClient::Delete(const std::string& url, HttpRequestArgsPtr args)
|
||||||
{
|
{
|
||||||
return request(url, kDel, std::string(), args);
|
return request(url, kDelete, std::string(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClient::request(const std::string& url,
|
HttpResponsePtr HttpClient::request(const std::string& url,
|
||||||
|
@ -30,7 +30,7 @@ namespace ix
|
|||||||
|
|
||||||
HttpResponsePtr get(const std::string& url, HttpRequestArgsPtr args);
|
HttpResponsePtr get(const std::string& url, HttpRequestArgsPtr args);
|
||||||
HttpResponsePtr head(const std::string& url, HttpRequestArgsPtr args);
|
HttpResponsePtr head(const std::string& url, HttpRequestArgsPtr args);
|
||||||
HttpResponsePtr del(const std::string& url, HttpRequestArgsPtr args);
|
HttpResponsePtr Delete(const std::string& url, HttpRequestArgsPtr args);
|
||||||
|
|
||||||
HttpResponsePtr post(const std::string& url,
|
HttpResponsePtr post(const std::string& url,
|
||||||
const HttpParameters& httpParameters,
|
const HttpParameters& httpParameters,
|
||||||
@ -94,7 +94,7 @@ namespace ix
|
|||||||
const static std::string kPost;
|
const static std::string kPost;
|
||||||
const static std::string kGet;
|
const static std::string kGet;
|
||||||
const static std::string kHead;
|
const static std::string kHead;
|
||||||
const static std::string kDel;
|
const static std::string kDelete;
|
||||||
const static std::string kPut;
|
const static std::string kPut;
|
||||||
const static std::string kPatch;
|
const static std::string kPatch;
|
||||||
|
|
||||||
|
@ -192,7 +192,8 @@ namespace ix
|
|||||||
return ::inet_ntop(af, a0, s, l);
|
return ::inet_ntop(af, a0, s, l);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32) && defined(__GNUC__)
|
||||||
static int hexval(unsigned c)
|
static int hexval(unsigned c)
|
||||||
{
|
{
|
||||||
if (c - '0' < 10) return c - '0';
|
if (c - '0' < 10) return c - '0';
|
||||||
@ -200,6 +201,7 @@ namespace ix
|
|||||||
if (c - 'a' < 6) return c - 'a' + 10;
|
if (c - 'a' < 6) return c - 'a' + 10;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// mingw does not have inet_pton, which were taken as is from the musl C library.
|
// mingw does not have inet_pton, which were taken as is from the musl C library.
|
||||||
|
@ -18,6 +18,19 @@
|
|||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <ws2def.h>
|
#include <ws2def.h>
|
||||||
|
|
||||||
|
#undef EWOULDBLOCK
|
||||||
|
#undef EAGAIN
|
||||||
|
#undef EINPROGRESS
|
||||||
|
#undef EBADF
|
||||||
|
#undef EINVAL
|
||||||
|
|
||||||
|
// map to WSA error codes
|
||||||
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
|
#define EAGAIN WSATRY_AGAIN
|
||||||
|
#define EINPROGRESS WSAEINPROGRESS
|
||||||
|
#define EBADF WSAEBADF
|
||||||
|
#define EINVAL WSAEINVAL
|
||||||
|
|
||||||
// Define our own poll on Windows, as a wrapper on top of select
|
// Define our own poll on Windows, as a wrapper on top of select
|
||||||
typedef unsigned long int nfds_t;
|
typedef unsigned long int nfds_t;
|
||||||
|
|
||||||
|
@ -15,20 +15,6 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <BaseTsd.h>
|
#include <BaseTsd.h>
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
|
|
||||||
#undef EWOULDBLOCK
|
|
||||||
#undef EAGAIN
|
|
||||||
#undef EINPROGRESS
|
|
||||||
#undef EBADF
|
|
||||||
#undef EINVAL
|
|
||||||
|
|
||||||
// map to WSA error codes
|
|
||||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
|
||||||
#define EAGAIN WSATRY_AGAIN
|
|
||||||
#define EINPROGRESS WSAEINPROGRESS
|
|
||||||
#define EBADF WSAEBADF
|
|
||||||
#define EINVAL WSAEINVAL
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "IXCancellationRequest.h"
|
#include "IXCancellationRequest.h"
|
||||||
|
@ -191,7 +191,6 @@ namespace ix
|
|||||||
// Make sure the OS send buffer is flushed before moving on
|
// Make sure the OS send buffer is flushed before moving on
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
|
||||||
std::chrono::duration<double, std::milli> duration(500);
|
std::chrono::duration<double, std::milli> duration(500);
|
||||||
std::this_thread::sleep_for(duration);
|
std::this_thread::sleep_for(duration);
|
||||||
} while (client->bufferedAmount() != 0);
|
} while (client->bufferedAmount() != 0);
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.2.4"
|
#define IX_WEBSOCKET_VERSION "11.2.6"
|
||||||
|
10
main.cpp
10
main.cpp
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <ixwebsocket/IXNetSystem.h>
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
#include <ixwebsocket/IXWebSocket.h>
|
#include <ixwebsocket/IXWebSocket.h>
|
||||||
|
#include <ixwebsocket/IXUserAgent.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -25,9 +26,12 @@ int main()
|
|||||||
// Our websocket object
|
// Our websocket object
|
||||||
ix::WebSocket webSocket;
|
ix::WebSocket webSocket;
|
||||||
|
|
||||||
|
// Connect to a server with encryption
|
||||||
|
// See https://machinezone.github.io/IXWebSocket/usage/#tls-support-and-configuration
|
||||||
std::string url("wss://echo.websocket.org");
|
std::string url("wss://echo.websocket.org");
|
||||||
webSocket.setUrl(url);
|
webSocket.setUrl(url);
|
||||||
|
|
||||||
|
std::cout << ix::userAgent() << std::endl;
|
||||||
std::cout << "Connecting to " << url << "..." << std::endl;
|
std::cout << "Connecting to " << url << "..." << std::endl;
|
||||||
|
|
||||||
// Setup a callback to be fired (in a background thread, watch out for race conditions !)
|
// Setup a callback to be fired (in a background thread, watch out for race conditions !)
|
||||||
@ -44,6 +48,12 @@ int main()
|
|||||||
std::cout << "Connection established" << std::endl;
|
std::cout << "Connection established" << std::endl;
|
||||||
std::cout << "> " << std::flush;
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
|
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||||
|
{
|
||||||
|
// Maybe SSL is not configured properly
|
||||||
|
std::cout << "Connection error: " << msg->errorInfo.reason << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user