Commit Graph

262 Commits

Author SHA1 Message Date
Alexandre Konieczny
c7e52e6fcd fix data race on _useMask 2019-04-29 16:41:34 -07:00
Benjamin Sergeant
0a7157655b initialize netSystem (aka winsock on windows) explicitely 2019-04-25 16:38:15 -07:00
Dimon4eg
58d65926bb Fixes for windows (#45)
* init Net system on Windows

* propagate DNS error

* Add zlib 1.2.11 sources

* link zlib statically for windows

* remove not implemented function declaration

* fix connect on Windows
2019-04-25 16:26:53 -07:00
Benjamin Sergeant
b178ba16af fix indentation of greatestCommonDivisor 2019-04-25 16:21:36 -07:00
Benjamin Sergeant
e4c09284b5 Remove commented code 2019-04-25 16:16:52 -07:00
Benjamin Sergeant
9367a1feff Fix data race in WebSocket where _url is accessed without protection in setThreadName
Also fix with url usage + docker container uses fedora and works with tsan
2019-04-25 16:11:46 -07:00
Benjamin Sergeant
4fe07579b9 Fix data races in DNSLookup (tsan) 2019-04-24 21:53:31 -07:00
Benjamin Sergeant
f563d14134 better server termination / another try at preventing thread join failures 2019-04-24 09:45:53 -07:00
Kumamon38
8ff1339b80 add boolean and add missing protocol error close constant (#41) 2019-04-23 04:31:55 -07:00
Benjamin Sergeant
9ab7bc652a (server) attempt to fix broken macOS unittest on travis CI 2019-04-22 09:36:16 -07:00
Benjamin Sergeant
d48bf9249b indentation / comestic changes 2019-04-19 16:57:38 -07:00
Benjamin Sergeant
4564173b75 (socket server) wait for all connections threads to be terminated before exiting stop method 2019-04-19 16:31:33 -07:00
Benjamin Sergeant
b041042473 fix Linux cast warning 2019-04-19 15:03:49 -07:00
Benjamin Sergeant
b0139c2217 add locks around Socket::send and Socket::recv to see if it helps with thread sanitizer error in Linux CI 2019-04-19 14:28:51 -07:00
Benjamin Sergeant
bb442021cf fix bad merge in IXWebSocketTransport.cpp ... 2019-04-19 09:41:16 -07:00
Benjamin Sergeant
91106b7456 Socket::Poll does not need a callback 2019-04-19 09:32:49 -07:00
Kumamon38
309b5ee1b3 Ping timeout use constant (#36)
* use constant for ping timeout

* change close code types
2019-04-19 09:16:25 -07:00
Kumamon38
e3d0c899d3 fix close code/reason issue (#34)
* fix close code/reason issue

* added code 1006 for abnormal closure
2019-04-18 10:02:31 -07:00
Kumamon38
d7595b0dd0 Real ping (#32)
* close method change and fix code

* missing mutex

* wip

* renaming and fixes

* renaming, fixes

* added enablePong/disablePong, add tests

* added new test cases

* add 1 test case

* fix gcd name to greatestCommonDivisor

* move ping and ping timeout checks into socket poll, local var in test cases and indent fixes

* indent issue
2019-04-18 09:24:16 -07:00
Benjamin Sergeant
c367435073 docker + linux build fix 2019-04-17 22:52:03 -07:00
Benjamin Sergeant
dc812c384e setter method does not need to return anything, make it void 2019-04-17 20:36:26 -07:00
Benjamin Sergeant
10b2d10dbd (doc) Add more doc to SocketServer 2019-04-17 20:36:26 -07:00
Benjamin Sergeant
f96babc6a6 websocket server: closed connection threads are joined properly 2019-04-17 20:36:26 -07:00
Benjamin Sergeant
4e2e14fb22
Bug/30 server connection problem (#31)
* use threads instead of std::async, need to cleanup threads

* less buggy server connection per thread system
2019-04-16 22:19:44 -07:00
Benjamin Sergeant
bcf2fc1812 make closeWireSize a default parameter of WebSocketTransport::close 2019-04-16 09:55:12 -07:00
Kumamon38
935e6791a3 close method change and fix code (#28)
* close method change and fix code

* missing mutex
2019-04-16 08:58:34 -07:00
Dimon4eg
fbb7c012a3 fix windows build (#29)
* fix windows build

* fix for Unix

* Fix build if TLS is OFF

* add OpenSSL req to ws

* Fix build on Mac

* fix tests for windows
2019-04-16 08:51:57 -07:00
Benjamin Sergeant
d8e83caffc fix warning 2019-04-13 21:16:04 -07:00
Benjamin Sergeant
1e96edc293 (server) fix masking bug 2019-03-22 15:33:04 -07:00
Benjamin Sergeant
0afb77393b can send TEXT message (we only support BINARY messages now) 2019-03-22 14:24:22 -07:00
Benjamin Sergeant
7614b642bb unmasked code is broken 2019-03-22 14:24:15 -07:00
Benjamin Sergeant
bc89580dfe remove printf + unittest fix 2019-03-22 09:56:28 -07:00
Benjamin Sergeant
358ae13a88 (server) server should not mask data when sending to client (some python client libraries enforce that and assert) 2019-03-22 09:53:56 -07:00
Benjamin Sergeant
ccf9dcba70 (server) HTTP response is malformed 2019-03-22 09:52:19 -07:00
Benjamin Sergeant
94604fad61 minor cleanup 2019-03-21 13:51:25 -07:00
Benjamin Sergeant
5c4cc7c50d HTTP/1.1 response should contains a reason (websocket server)
Fix compatibility problem with websockets python library, where the response does not contains a reason

File "/.../lib/python3.7/site-packages/websockets/http.py", line 126, in read_response
version, status_code, reason = status_line[:-2].split(b' ', 2)
ValueError: not enough values to unpack (expected 3, got 2)

The above exception was the direct cause of the following exception:

websockets.exceptions.InvalidMessage: Malformed HTTP message
2019-03-21 13:43:47 -07:00
Benjamin Sergeant
9ed961ec06 cleanup, remove dead method 2019-03-21 10:06:59 -07:00
Benjamin Sergeant
ee25bd0f92
Feature/connection state (#25)
* (cmake) add a warning about 32/64 conversion problems.

* fix typo

* New connection state for server code + fix OpenSSL double init bug

* update README
2019-03-20 18:34:24 -07:00
Benjamin Sergeant
e77b9176f3
Feature/redis (#23)
* Fix warning

* (cmake) add a warning about 32/64 conversion problems.

* simple redis clients

* can publish to redis

* redis subscribe

* display messages received per second

* verbose flag

* (cmake) use clang only compile option -Wshorten-64-to-32 when compiling with clang
2019-03-20 14:29:02 -07:00
Michael Lu
afe8b966ad Fixed heartbeat typos (#22) 2019-03-19 21:31:43 -07:00
Benjamin Sergeant
310724c961 make PollResultType an enum class 2019-03-19 09:29:57 -07:00
Benjamin Sergeant
ceba8ae620 fix bug with isReadyToWrite 2019-03-18 22:05:04 -07:00
Benjamin Sergeant
fead661ab7 workaround bug in Socket::isReadyToWrite 2019-03-18 20:37:33 -07:00
Benjamin Sergeant
9c8c17f577 use milliseconds 2019-03-18 20:17:44 -07:00
Benjamin Sergeant
c421d19800 disable sigpipe on osx when writing/reading into a dead pipe 2019-03-18 17:52:01 -07:00
Benjamin Sergeant
d5d1a2c5f4 no default parameters for isReadyToWrite and isReadyToRead 2019-03-18 14:31:21 -07:00
Benjamin Sergeant
2a90e3f478 when trying to flush the send buffer, use select to wait until it is possible instead of using sleep to retry at a given frequency 2019-03-18 14:25:27 -07:00
Benjamin Sergeant
d77f6f5659 linux hangs when closing 2019-03-16 11:38:23 -07:00
Benjamin Sergeant
c4afb84f6e use pipe to abort select on Linux as well as macOS 2019-03-15 17:46:40 -07:00
Benjamin Sergeant
b0b2f9b6d2 missing assert include on Linux 2019-03-15 11:43:27 -07:00
Benjamin Sergeant
ee37feb489 cleanup 2019-03-15 11:41:57 -07:00
Benjamin Sergeant
250665b92e linux compile fix 2019-03-14 18:55:33 -07:00
Benjamin Sergeant
86b83c889e linux fixes 2019-03-14 18:54:47 -07:00
Benjamin Sergeant
c9c657c07b build fix 2019-03-14 18:53:21 -07:00
Benjamin Sergeant
4f2babaf54 select interrupt cleanup 2019-03-14 18:37:38 -07:00
Benjamin Sergeant
1b03bf4555 linux build fix 2019-03-14 15:17:17 -07:00
Benjamin Sergeant
977b995af9 replace uint8_t with uint64_t for the send/close requests types / use named variable to index into the _fildes array 2019-03-14 15:03:57 -07:00
Benjamin Sergeant
310ab990bd set a default close reason string 2019-03-14 14:52:51 -07:00
Benjamin Sergeant
d6b49b54d4 do not busy loop while sending 2019-03-14 14:48:08 -07:00
Benjamin Sergeant
18550cf1cb send optimization + ws file transfer test 2019-03-14 14:47:53 -07:00
Benjamin Sergeant
2750df8aa7
send can fail silently when sending would block (EWOULDBLOCK return for send) (#18)
* try to use a pipe for communication

* flush send buffer on the background thread

* cleanup

* linux fix / linux still use event fd for now

* cleanup
2019-03-13 23:09:45 -07:00
Benjamin Sergeant
d6597d9f52 websocket send: make sure all data in the kernel buffer is sent 2019-03-11 22:16:55 -07:00
Benjamin Sergeant
892ea375e3 add new message type when receiving message fragments 2019-03-11 11:12:43 -07:00
Benjamin Sergeant
9c3b0b08ec Socket code refactoring, plus stop polling with a 1s timeout in readBytes while we only want to poll with a 1ms timeout 2019-03-04 13:40:15 -08:00
Benjamin Sergeant
fe7d94194c readBytes does not read bytes one by one but in chunks 2019-03-02 21:11:16 -08:00
Benjamin Sergeant
d6c26d6aa8 create a blocking + cancellable Socket::readBytes method 2019-03-02 15:16:46 -08:00
Benjamin Sergeant
8a74ddcd13 create a blocking + cancellable Socket::readBytes method 2019-03-02 11:01:51 -08:00
Benjamin Sergeant
0cff5065d9
Feature/http (#16)
* add skeleton and broken http client code.

GET returns "Resource temporarily unavailable" errors...

* linux compile fix

* can GET some pages

* Update formatting in README.md

* unittest for sending large messages

* document bug

* Feature/send large message (#14)

* introduce send fragment

* can pass a fin frame

* can send messages which are a perfect multiple of the chunk size

* set fin only for last fragment

* cleanup

* last fragment should be of type CONTINUATION

* Add simple send and receive programs

* speedups receiving + better way to wait for thing

* receive speedup by using linked list of chunks instead of large array

* document bug

* use chunks to receive data

* trailing spaces

* Update README.md

Add note about message fragmentation.

* Feature/ws cli (#15)

* New command line tool for transfering files / still very beta.

* add readme

* use cli11 for argument parsing

* json -> msgpack

* stop using base64 and use binary which can be stored in message pack

* add target for building with homebrew

* all CMakeLists are referenced by the top level one

* add ws_chat and ws_connect sub commands to ws

* cleanup

* add echo and broadcast server as ws sub-commands

* add gitignore

* comments

* ping pong added to ws

* mv cobra_publisher under ws folder

* Update README.md

* linux build fix

* linux build fix

* move http_client to a ws sub-command

* simple HTTP post support (urlencode parameters)

* can specify extra headers

* chunk encoding / simple redirect support / -I option

* follow redirects is optional

* make README vim markdown plugin friendly

* cleanup argument parsing + add socket creation factory

* add missing file

* http gzip compression

* cleanup

* doc

* Feature/send large message (#14)

* introduce send fragment

* can pass a fin frame

* can send messages which are a perfect multiple of the chunk size

* set fin only for last fragment

* cleanup

* last fragment should be of type CONTINUATION

* Add simple send and receive programs

* speedups receiving + better way to wait for thing

* receive speedup by using linked list of chunks instead of large array

* document bug

* use chunks to receive data

* trailing spaces
2019-02-28 21:54:03 -08:00
Benjamin Sergeant
3a77e96a05
Feature/send large message (#14)
* introduce send fragment

* can pass a fin frame

* can send messages which are a perfect multiple of the chunk size

* set fin only for last fragment

* cleanup

* last fragment should be of type CONTINUATION

* Add simple send and receive programs

* speedups receiving + better way to wait for thing

* receive speedup by using linked list of chunks instead of large array

* document bug

* use chunks to receive data

* trailing spaces
2019-02-20 18:59:07 -08:00
Benjamin Sergeant
3f8027b65c unittest for sending large messages 2019-02-16 10:32:02 -08:00
Benjamin Sergeant
ae841af91a use dynamically generated port number to configure servers in unittest 2019-01-28 15:24:19 -08:00
Benjamin Sergeant
ee12fbdb5f windows build fix 2019-01-27 10:46:02 -08:00
Benjamin Sergeant
316c630830 constexpr to declare number of fds 2019-01-26 21:01:36 -08:00
Benjamin Sergeant
1ea5db6110 linux fix 2019-01-26 20:57:48 -08:00
Benjamin Sergeant
986d9a00c0 remove shutdown call 2019-01-26 20:54:23 -08:00
Benjamin Sergeant
7a05a11014 rebase poll branch 2019-01-26 20:50:25 -08:00
Benjamin Sergeant
f09434263c insensitive string compare when validating server connection header 2019-01-25 16:17:51 -08:00
Benjamin Sergeant
fa7ef06f4d heartbeat correct 2019-01-25 16:11:39 -08:00
Benjamin Sergeant
3c9ec0aed0 close server socket on exit 2019-01-24 21:16:32 -08:00
Benjamin Sergeant
05033714bf hearbeat 2019-01-24 12:42:49 -08:00
Benjamin Sergeant
fdbd213fa2 check and validate the Connection: Upgrade header in client/server 2019-01-15 09:31:37 -08:00
Tony Lin
17b01a8c66 Fix missing upgrade header error 2019-01-15 15:35:37 +08:00
Benjamin Sergeant
79dd766fab C++14 + use make_unique and make_shared to make shared pointers 2019-01-11 21:25:06 -08:00
Benjamin Sergeant
1fa75d7fb2 check select errors better 2019-01-07 11:18:00 -08:00
Benjamin Sergeant
e30ef4a87c DNSLookup _id member does not need to be an atomic 2019-01-06 18:32:19 -08:00
Benjamin Sergeant
9fc94f0487 DNSLookup: fix #8 2019-01-06 18:27:26 -08:00
Benjamin Sergeant
121acdab6f DNSLookup: copy hostname and port instead of accessing member 2019-01-06 18:17:12 -08:00
Benjamin Sergeant
6deaa03114 return false -> return -1 2019-01-06 18:10:39 -08:00
Benjamin Sergeant
a21aae521f remove dead file 2019-01-06 14:26:11 -08:00
Benjamin Sergeant
a478f734f6 gcc linux compile fix 2019-01-06 12:12:39 -08:00
Benjamin Sergeant
98c579da03 make a class hierarchy for server code (IXWebSocketServer <- IXSocketServer) 2019-01-06 12:09:31 -08:00
Benjamin Sergeant
cc8a9e883e unittest + compiler warnings 2019-01-05 21:10:08 -08:00
Benjamin Sergeant
4d587e35d8 windows compile fix 2019-01-05 21:02:55 -08:00
Benjamin Sergeant
50f4fd1115 int -> ssize_t for socker recv and send 2019-01-05 20:53:50 -08:00
Benjamin Sergeant
06d2b68696 header refactoring 2019-01-05 20:38:43 -08:00
Benjamin Sergeant
bf6f057777 windows connect (compile fix) 2019-01-05 17:35:50 -08:00
Benjamin Sergeant
b57c1d69f2 windows connect potential fix 2019-01-05 17:32:21 -08:00
Benjamin Sergeant
ff265d83f9 more accurate description of errors 2019-01-05 17:18:43 -08:00
Benjamin Sergeant
c8c81366f7 windows (compile) fix 2019-01-05 17:04:09 -08:00
Benjamin Sergeant
9a37fd56d1 windows fix 2019-01-05 17:02:39 -08:00
Benjamin Sergeant
e4b0286a25 fix gcc warning 2019-01-05 16:26:11 -08:00
Benjamin Sergeant
78d88a8520 openssl cleanup 2019-01-05 11:42:25 -08:00
Benjamin Sergeant
46d00360a8 unittest on appveyor 2019-01-04 17:28:13 -08:00
Benjamin Sergeant
af3df5e519 Socket::readLine works with arbitrary long lines 2019-01-03 18:47:01 -08:00
Benjamin Sergeant
d75753ec98 timeout is configurable 2019-01-03 18:33:08 -08:00
Benjamin Sergeant
332bb87231 remove useless FIXME comment 2019-01-03 18:02:03 -08:00
Benjamin Sergeant
9bc2e95196 capture path/uri when connecting, and pass it back through callbacks in the openInfo member 2019-01-03 17:44:10 -08:00
Benjamin Sergeant
30a0aa0a0f implement a max connections (default = 32) settings 2019-01-03 17:05:44 -08:00
Benjamin Sergeant
8622ea5cb2 correct validation of the request (request line + headers) 2019-01-03 13:41:06 -08:00
Benjamin Sergeant
ed3a50d9b5 cancellation refactoring 2019-01-03 12:53:44 -08:00
Benjamin Sergeant
474985e784 split handshake code into its own files, so that Transport file is less massive 2019-01-02 20:07:54 -08:00
Benjamin Sergeant
cb904416c3 server unittest for validating client request / new timeout cancellation handling (need refactoring) 2019-01-02 16:08:32 -08:00
Benjamin Sergeant
b004769552 server per message deflate support 2019-01-02 08:12:29 -08:00
Benjamin Sergeant
239b5bc02c refactoring + cancellation was buggy during http upgrade 2019-01-02 07:45:07 -08:00
Benjamin Sergeant
6bfabd5493 use select to detect new incoming connections 2019-01-01 22:21:07 -08:00
Benjamin Sergeant
0b90f7df1b add a way to run in blocking more, which is useful for server mode to have N*thread instead of 2N*thread for N connections 2019-01-01 21:25:15 -08:00
Benjamin Sergeant
00ca7c8fb0 more named constants 2019-01-01 19:23:27 -08:00
Benjamin Sergeant
06b9b2e649 linux fix + unittest works with Linux 2019-01-01 17:13:26 -08:00
Benjamin Sergeant
b13fee16c1 crash when server failed to start 2019-01-01 16:14:46 -08:00
Benjamin Sergeant
9a7767ecb1 thread accepting connections can be cancelled/stopped externally 2019-01-01 16:11:27 -08:00
Benjamin Sergeant
9b82a33aff listen job run in its own thread, non blocking 2019-01-01 14:52:14 -08:00
Benjamin Sergeant
77903e9d90 cleanup / remove printf, add mutex, remove hardcoded values, can pass in a binding host 2019-01-01 14:28:41 -08:00
Benjamin Sergeant
de66a87a7c use shared_ptr 2019-01-01 13:53:13 -08:00
Benjamin Sergeant
5ea2028c22 unittest pass 2019-01-01 13:47:25 -08:00
Benjamin Sergeant
58a68ec0be record workers in a map instead of a vector 2018-12-31 14:52:59 -08:00
Benjamin Sergeant
f8373dc666 more cleanup to propagate server connection error and let onOpen callback execute 2018-12-31 12:43:47 -08:00
Benjamin Sergeant
3febc2431d only bind to localhost 2018-12-31 11:48:49 -08:00
Benjamin Sergeant
0bf736831a server code has a callback that takes a websocket 2018-12-30 22:12:13 -08:00
Benjamin Sergeant
7710bf793f cleanup / use a websocket instead of raw websockettransport 2018-12-30 22:00:49 -08:00
Benjamin Sergeant
a6a43bd361 can accept multiple connection / server can send data back to client 2018-12-30 21:16:05 -08:00
Benjamin Sergeant
a39209a895 proof of concept server implementation 2018-12-29 23:15:27 -08:00
Benjamin Sergeant
24c9e0abc3 can create a socket from a fd 2018-12-29 21:53:33 -08:00
Benjamin Sergeant
9cc324d78d add simple unittest 2018-12-29 18:34:08 -08:00
Benjamin Sergeant
8574beceb1 add missing src files (IXSetThreadName.{cpp,h}) ... 2018-12-23 14:19:30 -08:00
Benjamin Sergeant
0349b7f1c7 fix warning: field '_eventCallback' will be initialized after field '_publishMode' 2018-12-23 14:18:53 -08:00
Benjamin Sergeant
ce1ba20db5 Fix warning: field '_done' will be initialized after field '_wait' [-Wreorder] _done(false), 2018-12-23 14:17:30 -08:00
Benjamin Sergeant
395d823f41 set thread name / rename example 2018-12-23 14:14:38 -08:00
Benjamin Sergeant
6884f9f74f async dns lookup fix 2018-12-14 17:49:42 -08:00
Benjamin Sergeant
b34eccd749 non blocking dns lookup 2018-12-14 16:28:17 -08:00
Benjamin Sergeant
50b638f7fd add cancellation support while connecting, to speed up WebSocket::stop 2018-12-09 17:56:20 -08:00
Benjamin Sergeant
5bf1b91528 http upgrade and connections use non blocking sockets 2018-12-09 14:07:40 -08:00
Benjamin Sergeant
f77ececc92 threading race condition fixes, detected by TSAN 2018-12-06 08:27:28 -08:00
Benjamin Sergeant
58cccbdcf9 cleanup 2018-11-14 15:52:28 -08:00
Benjamin Sergeant
5710ffba6a per-message deflate compression fixes 2018-11-13 17:46:05 -08:00
Benjamin Sergeant
a7a422d6ed tweaks doc / license + send proper error code when closing the connecion 2018-11-12 09:00:55 -08:00
Benjamin Sergeant
43fcf93584 per message deflate support (with zlib) 2018-11-09 18:42:09 -08:00
Benjamin Sergeant
32f4c8305e (satori_publisher) better error handling 2018-11-07 14:54:44 -08:00
Benjamin Sergeant
ffd4f1d322 Add missing files ... 2018-11-07 12:25:38 -08:00
Benjamin Sergeant
10dd13deb3 Add DockerFile + parse rsv1 field 2018-11-07 11:45:17 -08:00
Benjamin Sergeant
c1ed83a005 stopping connection on Linux does not close the socket, which can create problem when re-starting the connection 2018-11-01 17:02:49 -07:00