win code runs
This commit is contained in:
parent
44e5ab7f7d
commit
a9ffa7da11
@ -13,6 +13,7 @@
|
||||
#include <sstream>
|
||||
#include <queue>
|
||||
#include <ixwebsocket/IXWebSocket.h>
|
||||
#include <ixwebsocket/IXSocket.h>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
@ -160,11 +161,9 @@ namespace
|
||||
|
||||
void interactiveMain()
|
||||
{
|
||||
std::string user(getenv("USER"));
|
||||
|
||||
WebSocketChat webSocketChat(user);
|
||||
|
||||
std::string user("foo");
|
||||
std::cout << "Type Ctrl-D to exit prompt..." << std::endl;
|
||||
WebSocketChat webSocketChat(user);
|
||||
webSocketChat.start();
|
||||
|
||||
while (true)
|
||||
@ -188,6 +187,9 @@ namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "main starting" << std::endl;
|
||||
Socket::init();
|
||||
std::cout << "socket initialized" << std::endl;
|
||||
interactiveMain();
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// Linux/Android has a special type of virtual files. select(2) will react
|
||||
// when reading/writing to those files, unlike closing sockets.
|
||||
@ -155,7 +157,7 @@ namespace ix
|
||||
|
||||
#ifdef _WIN32
|
||||
unsigned long nonblocking = 1;
|
||||
ioctlsocket(fd, FIONBIO, &nonblocking);
|
||||
ioctlsocket(_sockfd, FIONBIO, &nonblocking);
|
||||
#else
|
||||
fcntl(_sockfd, F_SETFL, O_NONBLOCK); // make socket non blocking
|
||||
#endif
|
||||
@ -184,7 +186,7 @@ namespace ix
|
||||
#endif
|
||||
|
||||
int sockfd = _sockfd;
|
||||
int nfds = std::max(sockfd, _eventfd);
|
||||
int nfds = (std::max)(sockfd, _eventfd);
|
||||
select(nfds + 1, &rfds, nullptr, nullptr, nullptr);
|
||||
|
||||
onPollCallback();
|
||||
@ -261,7 +263,7 @@ namespace ix
|
||||
flags = MSG_NOSIGNAL;
|
||||
#endif
|
||||
|
||||
return (int) ::recv(_sockfd, buffer, length, flags);
|
||||
return (int) ::recv(_sockfd, (char*) buffer, length, flags);
|
||||
}
|
||||
|
||||
int Socket::getErrno() const
|
||||
@ -279,6 +281,18 @@ namespace ix
|
||||
closesocket(fd);
|
||||
#else
|
||||
::close(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
// FIXME: need finalize
|
||||
bool Socket::init()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
INT rc;
|
||||
WSADATA wsaData;
|
||||
|
||||
rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
return rc != 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ namespace ix
|
||||
Socket();
|
||||
virtual ~Socket();
|
||||
|
||||
static bool init();
|
||||
|
||||
int hostname_connect(const std::string& hostname,
|
||||
int port,
|
||||
std::string& errMsg);
|
||||
|
@ -19,8 +19,9 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
// #include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
@ -272,7 +273,7 @@ namespace ix {
|
||||
{
|
||||
int N = (int) _rxbuf.size();
|
||||
|
||||
ssize_t ret;
|
||||
int ret;
|
||||
_rxbuf.resize(N + 1500);
|
||||
ret = _socket->recv((char*)&_rxbuf[0] + N, 1500);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user