Compare commits

..

6 Commits

12 changed files with 37 additions and 19 deletions

View File

@ -1,6 +1,9 @@
# Changelog
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
- 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)

View File

@ -1 +1 @@
5.0.1
5.0.3

View File

@ -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.
Here is what the client API looks like.
### WebSocket client API
```
ix::WebSocket webSocket;
@ -56,7 +56,7 @@ webSocket.sendBinary("some serialized binary data");
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.
@ -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
//
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 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
@ -196,7 +196,7 @@ bool ok = httpClient.performRequest(args, [](const HttpResponsePtr& response)
// 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);
@ -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.
cd build
cmake ..
cmake -DUSE_TLS=1 ..
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
```
@ -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.
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
It is possible to get IXWebSocket through Microsoft [vcpkg](https://github.com/microsoft/vcpkg).

View File

@ -12,10 +12,10 @@
#include "IXCancellationRequest.h"
#include <atomic>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <memory>
struct addrinfo;

View File

@ -6,8 +6,8 @@
#pragma once
#include "IXWebSocketHttpHeaders.h"
#include "IXProgressCallback.h"
#include "IXWebSocketHttpHeaders.h"
#include <tuple>
namespace ix
@ -111,10 +111,12 @@ namespace ix
class Http
{
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 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);
};
}
} // namespace ix

View File

@ -14,6 +14,7 @@
#include <vector>
#include <cstring>
#include <assert.h>
#include <zlib.h>
namespace ix
@ -52,6 +53,8 @@ namespace ix
bool HttpClient::performRequest(HttpRequestArgsPtr args,
const OnResponseCallback& onResponseCallback)
{
assert(_async && "HttpClient needs its async parameter set to true "
"in order to call performRequest");
if (!_async) return false;
// Enqueue the task

View File

@ -6,9 +6,9 @@
#pragma once
#include "IXHttp.h"
#include "IXSocket.h"
#include "IXWebSocketHttpHeaders.h"
#include "IXHttp.h"
#include <algorithm>
#include <atomic>
#include <condition_variable>

View File

@ -6,9 +6,9 @@
#pragma once
#include "IXHttp.h"
#include "IXSocketServer.h"
#include "IXWebSocket.h"
#include "IXHttp.h"
#include <functional>
#include <memory>
#include <mutex>
@ -47,4 +47,3 @@ namespace ix
void setDefaultConnectionCallback();
};
} // namespace ix

View File

@ -128,6 +128,10 @@ namespace ix
optval != 0)
{
pollResult = PollResultType::Error;
// set errno to optval so that external callers can have an
// appropriate error description when calling strerror
errno = optval;
}
#endif
}

View File

@ -6,9 +6,9 @@
#pragma once
#include "IXGetFreePort.h"
#include <iostream>
#include <ixwebsocket/IXWebSocketServer.h>
#include "IXGetFreePort.h"
#include <mutex>
#include <spdlog/spdlog.h>
#include <sstream>

View File

@ -17,7 +17,7 @@ namespace ix
const std::string CobraMetricsPublisher::kSetBlacklistId = "sms_set_blacklist_id";
CobraMetricsPublisher::CobraMetricsPublisher() :
_enabled(false)
_enabled(true)
{
}

View File

@ -10,6 +10,7 @@
#include <chrono>
#include <jsoncpp/json/json.h>
#include <string>
#include <atomic>
#include <unordered_map>
namespace ix
@ -132,8 +133,8 @@ namespace ix
CobraMetricsThreadedPublisher _cobra_metrics_theaded_publisher;
/// A boolean to enable or disable this system
/// push becomes a no-op when _enabled is true
bool _enabled;
/// push becomes a no-op when _enabled is false
std::atomic<bool> _enabled;
/// A uuid used to uniquely identify a session
std::string _session;