The function 'Socket::ioctlsocket' isn't tested, but it is used internally
by 'Socket::bytesToRead', so if there are problems the test case should
be able to catch them. Well, there are some more functions that aren't
tested, but they are trivial...

The patch is for base/socket/socket.cpp . It makes 'Socket::write' similiar
to 'Socket::read' in that that now they both change the expected
read/write values in nbr/nbw, which may be -1 if error. Previously, only
'Socket::read' did that.


Here are some notes:

In socket.cpp u_long Socket::bytesToRead -- should the macro #ifdef FIONHEAD
be changed to #ifdef WIN32 ?

In socket.cpp int Socket::recv ( char*, int, int, u_long ) -- how does a
caller distinguish between orderly shutdown and the returned 0 at the end?
If there's a timeout and no sockets are ready, then also value of 0 is
returned again.

In socket.cpp int Socket::recv ( char*, int, int ) -- i thought that the
value of 0 returned by recv is not an error. Or is it the desired behaviour
to be to always handle anything but > 0  values, as errors ? ( "unless
data was recv()`ed, it's an error - do something" )
Index: ../../base/socket/socket.cpp
===================================================================
--- ../../base/socket/socket.cpp        (revision 3035)
+++ ../../base/socket/socket.cpp        (working copy)
@@ -780,7 +780,7 @@
 
 /*!
  *Inherited from Stream.
- *Return zero on success.
+ *Return zero on success, or -1 error. Also sets nbr to -1 if error.
  */
 int Socket::read(char* buffer, u_long len, u_long *nbr)
 {
@@ -794,16 +794,14 @@
 
 /*!
  *Inherited from Stream.
- *Return values are equals to send.
+ *Return zero on success, or -1 on error. Also sets nbw to -1 if error.
  */
 int Socket::write(const char* buffer, u_long len, u_long *nbw)
 {
-  int ret = send(buffer, len, 0);
-
-  if(ret == -1)
+  *nbw = static_cast<u_long>(send(buffer, len, 0));
+  
+  if ( *nbw == static_cast<u_long>(-1) )
     return -1;
 
-  *nbw = static_cast<u_long>(ret);
-
   return 0;
 }

Attachment: test_socket.cpp.gz
Description: GNU Zip compressed data

Reply via email to