Got it working on Windows using Mingw
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
#include "TessesFramework/Streams/FileStream.hpp"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
namespace Tesses::Framework::Streams
|
||||
{
|
||||
void FileStream::SetMode(std::string mode)
|
||||
@ -32,7 +34,8 @@ namespace Tesses::Framework::Streams
|
||||
}
|
||||
FileStream::FileStream(std::filesystem::path p, std::string mode)
|
||||
{
|
||||
this->f = fopen(p.c_str(),mode.c_str());
|
||||
std::string str = p.string();
|
||||
this->f = fopen(str.c_str(),mode.c_str());
|
||||
this->canSeek = true;
|
||||
this->owns=true;
|
||||
this->SetMode(mode);
|
||||
@ -66,7 +69,11 @@ namespace Tesses::Framework::Streams
|
||||
}
|
||||
int64_t FileStream::GetPosition()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return (int64_t)_ftelli64(this->f);
|
||||
#else
|
||||
return (int64_t)ftello(this->f);
|
||||
#endif
|
||||
}
|
||||
void FileStream::Flush()
|
||||
{
|
||||
@ -74,7 +81,11 @@ namespace Tesses::Framework::Streams
|
||||
}
|
||||
void FileStream::Seek(int64_t pos, SeekOrigin whence)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
_fseeki64(this->f,pos,whence == SeekOrigin::Begin ? SEEK_SET : whence == SeekOrigin::Current ? SEEK_CUR : SEEK_END);
|
||||
#else
|
||||
fseeko(this->f,(off_t)pos,whence == SeekOrigin::Begin ? SEEK_SET : whence == SeekOrigin::Current ? SEEK_CUR : SEEK_END);
|
||||
#endif
|
||||
}
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
|
||||
@ -14,7 +14,12 @@ using HttpUtils = Tesses::Framework::Http::HttpUtils;
|
||||
#else
|
||||
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <ws2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#else
|
||||
extern "C" {
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
@ -23,10 +28,11 @@ extern "C" {
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
}
|
||||
#endif
|
||||
#if defined(GEKKO)
|
||||
|
||||
extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool use_dhcp, int max_retries);
|
||||
#else
|
||||
#elif !defined(_WIN32)
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
@ -42,8 +48,12 @@ extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool
|
||||
#define NETWORK_ACCEPT accept
|
||||
#define NETWORK_GETADDRINFO getaddrinfo
|
||||
#define NETWORK_FREEADDRINFO freeaddrinfo
|
||||
#if defined(_WIN32)
|
||||
#define NETWORK_CLOSE closesocket
|
||||
#else
|
||||
#define NETWORK_CLOSE close
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef AF_INET6
|
||||
|
||||
@ -61,6 +71,8 @@ namespace Tesses::Framework::Streams {
|
||||
char gateway[16];
|
||||
if_config(localIp,netmask, gateway, true, 1);
|
||||
ipConfig.push_back(std::pair<std::string,std::string>("net",localIp));
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#else
|
||||
struct ifaddrs *ifAddrStruct = NULL;
|
||||
getifaddrs(&ifAddrStruct);
|
||||
@ -367,7 +379,7 @@ namespace Tesses::Framework::Streams {
|
||||
if(broadcast)
|
||||
{
|
||||
int broadcast = 1;
|
||||
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) != 0) {
|
||||
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)) != 0) {
|
||||
this->success=false;
|
||||
NETWORK_CLOSE(this->sock);
|
||||
continue;
|
||||
@ -434,7 +446,7 @@ namespace Tesses::Framework::Streams {
|
||||
{
|
||||
if(!this->success) return;
|
||||
int broadcast = 1;
|
||||
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) != 0)
|
||||
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)) != 0)
|
||||
{
|
||||
this->success=false;
|
||||
if(this->owns)
|
||||
@ -462,7 +474,7 @@ namespace Tesses::Framework::Streams {
|
||||
{
|
||||
|
||||
if(!this->success) return 0;
|
||||
ssize_t r = NETWORK_RECV(this->sock,buff,sz,0);
|
||||
ssize_t r = NETWORK_RECV(this->sock,(char*)buff,sz,0);
|
||||
|
||||
if(r <= 0)
|
||||
{
|
||||
@ -477,7 +489,7 @@ namespace Tesses::Framework::Streams {
|
||||
|
||||
if(!this->success) return 0;
|
||||
|
||||
ssize_t sz2 = NETWORK_SEND(this->sock,buff,sz, 0);
|
||||
ssize_t sz2 = NETWORK_SEND(this->sock,(const char*)buff,sz, 0);
|
||||
if(sz2 < 0) return 0;
|
||||
|
||||
return (size_t)sz;
|
||||
@ -487,7 +499,7 @@ namespace Tesses::Framework::Streams {
|
||||
if(!this->success) return 0;
|
||||
struct sockaddr_storage storage;
|
||||
socklen_t addrlen=(socklen_t)sizeof(storage);
|
||||
ssize_t r = NETWORK_RECVFROM(this->sock,buff,sz,0, (struct sockaddr*)&storage, (socklen_t*)&addrlen);
|
||||
ssize_t r = NETWORK_RECVFROM(this->sock,(char*)buff,sz,0, (struct sockaddr*)&storage, (socklen_t*)&addrlen);
|
||||
ip = StringifyIP((struct sockaddr*)&storage);
|
||||
port = GetPort((struct sockaddr*)&storage);
|
||||
if(r < 0) return 0;
|
||||
@ -516,7 +528,7 @@ namespace Tesses::Framework::Streams {
|
||||
}
|
||||
|
||||
SetPort((struct sockaddr*)&addr, port);
|
||||
ssize_t sz2 = NETWORK_SENDTO(this->sock,buff,sz, 0, (const sockaddr*)&addr, (socklen_t)sizeof(addr));
|
||||
ssize_t sz2 = NETWORK_SENDTO(this->sock,(const char*)buff,sz, 0, (const sockaddr*)&addr, (socklen_t)sizeof(addr));
|
||||
if(sz2 < 0) return 0;
|
||||
return (size_t)sz2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user