Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
197cf8ed36 | |||
dd0d7c268f | |||
b2bfccac0a | |||
8b8b352e61 | |||
0403dd354b | |||
b78b453504 |
@ -1,6 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [5.0.3] - 2019-08-14
|
||||||
|
- CobraMetricThreadedPublisher _enable flag is an atomic, and CobraMetricsPublisher is enabled by default
|
||||||
|
|
||||||
## [5.0.2] - 2019-08-01
|
## [5.0.2] - 2019-08-01
|
||||||
- ws cobra_subscribe has a new -q (quiet) option
|
- ws cobra_subscribe has a new -q (quiet) option
|
||||||
- ws cobra_subscribe knows to and display msg stats (count and # of messages received per second)
|
- ws cobra_subscribe knows to and display msg stats (count and # of messages received per second)
|
||||||
|
@ -1 +1 @@
|
|||||||
5.0.1
|
5.0.3
|
||||||
|
18
README.md
18
README.md
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
The [*ws*](https://github.com/machinezone/IXWebSocket/tree/master/ws) folder countains many interactive programs for chat, [file transfers](https://github.com/machinezone/IXWebSocket/blob/master/ws/ws_send.cpp), [curl like](https://github.com/machinezone/IXWebSocket/blob/master/ws/ws_http_client.cpp) http clients, demonstrating client and server usage.
|
The [*ws*](https://github.com/machinezone/IXWebSocket/tree/master/ws) folder countains many interactive programs for chat, [file transfers](https://github.com/machinezone/IXWebSocket/blob/master/ws/ws_send.cpp), [curl like](https://github.com/machinezone/IXWebSocket/blob/master/ws/ws_http_client.cpp) http clients, demonstrating client and server usage.
|
||||||
|
|
||||||
Here is what the client API looks like.
|
### WebSocket client API
|
||||||
|
|
||||||
```
|
```
|
||||||
ix::WebSocket webSocket;
|
ix::WebSocket webSocket;
|
||||||
@ -56,7 +56,7 @@ webSocket.sendBinary("some serialized binary data");
|
|||||||
webSocket.stop()
|
webSocket.stop()
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is what the server API looks like. Note that server support is very recent and subject to changes.
|
### WebSocket server API
|
||||||
|
|
||||||
```
|
```
|
||||||
// Run a server on localhost at a given port.
|
// Run a server on localhost at a given port.
|
||||||
@ -117,7 +117,7 @@ server.wait();
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is what the HTTP client API looks like.
|
### HTTP client API
|
||||||
|
|
||||||
```
|
```
|
||||||
//
|
//
|
||||||
@ -170,7 +170,7 @@ out = httpClient.post(url, std::string("foo=bar"), args);
|
|||||||
//
|
//
|
||||||
// Result
|
// Result
|
||||||
//
|
//
|
||||||
auto errorCode = response->errorCode; // Can be HttpErrorCode::Ok, HttpErrorCode::UrlMalformed, etc...
|
auto statusCode = response->statusCode; // Can be HttpErrorCode::Ok, HttpErrorCode::UrlMalformed, etc...
|
||||||
auto errorCode = response->errorCode; // 200, 404, etc...
|
auto errorCode = response->errorCode; // 200, 404, etc...
|
||||||
auto responseHeaders = response->headers; // All the headers in a special case-insensitive unordered_map of (string, string)
|
auto responseHeaders = response->headers; // All the headers in a special case-insensitive unordered_map of (string, string)
|
||||||
auto payload = response->payload; // All the bytes from the response as an std::string
|
auto payload = response->payload; // All the bytes from the response as an std::string
|
||||||
@ -196,7 +196,7 @@ bool ok = httpClient.performRequest(args, [](const HttpResponsePtr& response)
|
|||||||
// ok will be false if your httpClient is not async
|
// ok will be false if your httpClient is not async
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is what the HTTP server API looks like. Note that HTTP server support is very, very recent and subject to changes.
|
### HTTP server API
|
||||||
|
|
||||||
```
|
```
|
||||||
ix::HttpServer server(port, hostname);
|
ix::HttpServer server(port, hostname);
|
||||||
@ -243,7 +243,7 @@ CMakefiles for the library and the examples are available. This library has few
|
|||||||
```
|
```
|
||||||
mkdir build # make a build dir so that you can build out of tree.
|
mkdir build # make a build dir so that you can build out of tree.
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake -DUSE_TLS=1 ..
|
||||||
make -j
|
make -j
|
||||||
make install # will install to /usr/local on Unix, on macOS it is a good idea to sudo chown -R `whoami`:staff /usr/local
|
make install # will install to /usr/local on Unix, on macOS it is a good idea to sudo chown -R `whoami`:staff /usr/local
|
||||||
```
|
```
|
||||||
@ -251,6 +251,12 @@ make install # will install to /usr/local on Unix, on macOS it is a good idea to
|
|||||||
Headers and a static library will be installed to the target dir.
|
Headers and a static library will be installed to the target dir.
|
||||||
There is a unittest which can be executed by typing `make test`.
|
There is a unittest which can be executed by typing `make test`.
|
||||||
|
|
||||||
|
Options for building:
|
||||||
|
|
||||||
|
* `-DUSE_TLS=1` will enable TLS support
|
||||||
|
* `-DUSE_MBED_TLS=1` will use [mbedlts](https://tls.mbed.org/) for the TLS support (default on Windows)
|
||||||
|
* `-DUSE_WS=1` will build the ws interactive command line tool
|
||||||
|
|
||||||
### vcpkg
|
### vcpkg
|
||||||
|
|
||||||
It is possible to get IXWebSocket through Microsoft [vcpkg](https://github.com/microsoft/vcpkg).
|
It is possible to get IXWebSocket through Microsoft [vcpkg](https://github.com/microsoft/vcpkg).
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
#include "IXCancellationRequest.h"
|
#include "IXCancellationRequest.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
struct addrinfo;
|
struct addrinfo;
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "IXWebSocketHttpHeaders.h"
|
|
||||||
#include "IXProgressCallback.h"
|
#include "IXProgressCallback.h"
|
||||||
|
#include "IXWebSocketHttpHeaders.h"
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
@ -111,10 +111,12 @@ namespace ix
|
|||||||
class Http
|
class Http
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::tuple<bool, std::string, HttpRequestPtr> parseRequest(std::shared_ptr<Socket> socket);
|
static std::tuple<bool, std::string, HttpRequestPtr> parseRequest(
|
||||||
|
std::shared_ptr<Socket> socket);
|
||||||
static bool sendResponse(HttpResponsePtr response, std::shared_ptr<Socket> socket);
|
static bool sendResponse(HttpResponsePtr response, std::shared_ptr<Socket> socket);
|
||||||
|
|
||||||
static std::tuple<std::string, std::string, std::string> parseRequestLine(const std::string& line);
|
static std::tuple<std::string, std::string, std::string> parseRequestLine(
|
||||||
|
const std::string& line);
|
||||||
static std::string trim(const std::string& str);
|
static std::string trim(const std::string& str);
|
||||||
};
|
};
|
||||||
}
|
} // namespace ix
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
@ -52,6 +53,8 @@ namespace ix
|
|||||||
bool HttpClient::performRequest(HttpRequestArgsPtr args,
|
bool HttpClient::performRequest(HttpRequestArgsPtr args,
|
||||||
const OnResponseCallback& onResponseCallback)
|
const OnResponseCallback& onResponseCallback)
|
||||||
{
|
{
|
||||||
|
assert(_async && "HttpClient needs its async parameter set to true "
|
||||||
|
"in order to call performRequest");
|
||||||
if (!_async) return false;
|
if (!_async) return false;
|
||||||
|
|
||||||
// Enqueue the task
|
// Enqueue the task
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "IXHttp.h"
|
||||||
#include "IXSocket.h"
|
#include "IXSocket.h"
|
||||||
#include "IXWebSocketHttpHeaders.h"
|
#include "IXWebSocketHttpHeaders.h"
|
||||||
#include "IXHttp.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "IXHttp.h"
|
||||||
#include "IXSocketServer.h"
|
#include "IXSocketServer.h"
|
||||||
#include "IXWebSocket.h"
|
#include "IXWebSocket.h"
|
||||||
#include "IXHttp.h"
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -47,4 +47,3 @@ namespace ix
|
|||||||
void setDefaultConnectionCallback();
|
void setDefaultConnectionCallback();
|
||||||
};
|
};
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
@ -128,6 +128,10 @@ namespace ix
|
|||||||
optval != 0)
|
optval != 0)
|
||||||
{
|
{
|
||||||
pollResult = PollResultType::Error;
|
pollResult = PollResultType::Error;
|
||||||
|
|
||||||
|
// set errno to optval so that external callers can have an
|
||||||
|
// appropriate error description when calling strerror
|
||||||
|
errno = optval;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "IXGetFreePort.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ixwebsocket/IXWebSocketServer.h>
|
#include <ixwebsocket/IXWebSocketServer.h>
|
||||||
#include "IXGetFreePort.h"
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -17,7 +17,7 @@ namespace ix
|
|||||||
const std::string CobraMetricsPublisher::kSetBlacklistId = "sms_set_blacklist_id";
|
const std::string CobraMetricsPublisher::kSetBlacklistId = "sms_set_blacklist_id";
|
||||||
|
|
||||||
CobraMetricsPublisher::CobraMetricsPublisher() :
|
CobraMetricsPublisher::CobraMetricsPublisher() :
|
||||||
_enabled(false)
|
_enabled(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <jsoncpp/json/json.h>
|
#include <jsoncpp/json/json.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <atomic>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
@ -132,8 +133,8 @@ namespace ix
|
|||||||
CobraMetricsThreadedPublisher _cobra_metrics_theaded_publisher;
|
CobraMetricsThreadedPublisher _cobra_metrics_theaded_publisher;
|
||||||
|
|
||||||
/// A boolean to enable or disable this system
|
/// A boolean to enable or disable this system
|
||||||
/// push becomes a no-op when _enabled is true
|
/// push becomes a no-op when _enabled is false
|
||||||
bool _enabled;
|
std::atomic<bool> _enabled;
|
||||||
|
|
||||||
/// A uuid used to uniquely identify a session
|
/// A uuid used to uniquely identify a session
|
||||||
std::string _session;
|
std::string _session;
|
||||||
|
Reference in New Issue
Block a user