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-10-g


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-10-gc382a82
Date: Fri, 19 Feb 2010 10:24:50 +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  c382a8224b8fc000aadb6a7d9f630ff894b62a21 (commit)
       via  bff4636d7c9d71f782a78195e7381be919152d91 (commit)
      from  b5c07e87e944324e3870d63b10115b87d45345f9 (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 c382a8224b8fc000aadb6a7d9f630ff894b62a21
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Feb 19 11:23:33 2010 +0100

    Use 127.0.0.1 instead of localhost to avoid a lookup.

diff --git a/myserver/src/base/process/process_server_manager.cpp 
b/myserver/src/base/process/process_server_manager.cpp
index 13c39b2..cf1618e 100644
--- a/myserver/src/base/process/process_server_manager.cpp
+++ b/myserver/src/base/process/process_server_manager.cpp
@@ -401,7 +401,7 @@ int ProcessServerManager::runServer 
(ProcessServerManager::Server* server,
   MYSERVER_SOCKADDRIN serverSockAddrIn;
   int addrLen = sizeof (serverSockAddrIn);
 
-  server->host.assign ("localhost");
+  server->host.assign ("127.0.0.1");
   server->isLocal = true;
 
   if (nServers >= maxServers)
@@ -461,13 +461,12 @@ int ProcessServerManager::runServer 
(ProcessServerManager::Server* server,
   spi.uid = uid;
   spi.gid = gid;
 
-  if (Process::getForkServer ()->isInitialized ())
+  ForkServer *forkServer = Process::getForkServer ();
+  if (forkServer->isInitialized ())
     {
       int ret, port, pid;
-      ret = Process::getForkServer ()->executeProcess (&spi,
-                                                       
ForkServer::FLAG_STDIN_SOCKET,
-                                                       &pid,
-                                                       &port);
+      ret = forkServer->executeProcess (&spi, ForkServer::FLAG_STDIN_SOCKET,
+                                        &pid, &port);
 
       if (ret == 0)
         {
@@ -500,12 +499,12 @@ int ProcessServerManager::runServer 
(ProcessServerManager::Server* server,
     }
 
   server->DESCRIPTOR.fileHandle = (unsigned long) server->socket.getHandle ();
-  spi.stdIn = (FileHandle)server->DESCRIPTOR.fileHandle;
+  spi.stdIn = (FileHandle) server->DESCRIPTOR.fileHandle;
 
   if (server->socket.getsockname (&serverSockAddrIn, &addrLen))
     return -1;
 
-  server->port = ntohs (((sockaddr_in *)&serverSockAddrIn)->sin_port);
+  server->port = ntohs (((sockaddr_in *) &serverSockAddrIn)->sin_port);
 
   server->process.exec (&spi);
   server->socket.close ();
@@ -525,7 +524,7 @@ int ProcessServerManager::connect (Socket* sock,
   socklen_t nLength = sizeof (MYSERVER_SOCKADDRIN);
 
   if (server->socket.getHandle ())
-    server->socket.getsockname ((MYSERVER_SOCKADDR*)&serverSock, 
(int*)&nLength);
+    server->socket.getsockname ((MYSERVER_SOCKADDR*) &serverSock, (int*) 
&nLength);
 
   if (!serverSock.ss_family || serverSock.ss_family == AF_INET || 
!server->isLocal)
   {
@@ -539,7 +538,6 @@ int ProcessServerManager::connect (Socket* sock,
       sock->close ();
       return -1;
     }
-
   }
 #if ( HAVE_IPV6 && false )/* IPv6 communication not implemented yet by php.  */
   else if ( serverSock.ss_family == AF_INET6 )
@@ -554,7 +552,7 @@ int ProcessServerManager::connect (Socket* sock,
       return -1;
     }
   }
-#endif // HAVE_IPV6
+#endif /* HAVE_IPV6  */
   sock->setNonBlocking (1);
 
   return 0;



commit bff4636d7c9d71f782a78195e7381be919152d91
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Feb 19 10:15:24 2010 +0100

    Add a new mode to open temporary files, TEMPORARY_DELAYED.
    
    When this mode is used, the unlink is done just before the close, thus
    the file is accessible trough the file system during its life.

diff --git a/myserver/include/base/file/file.h 
b/myserver/include/base/file/file.h
index f53abac..016e308 100644
--- a/myserver/include/base/file/file.h
+++ b/myserver/include/base/file/file.h
@@ -34,6 +34,7 @@ class File : public Stream
 public:
   static const u_long READ;
   static const u_long WRITE;
+  static const u_long TEMPORARY_DELAYED;
   static const u_long TEMPORARY;
   static const u_long HIDDEN;
   static const u_long FILE_OPEN_ALWAYS;
@@ -48,10 +49,10 @@ public:
 
   virtual Handle getHandle ();
   virtual int setHandle (Handle);
-  virtual int writeToFile (const char* ,u_long ,u_long* );
-  virtual int createTemporaryFile (const char* );
+  virtual int writeToFile (const char *, u_long , u_long *);
+  virtual int createTemporaryFile (const char *, bool unlink = true);
 
-  virtual int openFile (const char*, u_long );
+  virtual int openFile (const char *, u_long);
   virtual int openFile (string const &file, u_long opt)
   {return openFile (file.c_str (), opt);}
 
@@ -70,7 +71,7 @@ public:
   virtual int operator =(File);
   virtual int close ();
 
-  /*! Inherithed from Stream. */
+  /* Inherithed from Stream.  */
   virtual int read (char* buffer, u_long len, u_long *nbr);
   virtual int write (const char* buffer, u_long len, u_long *nbw);
 
@@ -78,7 +79,12 @@ public:
                                 MemBuf *buf, u_long *nbw);
 
   int truncate (u_long size = 0);
+
+  /*! Get the options mask used with openFile.  */
+  u_long getOpenOptions (){return opt;}
 protected:
+  /* Options used by open.  */
+  u_long opt;
   FileHandle handle;
   string filename;
 };
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 90f50fa..0f5c0b8 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -52,15 +52,16 @@ extern "C"
 
 using namespace std;
 
-const u_long File::READ = (1<<0);
-const u_long File::WRITE = (1<<1);
-const u_long File::TEMPORARY = (1<<2);
-const u_long File::HIDDEN = (1<<3);
-const u_long File::FILE_OPEN_ALWAYS = (1<<4);
-const u_long File::OPEN_IF_EXISTS = (1<<5);
-const u_long File::APPEND = (1<<6);
-const u_long File::FILE_CREATE_ALWAYS = (1<<7);
-const u_long File::NO_INHERIT = (1<<8);
+const u_long File::READ = (1 << 0);
+const u_long File::WRITE = (1 << 1);
+const u_long File::TEMPORARY = (1 << 2);
+const u_long File::TEMPORARY_DELAYED = (1 << 3);
+const u_long File::HIDDEN = (1 << 4);
+const u_long File::FILE_OPEN_ALWAYS = (1 << 5);
+const u_long File::OPEN_IF_EXISTS = (1 << 6);
+const u_long File::APPEND = (1 << 7);
+const u_long File::FILE_CREATE_ALWAYS = (1 << 8);
+const u_long File::NO_INHERIT = (1 << 9);
 
 
 /*!
@@ -137,7 +138,7 @@ int File::truncate (u_long size)
  *\param opt Specify how open the file.
  *openFile returns 0 if the call was successful, any other value on errors.
  */
-int File::openFile (const char* nfilename,u_long opt)
+int File::openFile (const char* nfilename, u_long opt)
 {
   struct stat fStats;
   int flags;
@@ -166,11 +167,20 @@ int File::openFile (const char* nfilename,u_long opt)
     handle = open (filename.c_str (), O_CREAT | flags, S_IRUSR | S_IWUSR);
 
   if (opt & File::FILE_CREATE_ALWAYS)
-    truncate ();
-
+    if (truncate ())
+      {
+        close ();
+        return -1;
+      }
+ 
   if (opt & File::TEMPORARY)
-    unlink (filename.c_str ()); /* It will be removed on close.  */
+    if (unlink (filename.c_str ()))
+      {
+        close ();
+        return -1;
+      }
 
+  this->opt = opt;
   return handle < 0;
 }
 
@@ -224,19 +234,19 @@ const char *File::getFilename ()
 }
 
 /*!
- *Create a temporary file.
- *\param filename The new temporary file name.
+ * Create a temporary file.
+ * \param filename The new temporary file name.
+ * \param unlink Unlink the inode immediately, not before close.
  */
-int File::createTemporaryFile (const char* filename)
+int File::createTemporaryFile (const char* filename, bool unlink)
 {
   if (FilesUtility::nodeExists (filename))
     FilesUtility::deleteFile (filename);
 
-  return openFile (filename, File::READ
-                  | File::WRITE
-                  | File::FILE_CREATE_ALWAYS
-                  | File::TEMPORARY
-                  | File::NO_INHERIT);
+  u_long temporaryOpt = unlink ? File::TEMPORARY : File::TEMPORARY_DELAYED;
+
+  return openFile (filename, File::READ | File::WRITE | File::NO_INHERIT
+                   | File::FILE_CREATE_ALWAYS | temporaryOpt);
 }
 
 /*!
@@ -247,11 +257,15 @@ int File::close ()
   int ret = 0;
   if (handle != -1)
     {
+      if (opt & File::TEMPORARY_DELAYED)
+        unlink (filename.c_str ());
       ret = fsync (handle);
       ret |= ::close (handle);
     }
+
   filename.clear ();
   handle = -1;
+
   return ret;
 }
 
diff --git a/myserver/tests/test_file.cpp b/myserver/tests/test_file.cpp
index a45dd06..1eb49b8 100644
--- a/myserver/tests/test_file.cpp
+++ b/myserver/tests/test_file.cpp
@@ -38,8 +38,8 @@ class TestFile : public CppUnit::TestFixture
   string fname;
 
   CPPUNIT_TEST_SUITE (TestFile);
-
   CPPUNIT_TEST (testCreateTemporaryFile);
+  CPPUNIT_TEST (testCreateTemporaryDelayedFile);
   CPPUNIT_TEST (testOnFile);
   CPPUNIT_TEST (testBinary);
   CPPUNIT_TEST (testTruncate);
@@ -68,11 +68,36 @@ public:
     FilesUtility::deleteFile (fname);
   }
 
+  void testCreateTemporaryDelayedFile ()
+  {
+    int ret = tfile->createTemporaryFile (fname.c_str (), false);
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
+
+    /* The unlink is done just before the close, the file can be stat'ed. */
+    ret = FilesUtility::nodeExists (fname.c_str ());
+    CPPUNIT_ASSERT (ret);
+
+    ret = tfile->close ();
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
+
+    ret = FilesUtility::nodeExists (fname.c_str ());
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
+  }
+
   void testCreateTemporaryFile ()
   {
-    CPPUNIT_ASSERT_EQUAL (tfile->createTemporaryFile (fname.c_str ()), 0);
+    int ret = tfile->createTemporaryFile (fname.c_str (), true);
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
 
-    CPPUNIT_ASSERT_EQUAL (tfile->close (), 0);
+    /* Using unlink the file can't be stat'ed at this point.  */
+    ret = FilesUtility::nodeExists (fname.c_str ());
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
+
+    ret = tfile->close ();
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
+
+    ret = FilesUtility::nodeExists (fname.c_str ());
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
   }
 
   void testOnFile ()

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

Summary of changes:
 myserver/include/base/file/file.h                  |   14 ++++--
 myserver/src/base/file/file.cpp                    |   56 ++++++++++++-------
 .../src/base/process/process_server_manager.cpp    |   20 +++----
 myserver/tests/test_file.cpp                       |   31 ++++++++++-
 4 files changed, 82 insertions(+), 39 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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