myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-155-


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-155-g29f2439
Date: Fri, 16 Apr 2010 20:05:23 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  29f2439da0cd2a0d6d4fb4964451990753044d12 (commit)
       via  6d27ff8c9eab02636815ab2eb1adac4a16b40ecd (commit)
      from  f038e6c8e486ce869d0e27f9c9a70ee4c0437a13 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 29f2439da0cd2a0d6d4fb4964451990753044d12
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Apr 16 22:05:21 2010 +0200

    Remove superfluous error checks

diff --git a/myserver/src/base/file/files_utility.cpp 
b/myserver/src/base/file/files_utility.cpp
index e61aa3c..090f111 100644
--- a/myserver/src/base/file/files_utility.cpp
+++ b/myserver/src/base/file/files_utility.cpp
@@ -181,7 +181,6 @@ int FilesUtility::copyFile (File& src, File& dest)
 {
   char buffer[4096];
   u_long nbr, nbw;
-  int ret;
 
 #ifdef HAVE_POSIX_FALLOCATE
   if (posix_fallocate (dest.getHandle (), dest.getSeek (),
@@ -191,34 +190,24 @@ int FilesUtility::copyFile (File& src, File& dest)
 
   for (;;)
   {
-    ret = src.read (buffer, 4096, &nbr);
-    if (ret)
-      return -1;
+    src.read (buffer, 4096, &nbr);
 
     if (!nbr)
       break;
 
-    ret = dest.writeToFile (buffer, nbr, &nbw);
-    if (ret)
-      return -1;
+    dest.writeToFile (buffer, nbr, &nbw);
   }
   return 0;
 }
 
 /*!
  * Delete an existing file passing the path.
- * Return a non-null value on errors.
  * \param filename The file to delete.
  */
 int FilesUtility::deleteFile (const char *filename)
 {
-  int ret;
-  ret = checked::remove (filename);
-
-  if (ret && errno == ENOENT)
-    ret = 0;
-
-  return ret;
+  checked::remove (filename);
+  return 0;
 }
 
 /*!
@@ -227,20 +216,9 @@ int FilesUtility::deleteFile (const char *filename)
  */
 int FilesUtility::isDirectory (const char *filename)
 {
-#ifdef WIN32
-  u_long fa = GetFileAttributes (filename);
-  if (fa != INVALID_FILE_ATTRIBUTES)
-    return (fa & FILE_ATTRIBUTE_DIRECTORY)?1:0;
-  else
-    return 0;
-#else
   struct stat F_Stats;
-  int ret = stat (filename, &F_Stats);
-  if (ret < 0)
-    return 0;
-
-  return (S_ISDIR (F_Stats.st_mode))? 1 : 0;
-#endif
+  checked::stat (filename, &F_Stats);
+  return (S_ISDIR (F_Stats.st_mode)) ? 1 : 0;
 }
 
 /*!
@@ -253,10 +231,7 @@ int FilesUtility::isLink (const char* filename)
   return 0;
 #else
   struct stat F_Stats;
-  int ret = checked::lstat (filename, &F_Stats);
-  if (ret < 0)
-    return 0;
-
+  checked::lstat (filename, &F_Stats);
   return S_ISLNK (F_Stats.st_mode) ? 1 : 0;
 #endif
 
@@ -268,22 +243,17 @@ int FilesUtility::isLink (const char* filename)
  */
 int FilesUtility::nodeExists (const char* filename)
 {
-#ifdef WIN32
-  HANDLE hFile = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ,
-                             NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL
-                             | FILE_FLAG_BACKUP_SEMANTICS, NULL);
-
-  int nRet = (hFile != INVALID_HANDLE_VALUE) ? 1 : 0;
-  CloseHandle (hFile);
-  return nRet;
-#else
   struct stat fstats;
-  int ret = stat (filename, &fstats);
-  if (ret < 0)
-    return 0;
+  try
+    {
+      checked::stat (filename, &fstats);
+    }
+  catch (...)
+    {
+      return 0;
+    }
 
   return 1;
-#endif
 }
 
 /*!
@@ -294,13 +264,8 @@ int FilesUtility::nodeExists (const char* filename)
 time_t FilesUtility::getLastModTime (const char *filename)
 {
   int res;
-#ifdef WIN32
-  struct _stat sf;
-  res = _stat (filename, &sf);
-#else
   struct stat sf;
   res = stat (filename,&sf);
-#endif
 
   if (res == 0)
     return sf.st_mtime;
@@ -316,13 +281,9 @@ time_t FilesUtility::getLastModTime (const char *filename)
 time_t FilesUtility::getCreationTime (const char *filename)
 {
   int res;
-#ifdef WIN32
-  struct _stat sf;
-  res = _stat (filename, &sf);
-#else
   struct stat sf;
   res = stat (filename, &sf);
-#endif
+
   if (res == 0)
     return sf.st_ctime;
   else
@@ -337,13 +298,8 @@ time_t FilesUtility::getCreationTime (const char *filename)
 time_t FilesUtility::getLastAccTime (const char *filename)
 {
   int res;
-#ifdef WIN32
-  struct _stat sf;
-  res = _stat (filename, &sf);
-#else
   struct stat sf;
   res = stat (filename, &sf);
-#endif
   if (res == 0)
     return sf.st_atime;
   else
diff --git a/myserver/src/base/socket/socket.cpp 
b/myserver/src/base/socket/socket.cpp
index a520b8d..c1b6ec2 100644
--- a/myserver/src/base/socket/socket.cpp
+++ b/myserver/src/base/socket/socket.cpp
@@ -344,26 +344,21 @@ int Socket::send (const char* buffer, int len, int flags)
   {
     while (1)
       {
-        /*! When we can send data again?  */
+        /* When we can send data again?  */
         u_long time = getTicks () + (1000 * 1024 / throttlingRate) ;
-        /*! If a throttling rate is specified, send chunks of 1024 bytes.  */
+        /* If a throttling rate is specified, send chunks of 1024 bytes.  */
         ret = rawSend (buffer + (len - toSend), toSend < 1024 ?
                        toSend : 1024, flags);
-        /*! On errors returns directly -1.  */
-        if (ret < 0)
-          return -1;
+
         toSend -= (u_long) ret;
-        /*!
-         *If there are other bytes to send wait before cycle again.
-         */
+
+        /* If there are other bytes to send wait before cycle again.  */
         if (toSend)
-          {
-            Thread::wait (getTicks () - time);
-          }
+          Thread::wait (getTicks () - time);
         else
           break;
       }
