Compare commits

..

8 Commits

Author SHA1 Message Date
1b03bf4555 linux build fix 2019-03-14 15:17:17 -07:00
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
310ab990bd set a default close reason string 2019-03-14 14:52:51 -07:00
d6b49b54d4 do not busy loop while sending 2019-03-14 14:48:08 -07:00
f00cf39462 remove docker folder 2019-03-14 14:48:02 -07:00
18550cf1cb send optimization + ws file transfer test 2019-03-14 14:47:53 -07:00
168918f807 Update README.md
Stop lying about Windows support ...
2019-03-13 23:10:40 -07:00
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
6 changed files with 26 additions and 18 deletions

View File

@ -11,7 +11,6 @@ communication channels over a single TCP connection. *IXWebSocket* is a C++ libr
* iOS
* Linux
* Android
* Windows (no TLS support yet)
## Examples

View File

@ -31,6 +31,11 @@
namespace ix
{
// File descriptor at index 0 in _fildes is the read end of the pipe
// File descriptor at index 1 in _fildes is the write end of the pipe
const int EventFd::kPipeReadIndex = 0;
const int EventFd::kPipeWriteIndex = 1;
EventFd::EventFd()
{
#ifdef __linux__
@ -38,12 +43,12 @@ namespace ix
_eventfd = eventfd(0, 0);
fcntl(_eventfd, F_SETFL, O_NONBLOCK);
#else
_fildes[0] = -1;
_fildes[1] = -1;
_fildes[kPipeReadIndex] = -1;
_fildes[kPipeWriteIndex] = -1;
pipe(_fildes);
fcntl(_fildes[0], F_SETFL, O_NONBLOCK);
fcntl(_fildes[1], F_SETFL, O_NONBLOCK);
fcntl(_fildes[kPipeReadIndex], F_SETFL, O_NONBLOCK);
fcntl(_fildes[kPipeWriteIndex], F_SETFL, O_NONBLOCK);
#endif
}
@ -52,10 +57,10 @@ namespace ix
#ifdef __linux__
::close(_eventfd);
#else
::close(_fildes[0]);
::close(_fildes[1]);
_fildes[0] = -1;
_fildes[1] = -1;
::close(_fildes[kPipeReadIndex]);
::close(_fildes[kPipeWriteIndex]);
_fildes[kPipeReadIndex] = -1;
_fildes[kPipeWriteIndex] = -1;
#endif
}
@ -66,8 +71,7 @@ namespace ix
#if defined(__linux__)
fd = _eventfd;
#else
// File descriptor at index 1 in _fildes is the write end of the pipe
fd = _fildes[1];
fd = _fildes[kPipeWriteIndex];
#endif
if (fd == -1) return false;
@ -84,7 +88,7 @@ namespace ix
#if defined(__linux__)
fd = _eventfd;
#else
fd = _fildes[0];
fd = _fildes[kPipeReadIndex];
#endif
uint64_t value = 0;
::read(fd, &value, sizeof(value));
@ -111,7 +115,7 @@ namespace ix
#if defined(__linux__)
return _eventfd;
#else
return _fildes[0];
return _fildes[kPipeReadIndex];
#endif
}
}

View File

@ -29,5 +29,9 @@ namespace ix
// blocked on select.
int _fildes[2];
#endif
// Used to identify the read/write idx
static const int kPipeReadIndex;
static const int kPipeWriteIndex;
};
}

View File

@ -23,8 +23,8 @@ namespace ix
{
const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default
const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout;
const uint8_t Socket::kSendRequest = 1;
const uint8_t Socket::kCloseRequest = 2;
const uint64_t Socket::kSendRequest = 1;
const uint64_t Socket::kCloseRequest = 2;
constexpr size_t Socket::kChunkSize;
Socket::Socket(int fd) :
@ -86,7 +86,7 @@ namespace ix
}
else if (eventfd != -1 && FD_ISSET(eventfd, &rfds))
{
uint8_t value = _eventfd.read();
uint64_t value = _eventfd.read();
if (value == kSendRequest)
{

View File

@ -76,8 +76,8 @@ namespace ix
static void cleanup(); // Required on Windows to cleanup WinSocket
// Used as special codes for pipe communication
static const uint8_t kSendRequest;
static const uint8_t kCloseRequest;
static const uint64_t kSendRequest;
static const uint64_t kCloseRequest;
protected:
void closeSocket(int fd);

View File

@ -766,6 +766,7 @@ namespace ix
_socket->close();
_closeCode = 1000;
_closeReason = "Normal Closure";
setReadyState(CLOSED);
}