Skip to content
Snippets Groups Projects
Commit 3375eb60 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

More windows warning fixes

parent c2994719
No related branches found
No related tags found
No related merge requests found
Pipeline #11200 failed
...@@ -123,8 +123,8 @@ string URI::getBaseURI(int n) { ...@@ -123,8 +123,8 @@ string URI::getBaseURI(int n) {
return r; return r;
} else if (m_pathseg.size()+n >= 0) { } else if (m_pathseg.size()+n >= 0) {
string r = m_protostr + string("://") + m_host + ((m_port != 0) ? string(":") + std::to_string(m_port) : ""); string r = m_protostr + string("://") + m_host + ((m_port != 0) ? string(":") + std::to_string(m_port) : "");
int N = m_pathseg.size()+n; size_t N = m_pathseg.size()+n;
for (int i=0; i<N; i++) { for (size_t i=0; i<N; i++) {
r += "/"; r += "/";
r += getPathSegment(i); r += getPathSegment(i);
} }
......
#ifndef _FTL_NET_COMMON_HPP_
#define _FTL_NET_COMMON_HPP_
#ifndef WIN32
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define SOCKET int
#endif
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
typedef int socklen_t;
#endif
#endif // _FTL_NET_COMMON_HPP_
#ifndef _FTL_NET_LISTENER_HPP_ #ifndef _FTL_NET_LISTENER_HPP_
#define _FTL_NET_LISTENER_HPP_ #define _FTL_NET_LISTENER_HPP_
#ifndef WIN32 #include <ftl/net/common.hpp>
#include <netinet/in.h>
#endif
#ifdef WIN32
//#include <windows.h>
#include <winsock2.h>
#endif
#include <ftl/net/handlers.hpp> #include <ftl/net/handlers.hpp>
#include <ftl/net/peer.hpp> #include <ftl/net/peer.hpp>
...@@ -23,12 +16,12 @@ class Protocol; ...@@ -23,12 +16,12 @@ class Protocol;
class Listener { class Listener {
public: public:
explicit Listener(const char *uri); explicit Listener(const char *uri);
explicit Listener(int sfd) : descriptor_(sfd), default_proto_(nullptr) {} explicit Listener(SOCKET sfd) : descriptor_(sfd), default_proto_(nullptr) {}
virtual ~Listener(); virtual ~Listener();
bool isListening() { return descriptor_ >= 0; } bool isListening() { return descriptor_ >= 0; }
void close(); void close();
int _socket() { return descriptor_; } SOCKET _socket() { return descriptor_; }
void setProtocol(Protocol *p) { default_proto_ = p; } void setProtocol(Protocol *p) { default_proto_ = p; }
...@@ -36,7 +29,7 @@ class Listener { ...@@ -36,7 +29,7 @@ class Listener {
void onConnection(connecthandler_t h) { handler_connect_.push_back(h); }; void onConnection(connecthandler_t h) { handler_connect_.push_back(h); };
private: private:
int descriptor_; SOCKET descriptor_;
Protocol *default_proto_; Protocol *default_proto_;
sockaddr_in slocalAddr; sockaddr_in slocalAddr;
std::vector<connecthandler_t> handler_connect_; std::vector<connecthandler_t> handler_connect_;
......
...@@ -5,12 +5,7 @@ ...@@ -5,12 +5,7 @@
#define NOMINMAX #define NOMINMAX
#endif #endif
#ifndef WIN32 #include <ftl/net/common.hpp>
#define INVALID_SOCKET -1
#include <netinet/in.h>
#else
#include <winsock2.h>
#endif
//#define GLOG_NO_ABBREVIATED_SEVERITIES //#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <loguru.hpp> #include <loguru.hpp>
...@@ -74,7 +69,7 @@ class Peer { ...@@ -74,7 +69,7 @@ class Peer {
public: public:
explicit Peer(const char *uri, ftl::net::Dispatcher *d=nullptr); explicit Peer(const char *uri, ftl::net::Dispatcher *d=nullptr);
explicit Peer(int s, ftl::net::Dispatcher *d=nullptr); explicit Peer(SOCKET s, ftl::net::Dispatcher *d=nullptr);
~Peer(); ~Peer();
/** /**
...@@ -172,7 +167,7 @@ class Peer { ...@@ -172,7 +167,7 @@ class Peer {
* Get the internal OS dependent socket. * Get the internal OS dependent socket.
* TODO(nick) Work out if this should be private. * TODO(nick) Work out if this should be private.
*/ */
int _socket() const { return sock_; }; SOCKET _socket() const { return sock_; };
/** /**
* Internal handlers for specific event types. This should be private but * Internal handlers for specific event types. This should be private but
...@@ -198,7 +193,7 @@ class Peer { ...@@ -198,7 +193,7 @@ class Peer {
private: // Data private: // Data
Status status_; Status status_;
int sock_; SOCKET sock_;
ftl::URI::scheme_t scheme_; ftl::URI::scheme_t scheme_;
uint32_t version_; uint32_t version_;
......
...@@ -42,7 +42,7 @@ int ws_dispatch(const char *data, size_t len, std::function<void(const wsheader_ ...@@ -42,7 +42,7 @@ int ws_dispatch(const char *data, size_t len, std::function<void(const wsheader_
* Websocket header constructor. Fills a buffer with the correct websocket * Websocket header constructor. Fills a buffer with the correct websocket
* header for a given opcode, mask setting and message length. * header for a given opcode, mask setting and message length.
*/ */
size_t ws_prepare(wsheader_type::opcode_type, bool useMask, size_t len, char *buffer, size_t maxlen); int ws_prepare(wsheader_type::opcode_type, bool useMask, size_t len, char *buffer, size_t maxlen);
bool ws_connect(int sockfd, const ftl::URI &uri); bool ws_connect(int sockfd, const ftl::URI &uri);
......
...@@ -91,7 +91,7 @@ SOCKET tcpListen(URI &uri) { ...@@ -91,7 +91,7 @@ SOCKET tcpListen(URI &uri) {
return ssock; return ssock;
} }
int wsListen(URI &uri) { SOCKET wsListen(URI &uri) {
return INVALID_SOCKET; return INVALID_SOCKET;
} }
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#define NOMINMAX #define NOMINMAX
#endif #endif
#include <ftl/net/common.hpp>
#include <fcntl.h> #include <fcntl.h>
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h>
#include <Ws2tcpip.h> #include <Ws2tcpip.h>
#include <windows.h>
#endif #endif
#ifdef WIN32 #ifdef WIN32
...@@ -24,17 +24,6 @@ ...@@ -24,17 +24,6 @@
#include <ftl/config.h> #include <ftl/config.h>
#include "net_internal.hpp" #include "net_internal.hpp"
#ifndef WIN32
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <algorithm> #include <algorithm>
...@@ -68,7 +57,7 @@ ftl::UUID ftl::net::this_peer; ...@@ -68,7 +57,7 @@ ftl::UUID ftl::net::this_peer;
static ctpl::thread_pool pool(5); static ctpl::thread_pool pool(5);
// TODO(nick) Move to tcp_internal.cpp // TODO(nick) Move to tcp_internal.cpp
static int tcpConnect(URI &uri) { static SOCKET tcpConnect(URI &uri) {
int rc; int rc;
sockaddr_in destAddr; sockaddr_in destAddr;
...@@ -81,7 +70,7 @@ static int tcpConnect(URI &uri) { ...@@ -81,7 +70,7 @@ static int tcpConnect(URI &uri) {
#endif #endif
//We want a TCP socket //We want a TCP socket
int csocket = socket(AF_INET, SOCK_STREAM, 0); SOCKET csocket = socket(AF_INET, SOCK_STREAM, 0);
if (csocket == INVALID_SOCKET) { if (csocket == INVALID_SOCKET) {
LOG(ERROR) << "Unable to create TCP socket"; LOG(ERROR) << "Unable to create TCP socket";
...@@ -140,7 +129,7 @@ static int tcpConnect(URI &uri) { ...@@ -140,7 +129,7 @@ static int tcpConnect(URI &uri) {
return csocket; return csocket;
} }
Peer::Peer(int s, Dispatcher *d) : sock_(s) { Peer::Peer(SOCKET s, Dispatcher *d) : sock_(s) {
status_ = (s == INVALID_SOCKET) ? kInvalid : kConnecting; status_ = (s == INVALID_SOCKET) ? kInvalid : kConnecting;
_updateURI(); _updateURI();
...@@ -541,10 +530,10 @@ int Peer::_send() { ...@@ -541,10 +530,10 @@ int Peer::_send() {
auto send_size = send_buf_.vector_size(); auto send_size = send_buf_.vector_size();
int c = 0; int c = 0;
for (int i = 0; i < send_size; i++) { for (int i = 0; i < send_size; i++) {
c += ftl::net::internal::send(sock_, (char*)send_vec[i].iov_base, send_vec[i].iov_len, 0); c += ftl::net::internal::send(sock_, (char*)send_vec[i].iov_base, (int)send_vec[i].iov_len, 0);
} }
#else #else
int c = ftl::net::internal::writev(sock_, send_buf_.vector(), send_buf_.vector_size()); int c = ftl::net::internal::writev(sock_, send_buf_.vector(), (int)send_buf_.vector_size());
#endif #endif
send_buf_.clear(); send_buf_.clear();
......
...@@ -5,25 +5,15 @@ ...@@ -5,25 +5,15 @@
//#define GLOG_NO_ABBREVIATED_SEVERITIES //#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <loguru.hpp> #include <loguru.hpp>
#include <ftl/net/common.hpp>
#include <cstring> #include <cstring>
#include <ftl/net/ws_internal.hpp> #include <ftl/net/ws_internal.hpp>
#include <memory> #include <memory>
#ifndef WIN32
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h>
#include <Ws2tcpip.h> #include <Ws2tcpip.h>
#include <windows.h>
#endif #endif
#include <string> #include <string>
...@@ -88,7 +78,7 @@ int ftl::net::ws_dispatch(const char *data, size_t len, std::function<void(const ...@@ -88,7 +78,7 @@ int ftl::net::ws_dispatch(const char *data, size_t len, std::function<void(const
return (int)(ws.header_size+ws.N); return (int)(ws.header_size+ws.N);
} }
size_t ftl::net::ws_prepare(wsheader_type::opcode_type op, bool useMask, size_t len, char *data, size_t maxlen) { int ftl::net::ws_prepare(wsheader_type::opcode_type op, bool useMask, size_t len, char *data, size_t maxlen) {
// TODO: // TODO:
// Masking key should (must) be derived from a high quality random // Masking key should (must) be derived from a high quality random
// number generator, to mitigate attacks on non-WebSocket friendly // number generator, to mitigate attacks on non-WebSocket friendly
...@@ -138,10 +128,10 @@ size_t ftl::net::ws_prepare(wsheader_type::opcode_type op, bool useMask, size_t ...@@ -138,10 +128,10 @@ size_t ftl::net::ws_prepare(wsheader_type::opcode_type op, bool useMask, size_t
} }
} }
return header_size; return (int)header_size;
} }
bool ftl::net::ws_connect(int sockfd, const URI &uri) { bool ftl::net::ws_connect(SOCKET sockfd, const URI &uri) {
string http = ""; string http = "";
int status; int status;
int i; int i;
...@@ -158,7 +148,7 @@ bool ftl::net::ws_connect(int sockfd, const URI &uri) { ...@@ -158,7 +148,7 @@ bool ftl::net::ws_connect(int sockfd, const URI &uri) {
http += "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"; http += "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n";
http += "Sec-WebSocket-Version: 13\r\n"; http += "Sec-WebSocket-Version: 13\r\n";
http += "\r\n"; http += "\r\n";
int rc = (int)::send(sockfd, http.c_str(), http.length(), 0); int rc = ::send(sockfd, http.c_str(), (int)http.length(), 0);
if (rc != (int)http.length()) { if (rc != (int)http.length()) {
LOG(ERROR) << "Could not send Websocket http request..."; LOG(ERROR) << "Could not send Websocket http request...";
std::cout << http; std::cout << http;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment