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