Compare commits
8 Commits
v1.2.0
...
feature/pi
Author | SHA1 | Date | |
---|---|---|---|
|
a5179cd17f | ||
|
e158175819 | ||
|
ec2f229489 | ||
|
ead9616d04 | ||
|
922d58eb59 | ||
|
d1a7b9a985 | ||
|
11092027cd | ||
|
4de3ec995e |
@@ -11,6 +11,7 @@ communication channels over a single TCP connection. *IXWebSocket* is a C++ libr
|
|||||||
* iOS
|
* iOS
|
||||||
* Linux
|
* Linux
|
||||||
* Android
|
* Android
|
||||||
|
* Windows (no TLS support yet)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@@ -31,11 +31,6 @@
|
|||||||
|
|
||||||
namespace ix
|
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()
|
EventFd::EventFd()
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@@ -43,12 +38,12 @@ namespace ix
|
|||||||
_eventfd = eventfd(0, 0);
|
_eventfd = eventfd(0, 0);
|
||||||
fcntl(_eventfd, F_SETFL, O_NONBLOCK);
|
fcntl(_eventfd, F_SETFL, O_NONBLOCK);
|
||||||
#else
|
#else
|
||||||
_fildes[kPipeReadIndex] = -1;
|
_fildes[0] = -1;
|
||||||
_fildes[kPipeWriteIndex] = -1;
|
_fildes[1] = -1;
|
||||||
|
|
||||||
pipe(_fildes);
|
pipe(_fildes);
|
||||||
fcntl(_fildes[kPipeReadIndex], F_SETFL, O_NONBLOCK);
|
fcntl(_fildes[0], F_SETFL, O_NONBLOCK);
|
||||||
fcntl(_fildes[kPipeWriteIndex], F_SETFL, O_NONBLOCK);
|
fcntl(_fildes[1], F_SETFL, O_NONBLOCK);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,10 +52,10 @@ namespace ix
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
::close(_eventfd);
|
::close(_eventfd);
|
||||||
#else
|
#else
|
||||||
::close(_fildes[kPipeReadIndex]);
|
::close(_fildes[0]);
|
||||||
::close(_fildes[kPipeWriteIndex]);
|
::close(_fildes[1]);
|
||||||
_fildes[kPipeReadIndex] = -1;
|
_fildes[0] = -1;
|
||||||
_fildes[kPipeWriteIndex] = -1;
|
_fildes[1] = -1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +66,8 @@ namespace ix
|
|||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
fd = _eventfd;
|
fd = _eventfd;
|
||||||
#else
|
#else
|
||||||
fd = _fildes[kPipeWriteIndex];
|
// File descriptor at index 1 in _fildes is the write end of the pipe
|
||||||
|
fd = _fildes[1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fd == -1) return false;
|
if (fd == -1) return false;
|
||||||
@@ -88,7 +84,7 @@ namespace ix
|
|||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
fd = _eventfd;
|
fd = _eventfd;
|
||||||
#else
|
#else
|
||||||
fd = _fildes[kPipeReadIndex];
|
fd = _fildes[0];
|
||||||
#endif
|
#endif
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
::read(fd, &value, sizeof(value));
|
::read(fd, &value, sizeof(value));
|
||||||
@@ -115,7 +111,7 @@ namespace ix
|
|||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
return _eventfd;
|
return _eventfd;
|
||||||
#else
|
#else
|
||||||
return _fildes[kPipeReadIndex];
|
return _fildes[0];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,9 +29,5 @@ namespace ix
|
|||||||
// blocked on select.
|
// blocked on select.
|
||||||
int _fildes[2];
|
int _fildes[2];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Used to identify the read/write idx
|
|
||||||
static const int kPipeReadIndex;
|
|
||||||
static const int kPipeWriteIndex;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -23,8 +23,8 @@ namespace ix
|
|||||||
{
|
{
|
||||||
const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default
|
const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default
|
||||||
const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout;
|
const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout;
|
||||||
const uint64_t Socket::kSendRequest = 1;
|
const uint8_t Socket::kSendRequest = 1;
|
||||||
const uint64_t Socket::kCloseRequest = 2;
|
const uint8_t Socket::kCloseRequest = 2;
|
||||||
constexpr size_t Socket::kChunkSize;
|
constexpr size_t Socket::kChunkSize;
|
||||||
|
|
||||||
Socket::Socket(int fd) :
|
Socket::Socket(int fd) :
|
||||||
@@ -86,7 +86,7 @@ namespace ix
|
|||||||
}
|
}
|
||||||
else if (eventfd != -1 && FD_ISSET(eventfd, &rfds))
|
else if (eventfd != -1 && FD_ISSET(eventfd, &rfds))
|
||||||
{
|
{
|
||||||
uint64_t value = _eventfd.read();
|
uint8_t value = _eventfd.read();
|
||||||
|
|
||||||
if (value == kSendRequest)
|
if (value == kSendRequest)
|
||||||
{
|
{
|
||||||
|
@@ -76,8 +76,8 @@ namespace ix
|
|||||||
static void cleanup(); // Required on Windows to cleanup WinSocket
|
static void cleanup(); // Required on Windows to cleanup WinSocket
|
||||||
|
|
||||||
// Used as special codes for pipe communication
|
// Used as special codes for pipe communication
|
||||||
static const uint64_t kSendRequest;
|
static const uint8_t kSendRequest;
|
||||||
static const uint64_t kCloseRequest;
|
static const uint8_t kCloseRequest;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeSocket(int fd);
|
void closeSocket(int fd);
|
||||||
|
@@ -766,7 +766,6 @@ namespace ix
|
|||||||
_socket->close();
|
_socket->close();
|
||||||
|
|
||||||
_closeCode = 1000;
|
_closeCode = 1000;
|
||||||
_closeReason = "Normal Closure";
|
|
||||||
setReadyState(CLOSED);
|
setReadyState(CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user