• R/O
  • SSH
  • HTTPS

tidesnet: Commit


Commit MetaInfo

Revision82 (tree)
Time2020-04-30 17:03:43
Authorquiret

Log Message

- adjusted code to use the new TRANSFORM_INT_CLAMP function instead of an internal helper

Change Summary

Incremental Difference

--- library/src/netsocket.cpp (revision 81)
+++ library/src/netsocket.cpp (revision 82)
@@ -15,6 +15,7 @@
1515 #include "tidesdef.hxx"
1616
1717 #include <sdk/PluginHelpers.h>
18+#include <sdk/MemoryRaw.h>
1819
1920 #ifdef __linux__
2021 #include <sys/time.h>
@@ -65,20 +66,6 @@
6566 // Factories of the connection classes.
6667 connReceivFact_t connReceivFact;
6768
68-// Safe unsigned number truncation logic to primUnsignedType.
69-template <typename primUnsignedType, typename secUnsignedType>
70-AINLINE primUnsignedType truncate_number( secUnsignedType sec )
71-{
72- primUnsignedType max_val = std::numeric_limits <primUnsignedType>::max();
73-
74- if ( sec > max_val )
75- {
76- return max_val;
77- }
78-
79- return (primUnsignedType)sec;
80-}
81-
8269 // We put those functions into the internal object because there can be data channel contexts attached
8370 // to a socket and they'd pipe data in special ways.
8471 size_t NetSocketImpl::WriteInternal( const void *memBuf, size_t writeSize )
@@ -98,7 +85,7 @@
9885 }
9986
10087 // We can only send up to an unsigned long.
101- ULONG sys_max_send_size = truncate_number <ULONG> ( writeSize );
88+ ULONG sys_max_send_size = TRANSFORM_INT_CLAMP <ULONG> ( writeSize );
10289
10390 SOCKET sysSocket = nativeSocket->transportSocket;
10491
@@ -141,7 +128,7 @@
141128
142129 // Need to truncate because Linux does not support writing greater than
143130 // SSIZE_MAX bytes.
144- size_t truncWriteCount = std::min( (size_t)std::numeric_limits <ssize_t>::max(), writeSize );
131+ size_t truncWriteCount = (size_t)TRANSFORM_INT_CLAMP <ssize_t> ( writeSize );
145132
146133 ssize_t writtenCount = write( sysSocket, memBuf, truncWriteCount );
147134
@@ -182,7 +169,7 @@
182169 SOCKET sysSocket = nativeSocket->transportSocket;
183170
184171 // Truncate the number.
185- ULONG sys_max_recv_size = truncate_number <ULONG> ( readCount );
172+ ULONG sys_max_recv_size = TRANSFORM_INT_CLAMP <ULONG> ( readCount );
186173
187174 // We use WSARecv instead of Unix recv because it is more robust.
188175 WSABUF recvbuf;
@@ -244,7 +231,7 @@
244231 int sysSocket = nativeSocket->socketFD;
245232
246233 // Need to truncate the number.
247- size_t truncReadCount = std::min( (size_t)std::numeric_limits <ssize_t>::max(), readCount );
234+ size_t truncReadCount = (size_t)TRANSFORM_INT_CLAMP <ssize_t> ( readCount );
248235
249236 int recv_flags = 0;
250237
--- unittest/src/network_tests.cpp (revision 81)
+++ unittest/src/network_tests.cpp (revision 82)
@@ -192,7 +192,7 @@
192192 {
193193 using namespace TidesNetwork;
194194
195- printf( "testing remote hostname resolution..." );
195+ printf( "testing remote hostname resolution:\n" );
196196 {
197197 // Test IPV4.
198198 {
@@ -207,10 +207,13 @@
207207 // WARNING: not all networks seem to support IPV6 anyway.
208208 ipdescIPV6 resolved;
209209
210- assert( netMan->ResolveHostnameIPV6( "google.com", resolved ) == true );
210+ if ( netMan->ResolveHostnameIPV6( "google.com", resolved ) == false )
211+ {
212+ printf( "failed to find google.com IPV6 address\n" );
213+ }
211214 }
212215 }
213- printf( "ok.\n" );
216+ printf( "finished.\n" );
214217 }
215218
216219 void DO_NETWORK_TEST( void )
Show on old repository browser