Date: Monday, January 29, 2007 @ 17:46:36
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: GNUmakefile (1.24 -> 1.25) include/DriverSocket.hpp (1.19 ->
          1.20) include/JavaSocket.hpp (1.43 -> 1.44) src/JavaSocket.cpp
          (1.86 -> 1.87)

Use of new buffered socket
The buffering implies a lot less system calls. Buffering the writes fixes 
CAROB-123


--------------------------+
 GNUmakefile              |    1 +
 include/DriverSocket.hpp |    5 +++--
 include/JavaSocket.hpp   |   25 +++++++++++--------------
 src/JavaSocket.cpp       |   12 ++++++------
 4 files changed, 21 insertions(+), 22 deletions(-)


Index: carob/GNUmakefile
diff -u carob/GNUmakefile:1.24 carob/GNUmakefile:1.25
--- carob/GNUmakefile:1.24      Mon Jan 22 17:02:42 2007
+++ carob/GNUmakefile   Mon Jan 29 17:46:36 2007
@@ -54,6 +54,7 @@
 #Carob C++ lib
 OBJS                    = ${SRCDIR}/Common.o\
                           ${SRCDIR}/JavaSocket.o\
+                          ${SRCDIR}/BufferedSocket.o\
                           ${SRCDIR}/DriverSocket.o\
                           ${SRCDIR}/CarobException.o\
                           ${SRCDIR}/SocketAddress.o\
Index: carob/include/DriverSocket.hpp
diff -u carob/include/DriverSocket.hpp:1.19 carob/include/DriverSocket.hpp:1.20
--- carob/include/DriverSocket.hpp:1.19 Wed Jan 17 17:23:31 2007
+++ carob/include/DriverSocket.hpp      Mon Jan 29 17:46:36 2007
@@ -23,6 +23,7 @@
 #define _DRIVERSOCKET_H_
 
 #include "JavaSocket.hpp"
+#include "BufferedSocket.hpp"
 
 namespace CarobNS {
 
@@ -35,14 +36,14 @@
  * Defines handy methods to read/write to/from a controller following
  * the controller/driver communication protocol.
  */
-class DriverSocket : public JavaSocket
+class DriverSocket : public BufferedSocket
 {
 public:
   /**
    * Empty constructor
    * @throws ConnectionException if the connection fails
    */
-  DriverSocket() throw (CodecException, UnexpectedException) : JavaSocket() {}
+  DriverSocket() throw (CodecException, UnexpectedException) : 
BufferedSocket() {}
 
   /**
    * Writes a string to the socket according to the controller protocol
Index: carob/include/JavaSocket.hpp
diff -u carob/include/JavaSocket.hpp:1.43 carob/include/JavaSocket.hpp:1.44
--- carob/include/JavaSocket.hpp:1.43   Thu Jan 25 16:30:47 2007
+++ carob/include/JavaSocket.hpp        Mon Jan 29 17:46:36 2007
@@ -19,8 +19,8 @@
  * Contributor(s): Zsolt Simon, Marc Herbert
  */
 
-#ifndef SOCKET_H_
-#define SOCKET_H_
+#ifndef _JAVA_SOCKET_H_
+#define _JAVA_SOCKET_H_
 
 #include "SocketAddress.hpp"
 #include "StringCodecs.hpp"
@@ -186,6 +186,12 @@
    */
   static int    pollOnSingleFd(int socketFd, int pollTimeoutInMs, bool 
pollOnWrites = false);
 protected:
+  /** Socket file descriptor */
+  int                         socket_fd;
+  /** true if the socket is connected to a host */
+  bool                        connected;
+  /** true cancels all input and connections attempts */
+  bool                        canceled;
   /**
    * Substitute for recv. Waits for incomming data by calling pollOnSingleFd
    * and loops until full length has been received or an erro occured. If
@@ -197,7 +203,7 @@
    * @return the total number of bytes send, -1 in case of failure
    * @throw SocketIOException if interrupted by shutdown() function
    */
-  int32_t       recvFully(void *buf, const int len, const int flags)
+  virtual int   recvFully(void *buf, const int len, const int flags)
                     const throw (SocketIOException, UnexpectedException);
   /**
    * Wrapper over send(...) function to handle errors and throw exceptions
@@ -208,7 +214,7 @@
    * @param flags send option, see recv man page
    * @throws SocketIOException
    */
-  void          sendToSocket(const wchar_t fctName[],
+  virtual void  sendToSocket(const wchar_t fctName[],
                     const std::wstring& objName, const void* buf, int len,
                     int flags) const throw (SocketIOException,
                     UnexpectedException);
@@ -228,14 +234,6 @@
 
 private:
   const CarobNS::StringCodec& utf8_codec;
-
-  /** Socket file descriptor */
-  int           socket_fd;
-  /** true if the socket is connected to a host */
-  bool          connected;
-  /** true cancels all input and connections attempts */
-  bool          canceled;
-
   /**
    * Sets the socket to desired blocking mode
    * 
@@ -245,8 +243,7 @@
    */
   void          setBlockingMode(const wchar_t fctName[], bool blocking)
                     throw (ConnectionException, UnexpectedException);
-
 };
 
 } //namespace CarobNS
-#endif /*SOCKET_H_*/
+#endif /*_JAVA_SOCKET_H_*/
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.86 carob/src/JavaSocket.cpp:1.87
--- carob/src/JavaSocket.cpp:1.86       Mon Jan 29 16:36:35 2007
+++ carob/src/JavaSocket.cpp    Mon Jan 29 17:46:36 2007
@@ -187,14 +187,14 @@
 
 
 JavaSocket::JavaSocket() throw (CodecException) :
+socket_fd(-1),
+connected(false),
+canceled(false),
 #ifdef CAROB_USE_ICONV // cpp-based factory :-]
-  utf8_codec(*new IconvCodec("UTF-8")),
+  utf8_codec(*new IconvCodec("UTF-8"))
 #else
-  utf8_codec(*new MBSCodec(tryUTF8locale())),
+  utf8_codec(*new MBSCodec(tryUTF8locale()))
 #endif
-socket_fd(-1),
-connected(false),
-canceled(false)
 {
 }
 
@@ -571,7 +571,7 @@
   }
   // We were shutdown()
   if (!connected)
-    throw SocketIOException(L"JavaSocket shut down, read aborted");
+    throw SocketIOException(L"JavaSocket has been shutdown, read aborted");
   return alreadyRead;
 }
 

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

Reply via email to