Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
Fix Visual C++ Compiler Warnings: (#33)
Browse files Browse the repository at this point in the history
- Enable 'TreatWarningsAsErrors' in build config.
- For Win, convert socket buffer sizes to INT.
- For Win, suppress IPv6 warning.
  • Loading branch information
zodiac403 authored and Cylix committed Oct 31, 2017
1 parent e0d0208 commit c4e0cf6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ target
*.exe
*.out
*.app
.vs/
*.sln
*.vcxproj
*.suo
Expand Down
12 changes: 8 additions & 4 deletions msvc15/tacopie.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ SOFTWARE.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand All @@ -95,7 +95,7 @@ SOFTWARE.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -133,6 +133,7 @@ SOFTWARE.
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -146,6 +147,7 @@ SOFTWARE.
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -161,6 +163,7 @@ SOFTWARE.
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -178,6 +181,7 @@ SOFTWARE.
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -188,4 +192,4 @@ SOFTWARE.
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
15 changes: 11 additions & 4 deletions sources/network/common/tcp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
#define SOCKET_ERROR -1
#endif /* SOCKET_ERROR */

#if _WIN32
#define __TACOPIE_LENGTH(size) static_cast<int>(size) // for Windows, convert buffer size to `int`
#pragma warning ( disable: 4996 ) // for Windows, `inet_ntoa` is deprecated as it does not support IPv6
#else
#define __TACOPIE_LENGTH(size) size // for Unix, keep buffer size as `size_t`
#endif /* _WIN32 */

namespace tacopie {

//!
Expand Down Expand Up @@ -92,7 +99,7 @@ tcp_socket::recv(std::size_t size_to_read) {

std::vector<char> data(size_to_read, 0);

ssize_t rd_size = ::recv(m_fd, const_cast<char*>(data.data()), size_to_read, 0);
ssize_t rd_size = ::recv(m_fd, const_cast<char*>(data.data()), __TACOPIE_LENGTH(size_to_read), 0);

if (rd_size == SOCKET_ERROR) { __TACOPIE_THROW(error, "recv() failure"); }

Expand All @@ -108,7 +115,7 @@ tcp_socket::send(const std::vector<char>& data, std::size_t size_to_write) {
create_socket_if_necessary();
check_or_set_type(type::CLIENT);

ssize_t wr_size = ::send(m_fd, data.data(), size_to_write, 0);
ssize_t wr_size = ::send(m_fd, data.data(), __TACOPIE_LENGTH(size_to_write), 0);

if (wr_size == SOCKET_ERROR) { __TACOPIE_THROW(error, "send() failure"); }

Expand All @@ -124,7 +131,7 @@ tcp_socket::listen(std::size_t max_connection_queue) {
create_socket_if_necessary();
check_or_set_type(type::SERVER);

if (::listen(m_fd, max_connection_queue) == SOCKET_ERROR) { __TACOPIE_THROW(debug, "listen() failure"); }
if (::listen(m_fd, __TACOPIE_LENGTH(max_connection_queue)) == SOCKET_ERROR) { __TACOPIE_THROW(debug, "listen() failure"); }
}

tcp_socket
Expand All @@ -143,7 +150,7 @@ tcp_socket::accept(void) {
}

//!
//! check whether the current socket has an approriate type for that kind of operation
//! check whether the current socket has an appropriate type for that kind of operation
//! if current type is UNKNOWN, update internal type with given type
//!

Expand Down

0 comments on commit c4e0cf6

Please sign in to comment.