Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix obvious issues when build by Visual Studio 2005 #94

Closed
wants to merge 3 commits into from

2 participants

@don-pit

Greetings.

I've built libmodbus with Visual Studio 2005 and by the way have fixed some issues. They are concerning a) compilation and b) prolonged connection phase on nonblocking socket.

I hope this patch would be useful.

don-pit added some commits
@don-pit don-pit Build modbus.dll with Visual Studio 2005 and fix some build problems 64597be
@don-pit don-pit Connect nonblocking socket in win32
If socket is nonblocking and connection cannot be completed immediately,
connect() sets last error to WSAEWOULDBLOCK (as stated in MSDN).
ea1c664
@don-pit don-pit Restore typo in copyright message 4f968ed
@stephane
Owner

Does current src/win32/modbus.vcproj in master work for you?

Almost. Just change attribute Version of VisualStudioProject tag to 8 and get plausible project file. Other differences were introduced by VS2005 automatically, so I don't think they are significant.

Owner

So we add this information in a README file, it's OK?

Yes. Should modbus-8.vcproj stay under version control?

Owner

Ok. Can I merge with master before moving ahead?

Owner

The fix for unsigned long ioctloption = 1; is already in master (different version btw) and I want to keep only vc project in master so what you want to merge?

Owner

sorry, I mean "I want to keep only one vc project in master"

Current master head (as in bfee617) is still broken for VS 2005. I had to shift ws2tcpip.h inclusion along the modbus-tcp.c file.
I think it's better to open a new pull request instead of #94 on top of the current head.

Owner

Yes for opening a new pull request.
Thank you.

@stephane

Could we call WSAGetLastError();

Owner

and does it return same value on subsequent calls?
The MSDN documentation isn't really clear on that point but it's possible so it will avoid a useless if in POSIX code.

Seems so. But IMHO using of WSAGetLastError() calls instead of socket_error variable would be risky.

@don-pit

Partially replaced with #98

@don-pit don-pit closed this
@don-pit don-pit deleted the don-pit:vs2005_build branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 5, 2013
  1. @don-pit
Commits on Feb 6, 2013
  1. @don-pit

    Connect nonblocking socket in win32

    don-pit authored
    If socket is nonblocking and connection cannot be completed immediately,
    connect() sets last error to WSAEWOULDBLOCK (as stated in MSDN).
  2. @don-pit
This page is out of date. Refresh to see the latest.
Showing with 503 additions and 32 deletions.
  1. +38 −31 src/modbus-tcp.c
  2. +1 −1  src/win32/README.win32
  3. +464 −0 src/win32/modbus-8.vcproj
