Skip to content

Commit

Permalink
WinSock2
Browse files Browse the repository at this point in the history
  • Loading branch information
haphzd committed Jul 27, 2016
1 parent d644c75 commit f9d566e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions rwgame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ target_link_libraries( rwgame
${BULLET_LIBRARIES})
if(MINGW)
add_definitions(-D _USE_MATH_DEFINES)
target_link_libraries( rwgame
target_link_libraries(rwgame
iconv
mman)
mman
ws2_32)
endif()
>>>>>>> c825ae3... Windows/MinGW_W64 compatibility

Expand Down
12 changes: 7 additions & 5 deletions rwgame/debug/TcpSocket.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <vector>

Expand Down Expand Up @@ -65,15 +63,19 @@ size_t TcpSocket::send(const std::string& str)

void TcpSocket::disconnect()
{
close(sock);
#ifndef RW_WINDOWS
close(sock);
#else
closesocket(sock);
#endif
sock = -1;
}


std::string TcpSocket::getRemoteAddress() const
char* TcpSocket::getRemoteAddress() const
{
char buffer[INET_ADDRSTRLEN+1] = { };
return inet_ntop(AF_INET, &addr, buffer, INET_ADDRSTRLEN+1);
return inet_ntoa(addr.sin_addr);
}


Expand Down
9 changes: 7 additions & 2 deletions rwgame/debug/TcpSocket.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#pragma once

#include <string>
#ifndef RW_WINDOWS
#include <netinet/in.h>

#include <sys/socket.h>
#include <arpa/inet.h>
#else
#include <ws2tcpip.h>
#endif

class TcpSocket
{
Expand All @@ -17,7 +22,7 @@ class TcpSocket
size_t send(const std::string& str);
void disconnect();

std::string getRemoteAddress() const;
char* getRemoteAddress() const;
short getRemotePort() const;

private:
Expand Down

0 comments on commit f9d566e

Please sign in to comment.