Compare commits

..

8 Commits

Author SHA1 Message Date
Benjamin Sergeant
a5179cd17f do not busy loop while sending 2019-03-14 14:37:43 -07:00
Benjamin Sergeant
e158175819 remove docker folder 2019-03-14 13:47:19 -07:00
Benjamin Sergeant
ec2f229489 send optimization + ws file transfer test 2019-03-14 13:47:03 -07:00
Benjamin Sergeant
ead9616d04 cleanup 2019-03-13 23:03:52 -07:00
Benjamin Sergeant
922d58eb59 linux fix / linux still use event fd for now 2019-03-13 17:23:05 -07:00
Benjamin Sergeant
d1a7b9a985 cleanup 2019-03-13 12:05:17 -07:00
Benjamin Sergeant
11092027cd flush send buffer on the background thread 2019-03-12 21:49:26 -07:00
Benjamin Sergeant
4de3ec995e try to use a pipe for communication 2019-03-12 18:32:42 -07:00
6 changed files with 18 additions and 26 deletions

View File

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

View File

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

View File

@@ -29,9 +29,5 @@ 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 uint64_t Socket::kSendRequest = 1;
const uint64_t Socket::kCloseRequest = 2;
const uint8_t Socket::kSendRequest = 1;
const uint8_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))
{
uint64_t value = _eventfd.read();
uint8_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 uint64_t kSendRequest;
static const uint64_t kCloseRequest;
static const uint8_t kSendRequest;
static const uint8_t kCloseRequest;
protected:
void closeSocket(int fd);

View File

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