-    /*! Return the number of sent bytes. */
+    /* Return the number of sent bytes.  */
     return len - toSend;
   }
   return 0;
@@ -532,9 +527,6 @@ int Socket::recv (char* buffer, int len, int flags, u_long 
timeout)
 {
   int ret = dataAvailable (timeout / 1000, timeout % 1000);
 
-  if (ret < 0)
-    return ret;
-
   if (ret)
     return recv (buffer, len, flags);
 
@@ -665,7 +657,7 @@ int Socket::dataAvailable (int sec, int usec)
   FD_SET (fd, &readfds);
 
   ret = checked::select (fd + 1, &readfds, NULL, NULL, &tv);
-  if (ret <= 0)
+  if (ret == 0)
     return 0;
 
   if (FD_ISSET (fd, &readfds))
@@ -680,11 +672,7 @@ int Socket::dataAvailable (int sec, int usec)
  */
 int Socket::read (char* buffer, u_long len, u_long *nbr)
 {
-  int ret = recv (buffer, len, 0);
-  if (ret < 0)
-    return ret;
-
-  *nbr = static_cast<u_long> (ret);
+  *nbr = static_cast<u_long> (recv (buffer, len, 0));
   return 0;
 }
 
@@ -694,10 +682,6 @@ int Socket::read (char* buffer, u_long len, u_long *nbr)
  */
 int Socket::write (const char* buffer, u_long len, u_long *nbw)
 {
-  int ret = send (buffer, len, 0);
-  if (ret < 0)
-    return ret;
-
-  *nbw = static_cast<u_long> (ret);
+  *nbw = static_cast<u_long> (send (buffer, len, 0));
   return 0;
 }
diff --git a/myserver/src/base/sync/event.cpp b/myserver/src/base/sync/event.cpp
index 780f3a8..f44d0c5 100644
--- a/myserver/src/base/sync/event.cpp
+++ b/myserver/src/base/sync/event.cpp
@@ -64,10 +64,10 @@ int Event::init (bool broadcast)
 {
   int ret = 0;
   if (initialized)
-  {
-    destroy ();
-    initialized = false;
-  }
+    {
+      destroy ();
+      initialized = false;
+    }
   this->broadcast = broadcast;
 #ifdef HAVE_PTHREAD
   ret = pthread_mutex_init (&mutex,(pthread_mutexattr_t*) NULL);
diff --git a/myserver/src/base/utility.cpp b/myserver/src/base/utility.cpp
index 5df6d69..45c42b1 100644
--- a/myserver/src/base/utility.cpp
+++ b/myserver/src/base/utility.cpp
@@ -231,7 +231,6 @@ int readFileHandle (SocketHandle s, Handle* fd)
   } cmh;
   char tbuf[4];
   struct iovec iov;
-  int ret;
   struct cmsghdr *cmsg;
 
   memset (&mh, 0, sizeof (mh));
@@ -242,10 +241,8 @@ int readFileHandle (SocketHandle s, Handle* fd)
   iov.iov_base = tbuf;
   iov.iov_len = 4;
 
-  ret = recvmsg (s, &mh, 0);
-  if (ret < 0)
-    return ret;
-
+  /* FIXME:  add recvmsg to checked.  */
+  checked::checkError (recvmsg (s, &mh, 0));
   cmsg = CMSG_FIRSTHDR (&mh);
   *fd = *((int *) CMSG_DATA (cmsg));
   return 0;
@@ -285,8 +282,9 @@ int writeFileHandle (SocketHandle s, Handle fd)
   cmsg->cmsg_len = CMSG_LEN (sizeof (int));
   cmsg->cmsg_level = SOL_SOCKET;
   cmsg->cmsg_type = SCM_RIGHTS;
-  *(int *)CMSG_DATA (cmsg) = fd;
+  *(int *) CMSG_DATA (cmsg) = fd;
 
-  return sendmsg (s, &mh, 0);
+  /* FIXME: add sendmsg to checked.  */
+  return checked::checkError (sendmsg (s, &mh, 0));
 #endif
 }
