Compare commits
1 Commits
v5.0.6
...
release/5.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
571f0c8a01 |
@@ -18,8 +18,6 @@ matrix:
|
|||||||
# Linux
|
# Linux
|
||||||
- os: linux
|
- os: linux
|
||||||
dist: bionic
|
dist: bionic
|
||||||
before_install:
|
|
||||||
- sudo apt-get install -y libmbedtls-dev
|
|
||||||
script:
|
script:
|
||||||
- python test/run.py
|
- python test/run.py
|
||||||
- make ws
|
- make ws
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
# 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.4
|
5.0.3
|
||||||
|
|||||||
33
README.md
33
README.md
@@ -16,32 +16,9 @@
|
|||||||
|
|
||||||
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/");
|
||||||
@@ -82,10 +59,6 @@ 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);
|
||||||
@@ -147,10 +120,6 @@ server.wait();
|
|||||||
### HTTP client API
|
### HTTP client API
|
||||||
|
|
||||||
```
|
```
|
||||||
#include <ixwebsocket/IXHttpClient.h>
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Preparation
|
// Preparation
|
||||||
//
|
//
|
||||||
@@ -230,8 +199,6 @@ 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,8 +15,9 @@ 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;
|
||||||
@@ -29,83 +30,10 @@ 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,18 +12,11 @@
|
|||||||
#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,6 +17,7 @@
|
|||||||
#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>
|
||||||
|
|
||||||
@@ -58,7 +59,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.
|
||||||
//
|
//
|
||||||
nfds_t nfds = 1;
|
int nfds = 1;
|
||||||
struct pollfd fds[2];
|
struct pollfd fds[2];
|
||||||
|
|
||||||
fds[0].fd = sockfd;
|
fds[0].fd = sockfd;
|
||||||
|
|||||||
3
makefile
3
makefile
@@ -17,9 +17,6 @@ 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