Date: Wednesday, February 14, 2007 @ 17:39:29
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/BufferedSocket.hpp (1.4 -> 1.5) include/JavaSocket.hpp
          (1.45 -> 1.46) src/BufferedSocket.cpp (1.7 -> 1.8)
          src/JavaSocket.cpp (1.89 -> 1.90)

Removed objName argument from sendToSocket() and receiveFromSocket() functions, 
which was leading to huge amount of wstring creations/destruction, while 
bringing nothing more than fctName argument
Partial, but bigger part, fix for CAROB-127


----------------------------+
 include/BufferedSocket.hpp |    7 +++----
 include/JavaSocket.hpp     |    7 +++----
 src/BufferedSocket.cpp     |    4 ++--
 src/JavaSocket.cpp         |   41 ++++++++++++++++++++---------------------
 4 files changed, 28 insertions(+), 31 deletions(-)


Index: carob/include/BufferedSocket.hpp
diff -u carob/include/BufferedSocket.hpp:1.4 
carob/include/BufferedSocket.hpp:1.5
--- carob/include/BufferedSocket.hpp:1.4        Tue Jan 30 16:43:55 2007
+++ carob/include/BufferedSocket.hpp    Wed Feb 14 17:39:29 2007
@@ -125,8 +125,8 @@
    * Wrapper over send(...) function to buffer output data and handle 
errors.<br>
    * Data is only sent to the socket when the buffer is full or when a read
    * operation is requested.
+   *
    * @param fctName name of the calling function (for logging purposes)
-   * @param objName name of the object to be send (for logging purposes)
    * @param buf data to be send
    * @param len length of buf
    * @param flags send option, see recv man page
@@ -134,9 +134,8 @@
    * @see #recvFully(void *, const int, const int) const
    */
   void                sendToSocket(const wchar_t fctName[],
-                          const std::wstring& objName, const void* buf, int 
len,
-                          int flags) const throw (SocketIOException,
-                          UnexpectedException);
+                          const void* buf, int len, int flags) const
+                          throw (SocketIOException, UnexpectedException);
 private:
   /**
    * Buffer in which data read from the network is stored.<br>
Index: carob/include/JavaSocket.hpp
diff -u carob/include/JavaSocket.hpp:1.45 carob/include/JavaSocket.hpp:1.46
--- carob/include/JavaSocket.hpp:1.45   Tue Feb  6 18:52:29 2007
+++ carob/include/JavaSocket.hpp        Wed Feb 14 17:39:29 2007
@@ -207,28 +207,27 @@
                     const throw (SocketIOException, UnexpectedException);
   /**
    * Wrapper over send(...) function to handle errors and throw exceptions
+   *
    * @param fctName name of the calling function (for logging purposes)
-   * @param objName name of the object to be send (for logging purposes)
    * @param buf data to be send
    * @param len length of buf
    * @param flags send option, see recv man page
    * @throws SocketIOException
    */
   virtual void  sendToSocket(const wchar_t fctName[],
-                    const std::wstring& objName, const void* buf, int len,
+                    const void* buf, int len,
                     int flags) const throw (SocketIOException,
                     UnexpectedException);
   /**
    * Wrapper around recv(...) function to handle errors and throw exceptions
+   *
    * @param fctName name of the calling function (for logging purposes)
-   * @param objName name of the object to be send (for logging purposes)
    * @param buf buffer in which to put the received data in
    * @param len length of buf
    * @param flags send option, see send man page
    * @throws SocketIOException in case of error
    */
   void          receiveFromSocket(const wchar_t fctName[],
-                    const std::wstring& objName, 
                     void *buf, int len, int flags)
                     const throw (SocketIOException, UnexpectedException);
 
Index: carob/src/BufferedSocket.cpp
diff -u carob/src/BufferedSocket.cpp:1.7 carob/src/BufferedSocket.cpp:1.8
--- carob/src/BufferedSocket.cpp:1.7    Tue Jan 30 16:43:55 2007
+++ carob/src/BufferedSocket.cpp        Wed Feb 14 17:39:29 2007
@@ -102,7 +102,7 @@
   return readThisTime;
 }
 