View
69 src/modbus-tcp.c
@@ -28,14 +28,6 @@
#if defined(_WIN32)
# define OS_WIN32
-/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
- * minwg32 headers check WINVER before allowing the use of these */
-# ifndef WINVER
-# define WINVER 0x0501
-# endif
-# include <ws2tcpip.h>
-# define SHUT_RDWR 2
-# define close closesocket
#else
# include <sys/socket.h>
# include <sys/ioctl.h>
@@ -62,6 +54,16 @@
#include "modbus-tcp-private.h"
#ifdef OS_WIN32
+
+/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
+ * minwg32 headers check WINVER before allowing the use of these */
+# ifndef WINVER
+# define WINVER 0x0501
+# endif
+# include <ws2tcpip.h>
+# define SHUT_RDWR 2
+# define close closesocket
+
static int _modbus_tcp_init_win32(void)
{
/* Initialise Windows Socket API */
@@ -224,8 +226,10 @@ static int _modbus_tcp_set_ipv4_options(int s)
#if !defined(SOCK_NONBLOCK) && defined(FIONBIO)
#ifdef OS_WIN32
/* Setting FIONBIO expects an unsigned long according to MSDN */
- unsigned long ioctloption = 1;
- ioctlsocket(s, FIONBIO, &ioctloption);
+ {
+ unsigned ioctloption = 1;
+ ioctlsocket(s, FIONBIO, &ioctloption);
+ }
#else
option = 1;
ioctl(s, FIONBIO, &option);
@@ -256,31 +260,34 @@ static int _connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen,
rc = connect(sockfd, addr, addrlen);
+ if (rc == -1) {
#ifdef OS_WIN32
- if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {
+ int socket_error = WSAGetLastError();
+ if (socket_error == WSAEINPROGRESS || socket_error == WSAEWOULDBLOCK) {
#else
- if (rc == -1 && errno == EINPROGRESS) {
+ if (errno == EINPROGRESS) {
#endif
- fd_set wset;
- int optval;
- socklen_t optlen = sizeof(optval);
-
- /* Wait to be available in writing */
- FD_ZERO(&wset);
- FD_SET(sockfd, &wset);
- rc = select(sockfd + 1, NULL, &wset, NULL, tv);
- if (rc <= 0) {
- /* Timeout or fail */
- return -1;
- }
+ fd_set wset;
+ int optval;
+ socklen_t optlen = sizeof(optval);
+
+ /* Wait to be available in writing */
+ FD_ZERO(&wset);
+ FD_SET(sockfd, &wset);
+ rc = select(sockfd + 1, NULL, &wset, NULL, tv);
+ if (rc <= 0) {
+ /* Timeout or fail */
+ return -1;
+ }
- /* The connection is established if SO_ERROR and optval are set to 0 */
- rc = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen);
- if (rc == 0 && optval == 0) {
- return 0;
- } else {
- errno = ECONNREFUSED;
- return -1;
+ /* The connection is established if SO_ERROR and optval are set to 0 */
+ rc = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen);
+ if (rc == 0 && optval == 0) {
+ return 0;
+ } else {
+ errno = ECONNREFUSED;
+ return -1;
+ }
}
}
return rc;
View
2  src/win32/README.win32
@@ -1,7 +1,7 @@
Intro
-----
-This directory contains the project file for Visual Studio 2008 to build a
+This directory contains the project files for Visual Studio to build a
modbus.dll.
The project file searches for D:/include/msvc_std to find stdint.h.
View
464 src/win32/modbus-8.vcproj
@@ -0,0 +1,464 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8,00"
+ Name="modbus"
+ ProjectGUID="{498E0845-C7F4-438B-8EDE-EF7FC9A74430}"
+ RootNamespace="modbus"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ Description=""
+ CommandLine=""
+ AdditionalDependencies=""
+ Outputs=""
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ EnableIntrinsicFunctions="true"
+ WholeProgramOptimization="false"
+ AdditionalIncludeDirectories="..\src;..;.;D:/include/msvc_std"
+ PreprocessorDefinitions="HAVE_CONFIG_H;DLLBUILD;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NONSTDC_NO_DEPRECATE=1"
+ MinimalRebuild="false"
+ ExceptionHandling="0"
+ BasicRuntimeChecks="2"
+ RuntimeLibrary="1"
+ FloatingPointModel="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ CompileAs="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_MSC_VER"
+ ResourceOutputFileName="$(SolutionDir)/modbus.res"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="ws2_32.lib"
+ Version="1.0.0"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""
+ GenerateManifest="true"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ Description=""
+ CommandLine=""
+ AdditionalDependencies=""
+ Outputs=""
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ WholeProgramOptimization="false"
+ AdditionalIncludeDirectories="..\src;..;.;D:/include/msvc_std"
+ PreprocessorDefinitions="HAVE_CONFIG_H;DLLBUILD;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NONSTDC_NO_DEPRECATE=1"
+ ExceptionHandling="0"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="false"
+ FloatingPointModel="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="0"
+ CompileAs="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions=""
+ AdditionalDependencies="ws2_32.lib"
+ LinkIncremental="0"
+ GenerateManifest="true"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ StackReserveSize="1048576"
+ StackCommitSize="524288"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="0"
+ EntryPointSymbol=""
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ SuppressStartupBanner="false"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ Description=""
+ CommandLine=""
+ AdditionalDependencies=""
+ Outputs=""
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ WholeProgramOptimization="false"
+ AdditionalIncludeDirectories="$(SolutionDir)"
+ PreprocessorDefinitions=""
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="0"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ CompileAs="1"
+ DisableSpecificWarnings="4244;4267"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ StackReserveSize="1048576"
+ StackCommitSize="524288"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ Description=""
+ CommandLine=""
+ AdditionalDependencies=""
+ Outputs=""
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ WholeProgramOptimization="false"
+ AdditionalIncludeDirectories="$(SolutionDir)"
+ PreprocessorDefinitions=""
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ CompileAs="1"
+ DisableSpecificWarnings="4244;4267"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ StackReserveSize="1048576"
+ StackCommitSize="524288"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="0"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\modbus-data.c"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-rtu.c"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-tcp.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ GeneratePreprocessedFile="0"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\modbus.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="config.h"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-private.h"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-rtu-private.h"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-rtu.h"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-tcp-private.h"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus-tcp.h"
+ >
+ </File>
+ <File
+ RelativePath="modbus-version.h"
+ >
+ </File>
+ <File
+ RelativePath="..\modbus.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\modbus.rc"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Something went wrong with that request. Please try again.