windows port wip
This commit is contained in:
parent
88c2e1f6de
commit
c3bf260330
@ -6,22 +6,26 @@
|
||||
|
||||
#include "IXSocket.h"
|
||||
|
||||
#include <netdb.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/select.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <WinSock2.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <errno.h>
|
||||
# include <netdb.h>
|
||||
# include <netinet/tcp.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/select.h>
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Linux/Android has a special type of virtual files. select(2) will react
|
||||
@ -35,7 +39,7 @@
|
||||
// cf Android/Kernel table here
|
||||
// https://android.stackexchange.com/questions/51651/which-android-runs-which-linux-kernel
|
||||
//
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
# include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
@ -51,7 +55,7 @@ namespace ix
|
||||
_sockfd(-1),
|
||||
_eventfd(-1)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
_eventfd = eventfd(0, 0);
|
||||
assert(_eventfd != -1 && "Panic - eventfd not functioning on this platform");
|
||||
#endif
|
||||
@ -61,7 +65,7 @@ namespace ix
|
||||
{
|
||||
close();
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
::close(_eventfd);
|
||||
#endif
|
||||
}
|
||||
@ -163,7 +167,7 @@ namespace ix
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(_sockfd, &rfds);
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
FD_SET(_eventfd, &rfds);
|
||||
#endif
|
||||
|
||||
@ -191,7 +195,7 @@ namespace ix
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
wakeUpFromPollApple();
|
||||
#else
|
||||
#elif defined(__linux__)
|
||||
wakeUpFromPollLinux();
|
||||
#endif
|
||||
}
|
||||
@ -202,7 +206,7 @@ namespace ix
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_socketMutex);
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
if (_eventfd == -1)
|
||||
{
|
||||
return false; // impossible to use this socket if eventfd is broken
|
||||
@ -248,4 +252,12 @@ namespace ix
|
||||
return (int) ::recv(_sockfd, buffer, length, flags);
|
||||
}
|
||||
|
||||
int Socket::getErrno() const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return WSAGetLastError();
|
||||
#else
|
||||
return errno;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ namespace ix
|
||||
virtual int send(const std::string& buffer);
|
||||
virtual int recv(void* buffer, size_t length);
|
||||
|
||||
int getErrno() const;
|
||||
|
||||
protected:
|
||||
void wakeUpFromPollApple();
|
||||
void wakeUpFromPollLinux();
|
||||
|
@ -20,7 +20,6 @@
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cstdlib>
|
||||
@ -277,8 +276,8 @@ namespace ix {
|
||||
_rxbuf.resize(N + 1500);
|
||||
ret = _socket->recv((char*)&_rxbuf[0] + N, 1500);
|
||||
|
||||
if (ret < 0 && (errno == EWOULDBLOCK ||
|
||||
errno == EAGAIN)) {
|
||||
if (ret < 0 && (_socket->getErrno() == EWOULDBLOCK ||
|
||||
_socket->getErrno() == EAGAIN)) {
|
||||
_rxbuf.resize(N);
|
||||
break;
|
||||
}
|
||||
@ -575,8 +574,8 @@ namespace ix {
|
||||
{
|
||||
int ret = _socket->send((char*)&_txbuf[0], _txbuf.size());
|
||||
|
||||
if (ret < 0 && (errno == EWOULDBLOCK ||
|
||||
errno == EAGAIN))
|
||||
if (ret < 0 && (_socket->getErrno() == EWOULDBLOCK ||
|
||||
_socket->getErrno() == EAGAIN))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user