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) {
return r;
} else if (m_pathseg.size()+n >= 0) {
string r = m_protostr + string("://") + m_host + ((m_port != 0) ? string(":") + std::to_string(m_port) : "");
int N = m_pathseg.size()+n;
for (int i=0; i<N; i++) {
size_t N = m_pathseg.size()+n;
for (size_t i=0; i<N; i++) {
r += "/";
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_
#define _FTL_NET_LISTENER_HPP_
#ifndef WIN32
#include <netinet/in.h>
#endif
#ifdef WIN32
//#include <windows.h>
#include <winsock2.h>
#endif
#include <ftl/net/common.hpp>
#include <ftl/net/handlers.hpp>
#include <ftl/net/peer.hpp>
......@@ -23,12 +16,12 @@ class Protocol;
class Listener {
public:
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();
bool isListening() { return descriptor_ >= 0; }
void close();
int _socket() { return descriptor_; }
SOCKET _socket() { return descriptor_; }
void setProtocol(Protocol *p) { default_proto_ = p; }
......@@ -36,7 +29,7 @@ class Listener {
void onConnection(connecthandler_t h) { handler_connect_.push_back(h); };
private:
int descriptor_;
SOCKET descriptor_;
Protocol *default_proto_;
sockaddr_in slocalAddr;
std::vector<connecthandler_t> handler_connect_;
......
......@@ -5,12 +5,7 @@
#define NOMINMAX
#endif
#ifndef WIN32
#define INVALID_SOCKET -1
#include <netinet/in.h>
#else
#include <winsock2.h>
#endif
#include <ftl/net/common.hpp>
//#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <loguru.hpp>
......@@ -74,7 +69,7 @@ class Peer {
public:
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();
/**
......@@ -172,7 +167,7 @@ class Peer {
* Get the internal OS dependent socket.
* 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
......@@ -198,7 +193,7 @@ class Peer {
private: // Data
Status status_;
int sock_;
SOCKET sock_;
ftl::URI::scheme_t scheme_;
uint32_t version_;
......
......@@ -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
* 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);
......
......@@ -91,7 +91,7 @@ SOCKET tcpListen(URI &uri) {
return ssock;
}
int wsListen(URI &uri) {
SOCKET wsListen(URI &uri) {
return INVALID_SOCKET;
}
......
......@@ -6,11 +6,11 @@
#define NOMINMAX
#endif
#include <ftl/net/common.hpp>
#include <fcntl.h>
#ifdef WIN32
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <windows.h>
#endif
#ifdef WIN32
......@@ -24,17 +24,6 @@
#include <ftl/config.h>
#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 <memory>
#include <algorithm>
......@@ -68,7 +57,7 @@ ftl::UUID ftl::net::this_peer;
static ctpl::thread_pool pool(5);
// TODO(nick) Move to tcp_internal.cpp
static int tcpConnect(URI &uri) {
static SOCKET tcpConnect(URI &uri) {
int rc;
sockaddr_in destAddr;
......@@ -81,7 +70,7 @@ static int tcpConnect(URI &uri) {
#endif
//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) {
LOG(ERROR) << "Unable to create TCP socket";
......@@ -140,7 +129,7 @@ static int tcpConnect(URI &uri) {
return csocket;
}
Peer::Peer(int s, Dispatcher *d) : sock_(s) {
Peer::Peer(SOCKET s, Dispatcher *d) : sock_(s) {
status_ = (s == INVALID_SOCKET) ? kInvalid : kConnecting;
_updateURI();
......@@ -541,10 +530,10 @@ int Peer::_send() {
auto send_size = send_buf_.vector_size();
int c = 0;
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
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
send_buf_.clear();
......
......@@ -5,25 +5,15 @@
//#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <loguru.hpp>
#include <ftl/net/common.hpp>
#include <cstring>
#include <ftl/net/ws_internal.hpp>
#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
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <windows.h>
#endif
#include <string>
......@@ -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);
}
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:
// Masking key should (must) be derived from a high quality random
// 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
}
}
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 = "";
int status;
int i;
......@@ -158,7 +148,7 @@ bool ftl::net::ws_connect(int sockfd, const URI &uri) {
http += "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n";
http += "Sec-WebSocket-Version: 13\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()) {
LOG(ERROR) << "Could not send Websocket http request...";
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