• R/O
  • SSH
  • HTTPS

tidesnet: Commit


Commit MetaInfo

Revision16 (tree)
Time2018-08-11 13:54:07
Authorquiret

Log Message

- fixed some stuff
- added a helper

Change Summary

Incremental Difference

--- library/include/tidesnet/netsocket.h (revision 15)
+++ library/include/tidesnet/netsocket.h (revision 16)
@@ -120,6 +120,29 @@
120120 virtual TidesNet* GetNetManager( void ) = 0;
121121 };
122122
123+// Helpers.
124+namespace SocketHelpers
125+{
126+ // This is a helpful function for gracefully quitting a socket.
127+ // Since ShutdownWrites does send a FIN message to the other side, we can
128+ // actually wait for it this way. It is safer to get a read with zero count
129+ // than to vehemently close the socket.
130+ inline void ReadSocketTillEnd( TidesNetwork::NetSocket *socket )
131+ {
132+ char buf_tmp[ 0x1000 ];
133+
134+ while ( true )
135+ {
136+ size_t readCount = socket->Read( buf_tmp, sizeof(buf_tmp) );
137+
138+ if ( readCount == 0 )
139+ {
140+ break;
141+ }
142+ }
143+ }
144+};
145+
123146 // Connection receiver class that dispatches client connections to our server.
124147 // This is also called a "server socket" in many other APIs, but we would like
125148 // to make clear that this is just the initiator of a connection, not the tunnel
--- library/src/mbedtls.cpp (revision 15)
+++ library/src/mbedtls.cpp (revision 16)
@@ -181,6 +181,16 @@
181181 return socket->GetFamily();
182182 }
183183
184+ bool GetIPV4( ipdescIPV4& descOut ) const override
185+ {
186+ return socket->GetIPV4( descOut );
187+ }
188+
189+ bool GetIPV6( ipdescIPV6& descOut ) const override
190+ {
191+ return socket->GetIPV6( descOut );
192+ }
193+
184194 void Close( void ) override
185195 {
186196 socket->Close();
--- library/src/netsocket.cpp (revision 15)
+++ library/src/netsocket.cpp (revision 16)
@@ -333,6 +333,14 @@
333333 return nullptr;
334334 }
335335
336+ // Set important properties.
337+ LINGER linger;
338+ linger.l_onoff = 1;
339+ linger.l_linger = 30;
340+ int error = setsockopt( acceptedSysSocket, SOL_SOCKET, SO_LINGER, (const char*)&linger, sizeof(linger) );
341+
342+ assert( error == 0 );
343+
336344 // Turn it into a runtime object.
337345 TidesNetImpl *nativeNetMan = (TidesNetImpl*)nativeListener->netMan;
338346
Show on old repository browser