diff --git a/myserver/src/filter/gzip/gzip.cpp 
b/myserver/src/filter/gzip/gzip.cpp
index 8f8fdc5..021f2d1 100644
--- a/myserver/src/filter/gzip/gzip.cpp
+++ b/myserver/src/filter/gzip/gzip.cpp
@@ -263,26 +263,26 @@ u_long Gzip::getHeader (char *buffer,u_long buffersize)
 int Gzip::read (char* buffer, u_long len, u_long *nbr)
 {
   char *tmp_buff;
-  int ret;
   u_long nbr_parent;
   if (!parent)
     return -1;
-  tmp_buff = new char[len/2];
-  if (!tmp_buff)
-    return -1;
 
   if (!active)
     return parent->read (buffer, len, nbr);
 
-  ret = parent->read (tmp_buff, len/2, &nbr_parent);
+  tmp_buff = new char[len/2];
 
-  if (ret == -1)
+  try
+    {
+      parent->read (tmp_buff, len/2, &nbr_parent);
+      *nbr = compress (tmp_buff, nbr_parent, buffer, len);
+    }
+  catch (...)
     {
       delete [] tmp_buff;
-      return -1;
+      throw;
     }
 
-  *nbr = compress (tmp_buff, nbr_parent, buffer, len);
   delete [] tmp_buff;
   return 0;
 }
@@ -310,10 +310,10 @@ int Gzip::write (const char* buffer, u_long len, u_long 
*nbw)
     {
       u_long nbw_parent;
       u_long size=std::min (len, 512UL);
-      u_long ret=compress (buffer, size, tmpBuffer, 1024);
+      u_long ret = compress (buffer, size, tmpBuffer, 1024);
 
-      if (ret && parent->write (tmpBuffer, ret, &nbw_parent) == -1)
-        return -1;
+      if (ret)
+        parent->write (tmpBuffer, ret, &nbw_parent);
 
       written += ret;
       buffer += size;
@@ -341,10 +341,9 @@ int Gzip::flush (u_long *nbw)
       u_long nbwParentFlush;
       if (!parent)
         return -1;
-      if (parent->write (buffer, *nbw, &nbwParent) != 0)
-        return -1;
-      if (parent->flush (&nbwParentFlush) != 0)
-        return -1;
+
+      parent->write (buffer, *nbw, &nbwParent);
+      parent->flush (&nbwParentFlush);
       *nbw = nbwParentFlush + nbwParent;
     }
   return 0;
