Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play nice with other processes. #38

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
3 changes: 2 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
# enable clock_gettime:
add_definitions( -D_POSIX_C_SOURCE=199309L )
endif()

elseif (MSVC)
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
endif()

add_subdirectory( src )
6 changes: 3 additions & 3 deletions source/src/byte_bufs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ByteBuf

uint8_t* data() const { return start; }
uint8_t* end() const { return limit; }
ssize_t size() const { return limit - start; } // ssize_t is signed
uint16_t size() const { return limit - start; } // uint16_t is signed

protected:
uint8_t* start;
Expand Down Expand Up @@ -72,7 +72,7 @@ class BufWriter
/// Return the unused size of the buffer, the remaining capacity which is empty.
/// A negative value would indicate an overrun, but that also indicates a bug in
/// in this class because protections are everywhere to prevent overruns.
ssize_t capacity() const { return limit - start; }
uint16_t capacity() const { return limit - start; }

/// Advance the start of the buffer by the specified number of bytes and trim
/// the capacity().
Expand Down Expand Up @@ -174,7 +174,7 @@ class BufReader
/// in the buffer.
/// A negative value would indicate an overrun, but that also indicates a bug in
/// in this class because protections are everywhere to prevent overruns.
ssize_t size() const { return limit - start; }
uint16_t size() const { return limit - start; }

/// Advance the start of the buffer by the specified number of bytes and trim
/// the size().
Expand Down
4 changes: 4 additions & 0 deletions source/src/cip/cipconnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,11 @@ void CipConn::GeneralConfiguration( ConnectionData* aConnData, ConnInstanceType
// "expected_packet_rate x connection_timeout_multiplier". Initial value
// is called a "pre-consumption" timeout value.
if( RxTimeoutUSecs() )
#ifdef _MSC_VER
SetInactivityWatchDogTimerUSecs(max(RxTimeoutUSecs(), 10000000u));
#else
SetInactivityWatchDogTimerUSecs( std::max( RxTimeoutUSecs(), 10000000u ) );
#endif
else
{
// this is not an erro
Expand Down
5 changes: 4 additions & 1 deletion source/src/enet_encap/encap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,11 @@ static int disposeOfLargePacket( int aSocket, unsigned aCount )
while( aCount )
{
// toss in chunks.
#ifdef _MSC_VER
int readz = min(aCount, unsigned(sizeof chunk));
#else
int readz = std::min( aCount, unsigned( sizeof chunk ) );

#endif
int num_read = Encapsulation::EnsuredTcpRecv( aSocket, chunk, readz );

if( num_read != readz )
Expand Down
4 changes: 2 additions & 2 deletions source/src/enet_encap/networkhandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ EipStatus NetworkHandlerInitialize()
}


EipStatus NetworkHandlerProcessOnce()
EipStatus NetworkHandlerProcessOnce(int timeoutInSeconds)
{
read_set = master_set;

Expand All @@ -785,7 +785,7 @@ EipStatus NetworkHandlerProcessOnce()
// On Linux, select() modifies timeout to reflect the amount of time
// not slept; most other implementations do not do this.
// Consider timeout to be undefined after select() returns.
tv.tv_sec = 0;
tv.tv_sec = timeoutInSeconds;
tv.tv_usec = 0;

int ready_count = select( highest_socket_handle + 1, &read_set, 0, 0, &tv );
Expand Down
2 changes: 1 addition & 1 deletion source/src/enet_encap/networkhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
EipStatus NetworkHandlerInitialize();

EipStatus NetworkHandlerProcessOnce();
EipStatus NetworkHandlerProcessOnce(int timeoutInSeconds = 0);

EipStatus NetworkHandlerFinish();

Expand Down