Compare commits
11 Commits
release/5.
...
v5.0.6
Author | SHA1 | Date | |
---|---|---|---|
87a45a2eba | |||
193da820b2 | |||
c6198305d4 | |||
c77d6ae3f5 | |||
c72b2dbd6b | |||
835523f77b | |||
ec8a35b587 | |||
aca18995d1 | |||
f9178f58aa | |||
2477946e68 | |||
7c4d040384 |
20
.travis.yml
20
.travis.yml
@ -15,15 +15,17 @@ matrix:
|
|||||||
- python test/run.py
|
- python test/run.py
|
||||||
- make ws
|
- make ws
|
||||||
|
|
||||||
# # Linux
|
# Linux
|
||||||
# - os: linux
|
- os: linux
|
||||||
# dist: xenial
|
dist: bionic
|
||||||
# script:
|
before_install:
|
||||||
# - python test/run.py
|
- sudo apt-get install -y libmbedtls-dev
|
||||||
# - make ws
|
script:
|
||||||
# env:
|
- python test/run.py
|
||||||
# - CC=gcc
|
- make ws
|
||||||
# - CXX=g++
|
env:
|
||||||
|
- CC=gcc
|
||||||
|
- CXX=g++
|
||||||
|
|
||||||
# Clang + Linux disabled for now
|
# Clang + Linux disabled for now
|
||||||
# - os: linux
|
# - os: linux
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
# 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.5] - 2019-08-22
|
||||||
|
- Windows: use select instead of WSAPoll, through a poll wrapper
|
||||||
|
|
||||||
|
## [5.0.4] - 2019-08-20
|
||||||
|
- Windows build fixes (there was a problem with the use of ::poll that has a different name on Windows (WSAPoll))
|
||||||
|
|
||||||
## [5.0.3] - 2019-08-14
|
## [5.0.3] - 2019-08-14
|
||||||
- CobraMetricThreadedPublisher _enable flag is an atomic, and CobraMetricsPublisher is enabled by default
|
- CobraMetricThreadedPublisher _enable flag is an atomic, and CobraMetricsPublisher is enabled by default
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
5.0.3
|
5.0.4
|
||||||
|
33
README.md
33
README.md
@ -16,9 +16,32 @@
|
|||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
### Windows note
|
||||||
|
|
||||||
|
To use the network system on Windows, you need to initialize it once with *WSAStartup()* and clean it up with *WSACleanup()*. We have helpers for that which you can use, see below. This init would typically take place in your main function.
|
||||||
|
|
||||||
|
```
|
||||||
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ix::initNetSystem();
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
ix::uninitNetSystem();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### WebSocket client API
|
### WebSocket client API
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#include <ixwebsocket/IXWebSocket.h>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
# Our websocket object
|
||||||
ix::WebSocket webSocket;
|
ix::WebSocket webSocket;
|
||||||
|
|
||||||
std::string url("ws://localhost:8080/");
|
std::string url("ws://localhost:8080/");
|
||||||
@ -59,6 +82,10 @@ webSocket.stop()
|
|||||||
### WebSocket server API
|
### WebSocket server API
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#include <ixwebsocket/IXWebSocketServer.h>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
// Run a server on localhost at a given port.
|
// Run a server on localhost at a given port.
|
||||||
// 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);
|
||||||
@ -120,6 +147,10 @@ server.wait();
|
|||||||
### HTTP client API
|
### HTTP client API
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#include <ixwebsocket/IXHttpClient.h>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
//
|
//
|
||||||
// Preparation
|
// Preparation
|
||||||
//
|
//
|
||||||
@ -199,6 +230,8 @@ bool ok = httpClient.performRequest(args, [](const HttpResponsePtr& response)
|
|||||||
### HTTP server API
|
### HTTP server API
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#include <ixwebsocket/IXHttpServer.h>
|
||||||
|
|
||||||
ix::HttpServer server(port, hostname);
|
ix::HttpServer server(port, hostname);
|
||||||
|
|
||||||
auto res = server.listen();
|
auto res = server.listen();
|
||||||
|
@ -15,9 +15,8 @@ namespace ix
|
|||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
|
// Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h
|
||||||
wVersionRequested = MAKEWORD(2, 2);
|
wVersionRequested = MAKEWORD(2, 2);
|
||||||
|
|
||||||
err = WSAStartup(wVersionRequested, &wsaData);
|
err = WSAStartup(wVersionRequested, &wsaData);
|
||||||
|
|
||||||
return err == 0;
|
return err == 0;
|
||||||
@ -30,10 +29,83 @@ namespace ix
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int err = WSACleanup();
|
int err = WSACleanup();
|
||||||
|
|
||||||
return err == 0;
|
return err == 0;
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function should be in the global namespace
|
||||||
|
#ifdef _WIN32
|
||||||
|
//
|
||||||
|
// That function could 'return WSAPoll(pfd, nfds, timeout);'
|
||||||
|
// but WSAPoll is said to have weird behaviors on the internet
|
||||||
|
// (the curl folks have had problems with it).
|
||||||
|
//
|
||||||
|
// So we make it a select wrapper
|
||||||
|
//
|
||||||
|
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||||
|
{
|
||||||
|
int maxfd = 0;
|
||||||
|
fd_set readfds, writefds, errorfds;
|
||||||
|
FD_ZERO(&readfds);
|
||||||
|
FD_ZERO(&writefds);
|
||||||
|
FD_ZERO(&errorfds);
|
||||||
|
|
||||||
|
for (nfds_t i = 0; i < nfds; ++i)
|
||||||
|
{
|
||||||
|
struct pollfd *fd = &fds[i];
|
||||||
|
|
||||||
|
if (fd->fd > maxfd)
|
||||||
|
{
|
||||||
|
maxfd = fd->fd;
|
||||||
|
}
|
||||||
|
if ((fd->events & POLLIN))
|
||||||
|
{
|
||||||
|
FD_SET(fd->fd, &readfds);
|
||||||
|
}
|
||||||
|
if ((fd->events & POLLOUT))
|
||||||
|
{
|
||||||
|
FD_SET(fd->fd, &writefds);
|
||||||
|
}
|
||||||
|
if ((fd->events & POLLERR))
|
||||||
|
{
|
||||||
|
FD_SET(fd->fd, &errorfds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_sec = timeout / 1000;
|
||||||
|
tv.tv_usec = (timeout % 1000) * 1000;
|
||||||
|
|
||||||
|
int ret = select(maxfd + 1, &readfds, &writefds, &errorfds,
|
||||||
|
timeout != -1 ? &tv : NULL);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (nfds_t i = 0; i < nfds; ++i)
|
||||||
|
{
|
||||||
|
struct pollfd *fd = &fds[i];
|
||||||
|
fd->revents = 0;
|
||||||
|
|
||||||
|
if (FD_ISSET(fd->fd, &readfds))
|
||||||
|
{
|
||||||
|
fd->revents |= POLLIN;
|
||||||
|
}
|
||||||
|
if (FD_ISSET(fd->fd, &writefds))
|
||||||
|
{
|
||||||
|
fd->revents |= POLLOUT;
|
||||||
|
}
|
||||||
|
if (FD_ISSET(fd->fd, &errorfds))
|
||||||
|
{
|
||||||
|
fd->revents |= POLLERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -12,11 +12,18 @@
|
|||||||
#include <basetsd.h>
|
#include <basetsd.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <ws2def.h>
|
#include <ws2def.h>
|
||||||
|
|
||||||
|
// Define our own poll on Windows
|
||||||
|
typedef unsigned long int nfds_t;
|
||||||
|
|
||||||
|
int poll(struct pollfd* fds, nfds_t nfds, int timeout);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <poll.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ namespace ix
|
|||||||
// shim to fallback to select on those platforms.
|
// shim to fallback to select on those platforms.
|
||||||
// See https://github.com/mpv-player/mpv/pull/5203/files for such a select wrapper.
|
// See https://github.com/mpv-player/mpv/pull/5203/files for such a select wrapper.
|
||||||
//
|
//
|
||||||
int nfds = 1;
|
nfds_t nfds = 1;
|
||||||
struct pollfd fds[2];
|
struct pollfd fds[2];
|
||||||
|
|
||||||
fds[0].fd = sockfd;
|
fds[0].fd = sockfd;
|
||||||
|
3
makefile
3
makefile
@ -17,6 +17,9 @@ ws:
|
|||||||
uninstall:
|
uninstall:
|
||||||
xargs rm -fv < build/install_manifest.txt
|
xargs rm -fv < build/install_manifest.txt
|
||||||
|
|
||||||
|
tag:
|
||||||
|
git tag v"`cat DOCKER_VERSION`"
|
||||||
|
|
||||||
.PHONY: docker
|
.PHONY: docker
|
||||||
|
|
||||||
NAME := bsergean/ws
|
NAME := bsergean/ws
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "IXCobraMetricsThreadedPublisher.h"
|
#include "IXCobraMetricsThreadedPublisher.h"
|
||||||
|
#include <atomic>
|
||||||
#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
|
||||||
|
Reference in New Issue
Block a user