-void BufferedSocket::sendToSocket(const wchar_t fctName[], const std::wstring& 
objName,
+void BufferedSocket::sendToSocket(const wchar_t fctName[],
     const void* buf, int len, int flags) const
     throw (SocketIOException, UnexpectedException)
 {
@@ -116,7 +116,7 @@
   { // Caching so big data would cost:
     // 1. more system calls 2. memcpy() cost
     // => just don't do cache.
-    JavaSocket::sendToSocket(fctName, objName, buf, len, flags);
+    JavaSocket::sendToSocket(fctName, buf, len, flags);
     return;
   }
 
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.89 carob/src/JavaSocket.cpp:1.90
--- carob/src/JavaSocket.cpp:1.89       Tue Feb  6 18:52:29 2007
+++ carob/src/JavaSocket.cpp    Wed Feb 14 17:39:29 2007
@@ -398,8 +398,8 @@
   int32_t netlen = htonl(utf8str.length());
 
   // First write number of bytes to follow as
-  sendToSocket(fctName, L"UTF string", &netlen, sizeof(netlen), 
SOCKET_SEND_FLAGS);
-  sendToSocket(fctName, L"UTF string", utf8str.data(), utf8str.length(), 
SOCKET_SEND_FLAGS);
+  sendToSocket(fctName, &netlen, sizeof(netlen), SOCKET_SEND_FLAGS);
+  sendToSocket(fctName, utf8str.data(), utf8str.length(), SOCKET_SEND_FLAGS);
 
   return utf8str.length();
 }
@@ -414,11 +414,11 @@
   uint16_t lenRec;
   size_t sizeRead = 0;
   //First get size
-  receiveFromSocket(fctName, L"UTF string size", &lenRecNet, 
sizeof(lenRecNet), 0);
+  receiveFromSocket(fctName, &lenRecNet, sizeof(lenRecNet), 0);
   lenRec = ntohl(lenRecNet); // number of bytes to come
 
   uint8_t* utfStr = new uint8_t[lenRec];
-  receiveFromSocket(fctName, L"UTF string", utfStr, lenRec, 0);
+  receiveFromSocket(fctName, utfStr, lenRec, 0);
   const std::string received(reinterpret_cast<char*>(utfStr), lenRec);
 
   try
@@ -444,7 +444,7 @@
   const wchar_t fctName[] = L"JavaSocket::WriteInt32";
   // we have to convert the byte order
   int32_t conv = htonl(i);
-  sendToSocket(fctName, L"Int32", &conv, sizeof(conv), SOCKET_SEND_FLAGS);
+  sendToSocket(fctName, &conv, sizeof(conv), SOCKET_SEND_FLAGS);
 }
 
 void JavaSocket::readJavaInt(int32_t& i) const throw (SocketIOException,
@@ -455,7 +455,7 @@
   // so we must convert it after reception
   int32_t rec = 0;
 
-  receiveFromSocket(fctName, L"Int32", &rec, sizeof(rec), 0);
+  receiveFromSocket(fctName, &rec, sizeof(rec), 0);
   i = ntohl(rec);
 }
 
@@ -465,7 +465,7 @@
   const wchar_t fctName[] = L"JavaSocket::writeJavaLong";
   // we have to convert the byte order
   int64_t conv = htonll(i);
-  sendToSocket(fctName, L"Int64", &conv, sizeof(conv), SOCKET_SEND_FLAGS);
+  sendToSocket(fctName, &conv, sizeof(conv), SOCKET_SEND_FLAGS);
 }
 
 void JavaSocket::readJavaLong(int64_t& i) const throw (SocketIOException,
@@ -476,7 +476,7 @@
   // so we must convert it after reception
   int64_t rec = 0;
 
-  receiveFromSocket(fctName, L"Int64", &rec, sizeof(rec), 0);
+  receiveFromSocket(fctName, &rec, sizeof(rec), 0);
   i = ntohll(rec);
 }
 