diff --git a/myserver/src/filter/gzip/gzip_decompress.cpp 
b/myserver/src/filter/gzip/gzip_decompress.cpp
index 4cb69c8..4fef3b2 100644
--- a/myserver/src/filter/gzip/gzip_decompress.cpp
+++ b/myserver/src/filter/gzip/gzip_decompress.cpp
@@ -89,7 +89,6 @@ u_long GzipDecompress::free ()
 {
   u_long ret = 0;
 #ifdef HAVE_ZLIB
-
   if (data.initialized == 0)
     return 0;
   data.initialized = 0;
@@ -217,22 +216,22 @@ int GzipDecompress::read (char* buffer, u_long len, 
u_long *nbr)
   u_long nbr_parent;
   if (!parent)
     return -1;
-  tmp_buff = new char[len/2];
-  if (!tmp_buff)
-    return -1;
 
   if (!active)
     return parent->read (buffer, len, nbr);
 
-  ret = parent->read (tmp_buff, len/2, &nbr_parent);
-
-  if (ret == -1)
+  tmp_buff = new char[len/2];
+  try
+    {
+      parent->read (tmp_buff, len/2, &nbr_parent);
+      *nbr = decompress (tmp_buff, nbr_parent, buffer, len);
+    }
+  catch (...)
     {
       delete [] tmp_buff;
-      return -1;
+      throw;
     }
 
-  *nbr = decompress (tmp_buff, nbr_parent, buffer, len);
 
   delete [] tmp_buff;
   return 0;



commit 6d27ff8c9eab02636815ab2eb1adac4a16b40ecd
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Apr 16 21:43:29 2010 +0200

    Add stat to the checked namespace

diff --git a/myserver/include/base/exceptions/checked.h 
b/myserver/include/base/exceptions/checked.h
index 4ceb64a..982a2a5 100644
--- a/myserver/include/base/exceptions/checked.h
+++ b/myserver/include/base/exceptions/checked.h
@@ -87,6 +87,7 @@ namespace checked
   int dup (int oldfd);
   int dup2 (int oldfd, int newfd);
   int pipe2 (int pipefd[2], int flags);
+  int stat(const char *path, struct stat *buf);
   int fstat (int fd, struct stat *buf);
   int fstatat (int fd, char const *name, struct stat *st, int flags);
   char *getcwd (char *buf, size_t size);
diff --git a/myserver/src/base/exceptions/checked.cpp 
b/myserver/src/base/exceptions/checked.cpp
index e63d866..f5f0a27 100644
--- a/myserver/src/base/exceptions/checked.cpp
+++ b/myserver/src/base/exceptions/checked.cpp
@@ -86,6 +86,11 @@ namespace checked
     return checkError (gnulib::gethostname (name, len));
   }
 
+  int stat (const char *path, struct stat *buf)
+  {
+    return checkError (::stat (path, buf));
+  }
+
   int getsockname (int fd, struct sockaddr *addr, socklen_t *addrlen)
   {
     return checkError (gnulib::getsockname (fd, addr, addrlen));

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/base/exceptions/checked.h   |    1 +
 myserver/src/base/exceptions/checked.cpp     |    5 ++
 myserver/src/base/file/files_utility.cpp     |   76 ++++++--------------------
 myserver/src/base/socket/socket.cpp          |   36 ++++---------
 myserver/src/base/sync/event.cpp             |    8 ++--
 myserver/src/base/utility.cpp                |   12 ++---
 myserver/src/filter/gzip/gzip.cpp            |   29 +++++-----
 myserver/src/filter/gzip/gzip_decompress.cpp |   17 +++---
 8 files changed, 63 insertions(+), 121 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]