@@ -487,7 +487,7 @@
   uint8_t byteToSend = b; // the implicit casts do it right
   //No byte order problem here: the only value read is '0' for false
   //all other values are true
-  sendToSocket(fctName, L"Boolean", &byteToSend, sizeof(byteToSend), 
SOCKET_SEND_FLAGS);
+  sendToSocket(fctName, &byteToSend, sizeof(byteToSend), SOCKET_SEND_FLAGS);
 }
 
 void JavaSocket::readJavaBool(bool& b) const throw (SocketIOException,
@@ -496,7 +496,7 @@
   const wchar_t fctName[] = L"JavaSocket::readJavaBool";
 
   uint8_t rec;
-  receiveFromSocket(fctName, L"Boolean", &rec, sizeof(rec), 0);
+  receiveFromSocket(fctName, &rec, sizeof(rec), 0);
   b = rec; // the implicit cast does it right
 }
 
@@ -504,14 +504,14 @@
     throw (SocketIOException, UnexpectedException)
 {
   const wchar_t fctName[] = L"JavaSocket::readJavaBytes";
-  receiveFromSocket(fctName, L"JavaBytes", data, length, 0);
+  receiveFromSocket(fctName, data, length, 0);
 }
 
 void JavaSocket::writeJavaBytes(int32_t length, java_byte* data) const
     throw (SocketIOException, UnexpectedException)
 {
   const wchar_t fctName[] = L"JavaSocket::writeJavaBytes";
-  sendToSocket(fctName, L"JavaBytes", data, length, SOCKET_SEND_FLAGS);
+  sendToSocket(fctName, data, length, SOCKET_SEND_FLAGS);
 }
 
 /* static */
@@ -585,7 +585,7 @@
   return alreadyRead;
 }
 
-void JavaSocket::sendToSocket(const wchar_t fctName[], const wstring& objName,
+void JavaSocket::sendToSocket(const wchar_t fctName[],
     const void* buf, int len, int flags) const
     throw (SocketIOException, UnexpectedException)
 {
@@ -594,20 +594,19 @@
   int ret = send(socket_fd, static_cast<const char*>(buf), len, flags);
   if ( ret == -1 )
   {
-    throw SocketIOException(std::wstring(L"(") + fctName + L"): could not 
write "
-        + objName + L" to socket");
+    throw SocketIOException(std::wstring(L"(") + fctName + L"): could not 
write"
+        L" data to socket");
   }
   if (ret != len)
   {
     // should never happen
     throw SocketIOException(std::wstring(L"(") + fctName + L"): only " + 
toUserString(ret)
-        + L"/" + toUserString(len) + L" bytes send while sending " + objName
-        + L" to socket");
+        + L"/" + toUserString(len) + L" bytes send while sending data to 
socket");
   }
 }
 
 void JavaSocket::receiveFromSocket(const wchar_t fctName[],
-    const wstring& objName, void *buf, int len, int flags) const
+    void *buf, int len, int flags) const
     throw (SocketIOException, UnexpectedException)
 {
   if (0 == len)
@@ -616,14 +615,14 @@
   int status = recvFully(buf, len, flags);
 
   if (status == -1)
-    throw SocketIOException(std::wstring(fctName) + L"Could not read from 
socket.");
+    throw SocketIOException(std::wstring(L"(") + fctName + L"): Could not read 
from socket.");
 
   if (status == 0)
-    throw SocketIOException(std::wstring(fctName) + L"Peer reset connection 
while receiving");
+    throw SocketIOException(std::wstring(L"(") + fctName + L"): Peer reset 
connection while receiving");
 
   // else it went fine
   // if (status != len)
-  //  throw SocketIOException(fctName + L"something is really wrong!");
+  //  throw SocketIOException(std::wstring(L"(") + fctName + L"): something is 
really wrong!");
 }
 
 void JavaSocket::setBlockingMode(const wchar_t fctName[], bool blocking)

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to