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. 52f78e0ef8


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 52f78e0ef8e476724fc62c2331c9148b994e44f7
Date: Tue, 06 Oct 2009 22:29:40 +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  52f78e0ef8e476724fc62c2331c9148b994e44f7 (commit)
       via  988666de95e3271015bf88794e8b7b7482be4292 (commit)
      from  dc002aaaa32bc9f7212ec4b0a0c0e5c7dfd57a9f (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 52f78e0ef8e476724fc62c2331c9148b994e44f7
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 00:29:40 2009 +0200

    Spell `Content-Type' properly.

diff --git a/myserver/src/http_handler/http_dir/http_dir.cpp 
b/myserver/src/http_handler/http_dir/http_dir.cpp
index 411a251..dfc046a 100644
--- a/myserver/src/http_handler/http_dir/http_dir.cpp
+++ b/myserver/src/http_handler/http_dir/http_dir.cpp
@@ -337,7 +337,7 @@ int HttpDir::send (HttpThreadContext* td,
 
   checkDataChunks (td, &keepalive, &useChunks);
 
-  td->response.setValue ("ContentType", "text/html");
+  td->response.setValue ("Content-Type", "text/html");
 
   if (!td->appendOutputs)
   {
diff --git a/myserver/src/http_handler/mscgi/mscgi_manager.cpp 
b/myserver/src/http_handler/mscgi/mscgi_manager.cpp
index 459ba18..6f10b0b 100644
--- a/myserver/src/http_handler/mscgi/mscgi_manager.cpp
+++ b/myserver/src/http_handler/mscgi/mscgi_manager.cpp
@@ -250,7 +250,7 @@ MsCgiData* MscgiManager::getCgiData ()
  */
 void MscgiManager::setContentType (const char * type)
 {
-  td->response.setValue ("ContentType", type);
+  td->response.setValue ("Content-Type", type);
 }
 
 /*!
diff --git a/myserver/src/protocol/http/http.cpp 
b/myserver/src/protocol/http/http.cpp
index 019cb6b..78592f1 100644
--- a/myserver/src/protocol/http/http.cpp
+++ b/myserver/src/protocol/http/http.cpp
@@ -643,12 +643,12 @@ Http::sendHTTPResource (string& uri, int systemrequest, 
int onlyHeader,
       /* If not specified differently, set the default content type to 
text/html.  */
       if (td->mime)
         {
-          td->response.setValue ("ContentType", td->mime->mimeType.c_str ());
+          td->response.setValue ("Content-Type", td->mime->mimeType.c_str ());
           cgiManager = td->mime->cgiManager.c_str ();
         }
       else
         {
-          td->response.setValue ("ContentType", "text/html");
+          td->response.setValue ("Content-Type", "text/html");
           cgiManager = "";
         }
 



commit 988666de95e3271015bf88794e8b7b7482be4292
Author: Giuseppe Scrivano <address@hidden>
Date:   Tue Oct 6 21:30:29 2009 +0200

    The d'tor frees used resource, calling close.

diff --git a/myserver/include/base/file/file.h 
b/myserver/include/base/file/file.h
index beaa148..1463c25 100644
--- a/myserver/include/base/file/file.h
+++ b/myserver/include/base/file/file.h
@@ -43,6 +43,8 @@ public:
 
   File ();
   File (char *,int);
+  virtual ~File ();
+
   virtual Handle getHandle ();
   virtual int setHandle (Handle);
   virtual int writeToFile (const char* ,u_long ,u_long* );
diff --git a/myserver/include/base/pipe/pipe.h 
b/myserver/include/base/pipe/pipe.h
index 0490b91..7268b00 100644
--- a/myserver/include/base/pipe/pipe.h
+++ b/myserver/include/base/pipe/pipe.h
@@ -29,22 +29,23 @@ using namespace std;
 class Pipe : public Stream
 {
 public:
-       Pipe ();
-       int create (bool readPipe = true);
-       long getReadHandle ();
-       long getWriteHandle ();
-       void inverted (Pipe&);
+  Pipe ();
+  virtual ~Pipe ();
+  int create (bool readPipe = true);
+  long getReadHandle ();
+  long getWriteHandle ();
+  void inverted (Pipe&);
   virtual int read (char* buffer, u_long len, u_long *nbr);
   virtual int write (const char* buffer, u_long len, u_long *nbw);
-       virtual int close ();
-       void closeRead ();
-       void closeWrite ();
-       bool pipeTerminated (){return terminated;}
+  virtual int close ();
+  void closeRead ();
+  void closeWrite ();
+  bool pipeTerminated (){return terminated;}
   int waitForData (int sec, int usec);
 private:
   bool terminated;
 # ifndef WIN32
-       int handles[2];
+  int handles[2];
 # else
   HANDLE readHandle;
   HANDLE writeHandle;
diff --git a/myserver/include/base/socket/socket.h 
b/myserver/include/base/socket/socket.h
index f221b9b..a4b8ed2 100644
--- a/myserver/include/base/socket/socket.h
+++ b/myserver/include/base/socket/socket.h
@@ -36,7 +36,8 @@ extern "C"
 # endif
 
 # ifndef WIN32
-extern "C" {
+extern "C"
+{
 #  include <sys/types.h>
 #  include <sys/socket.h>
 #  include <sys/ioctl.h>
@@ -88,8 +89,8 @@ public:
   Socket ();
   Socket (Socket*);
   Socket (SocketHandle);
-
-  Socket accept (MYSERVER_SOCKADDR*, socklen_t*);
+  virtual ~Socket ();
+  Socket* accept (MYSERVER_SOCKADDR*, socklen_t*);
   int setsockopt (int,int, const char*,int);
 
   virtual int connect (MYSERVER_SOCKADDR*, int);
@@ -102,8 +103,8 @@ public:
   int ioctlsocket (long, unsigned long*);
   int send (const char*, int, int);
   int connect (const char* host, u_short port);
-  int operator==(Socket);
-  int operator=(Socket);
+  int operator==(Socket*);
+  int operator=(Socket*);
   int getsockname (MYSERVER_SOCKADDR*,int*);
   int setNonBlocking (int);
   bool getNonBLocking () {return isNonBlocking;}
diff --git a/myserver/include/base/socket/ssl_socket.h 
b/myserver/include/base/socket/ssl_socket.h
index b709141..ae9b59c 100644
--- a/myserver/include/base/socket/ssl_socket.h
+++ b/myserver/include/base/socket/ssl_socket.h
@@ -65,7 +65,7 @@ public:
 # endif
 
        SslSocket (Socket*);
-       ~SslSocket ();
+       virtual ~SslSocket ();
 
 protected:
        bool externalContext;
diff --git a/myserver/include/base/unix_socket/unix_socket.h 
b/myserver/include/base/unix_socket/unix_socket.h
index 45f8bcb..985aef9 100644
--- a/myserver/include/base/unix_socket/unix_socket.h
+++ b/myserver/include/base/unix_socket/unix_socket.h
@@ -37,11 +37,12 @@ class UnixSocket: public Socket
 {
 public:
   UnixSocket ();
+  virtual ~UnixSocket ();
   int bind (const char *path);
   int shutdown ();
   int close ();
   int connect (const char* path);
-  Socket accept ();
+  Socket* accept ();
   int socket ();
 protected:
 
diff --git a/myserver/include/connections_scheduler/connections_scheduler.h 
b/myserver/include/connections_scheduler/connections_scheduler.h
index ecd3549..c2d9d9c 100644
--- a/myserver/include/connections_scheduler/connections_scheduler.h
+++ b/myserver/include/connections_scheduler/connections_scheduler.h
@@ -74,7 +74,8 @@ public:
     Server* server;
     ConnectionsScheduler* scheduler;
     SocketPair socketPair;
-  };
+    Socket socketPairWrite;
+   };
 
   ConnectionsScheduler (Server* server = NULL);
   ~ConnectionsScheduler ();
diff --git a/myserver/include/server/server.h b/myserver/include/server/server.h
index 2575149..5255c18 100644
--- a/myserver/include/server/server.h
+++ b/myserver/include/server/server.h
@@ -107,7 +107,7 @@ public:
   void rebootOnNextLoop ();
   ~Server ();
   Protocol* getProtocol (const char *protocolName);
-  int addConnection (Socket,MYSERVER_SOCKADDRIN*);
+  int addConnection (Socket*, MYSERVER_SOCKADDRIN*);
   u_long getNumConnections ();
   u_long getNumTotalConnections ();
   void getConnections (list<ConnectionPtr>&);
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 984df1b..9cdb157 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -22,7 +22,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <include/base/file/files_utility.h>
 
 #ifndef WIN32
-extern "C" {
+extern "C"
+{
 # include <fcntl.h>
 # include <unistd.h>
 # include <sys/types.h>
@@ -70,7 +71,15 @@ const u_long File::NO_INHERIT = (1<<8);
  */
 File::File ()
 {
-  handle = 0;
+  handle = -1;
+}
+
+/*!
+ *D'tor.
+ */
+File::~File ()
+{
+  close ();
 }
 
 /*!
@@ -310,7 +319,7 @@ int File::createTemporaryFile (const char* filename)
 int File::close ()
 {
   int ret = 0;
-  if (handle)
+  if (handle != -1)
     {
 #ifdef WIN32
       ret = !FlushFileBuffers (handle);
@@ -321,7 +330,7 @@ int File::close ()
 #endif
   }
   filename.clear ();
-  handle = 0;
+  handle = -1;
   return ret;
 }
 
diff --git a/myserver/src/base/pipe/pipe.cpp b/myserver/src/base/pipe/pipe.cpp
index 8e17a81..1ff9b51 100644
--- a/myserver/src/base/pipe/pipe.cpp
+++ b/myserver/src/base/pipe/pipe.cpp
@@ -197,16 +197,18 @@ int Pipe::close ()
 {
   terminated = true;
 #ifndef WIN32
-  if (handles[0])
+  if (handles[0] >= 0)
     ::close (handles[0]);
-  if (handles[1])
+  if (handles[1] >= 0)
     ::close (handles[1]);
-  handles[0] = handles[1] = 0;
+
+  handles[0] = handles[1] = -1;
 #else
-  if (readHandle)
+  if (readHandle >= 0)
     CloseHandle (readHandle);
-  if (writeHandle)
+  if (writeHandle >= 0)
     CloseHandle (writeHandle);
+
   readHandle = writeHandle = 0;
 #endif
   return 0;
@@ -232,12 +234,17 @@ Pipe::Pipe ()
 {
   terminated = false;
 #ifndef WIN32
-  handles[0] = handles[1] = 0;
+  handles[0] = handles[1] = -1;
 #else
-  readHandle = writeHandle = 0;
+  readHandle = writeHandle = -1;
 #endif
 }
 
+Pipe::~Pipe ()
+{
+  close ();
+}
+
 /*!
  *Close the read stream of the pipe.
  */
@@ -245,13 +252,13 @@ void Pipe::closeRead ()
 {
   terminated = true;
 #ifndef WIN32
-  if (handles[0])
+  if (handles[0] >= 0)
     ::close (handles[0]);
-  handles[0] = 0;
+  handles[0] = -1;
 #else
-  if (readHandle)
+  if (readHandle >= 0)
     CloseHandle (readHandle);
-  readHandle = 0;
+  readHandle = -1;
 #endif
 }
 
@@ -262,13 +269,13 @@ void Pipe::closeWrite ()
 {
   terminated = true;
 #ifndef WIN32
-  if (handles[1])
+  if (handles[1] >= 0)
     ::close (handles[1]);
-  handles[1] = 0;
+  handles[1] = -1;
 #else
-  if (writeHandle)
+  if (writeHandle >= 0)
     CloseHandle (writeHandle);
-  writeHandle = 0;
+  writeHandle = -1;
 #endif
 }
 
diff --git a/myserver/src/base/read_directory/read_directory.cpp 
b/myserver/src/base/read_directory/read_directory.cpp
index 0526242..0525000 100644
--- a/myserver/src/base/read_directory/read_directory.cpp
+++ b/myserver/src/base/read_directory/read_directory.cpp
@@ -52,7 +52,7 @@ ReadDirectory::ReadDirectory ()
  */
 ReadDirectory::~ReadDirectory ()
 {
-
+ findclose ();
 }
 
 /*!
@@ -163,6 +163,7 @@ int ReadDirectory::find (const char *filename)
  */
 int ReadDirectory::findclose ()
 {
+  dirName.empty ();
 #ifdef WIN32
   int ret;
   if (!ff)
@@ -171,9 +172,11 @@ int ReadDirectory::findclose ()
   ff = 0;
   return ret;
 #else
-  if (dh)
-    closedir (dh);
-  dirName.empty ();
+  if (!dh)
+    return -1;
+
+  closedir (dh);
+  dh = NULL;
   return 0;
 #endif
 }
diff --git a/myserver/src/base/socket/socket.cpp 
b/myserver/src/base/socket/socket.cpp
index 057aef6..92d437c 100644
--- a/myserver/src/base/socket/socket.cpp
+++ b/myserver/src/base/socket/socket.cpp
@@ -19,7 +19,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include "stdafx.h"
 #include <include/base/utility.h>
 #include <include/base/socket/socket.h>
-extern "C" {
+extern "C"
+{
 #include <string.h>
 #include <stdio.h>
 #ifndef WIN32
@@ -80,20 +81,20 @@ void Socket::setHandle (SocketHandle h)
 /*!
  *Check if the two sockets have the same handle descriptor
  */
-int Socket::operator==(Socket s)
+int Socket::operator==(Socket* s)
 {
-  return socketHandle == s.socketHandle;
+  return socketHandle == s->socketHandle;
 }
 
 /*!
  *Set the socket using the = operator
  */
-int Socket::operator=(Socket s)
+int Socket::operator=(Socket* s)
 {
-  socketHandle = s.socketHandle;
-  serverSocket = s.serverSocket;
-  throttlingRate = s.throttlingRate;
-  isNonBlocking = s.isNonBlocking;
+  socketHandle = s->socketHandle;
+  serverSocket = s->serverSocket;
+  throttlingRate = s->throttlingRate;
+  isNonBlocking = s->isNonBlocking;
   return 0;
 }
 /*!
@@ -103,15 +104,15 @@ int Socket::operator=(Socket s)
 int Socket::socket (int af, int type, int protocol)
 {
 #ifdef WIN32
-  socketHandle = (SOCKET)::socket (af, type, protocol);
+  socketHandle = ::socket (af, type, protocol);
 #else
   socketHandle = (FileHandle)::socket (af, type, protocol);
 #endif
-  return  (int)socketHandle;
+  return (int)socketHandle;
 }
 
 /*!
- *Set the base/socket/socket.handle.
+ * C'tor.
  */
 Socket::Socket (SocketHandle handle)
 {
@@ -121,7 +122,7 @@ Socket::Socket (SocketHandle handle)
 }
 
 /*!
- *Set the base/socket/socket.handle.
+ * C'tor.
  */
 Socket::Socket (Socket* socket)
 {
@@ -131,6 +132,11 @@ Socket::Socket (Socket* socket)
   isNonBlocking = socket->isNonBlocking;
 }
 
+Socket::~Socket ()
+{
+  close ();
+}
+
 /*!
  *Return the throttling rate (bytes/second) used by the socket. A return value
  *of zero means that no throttling is used.
@@ -156,8 +162,8 @@ Socket::Socket ()
 {
   /*! Reset everything.  */
   throttlingRate = 0;
-  serverSocket = 0;
-  setHandle (0);
+  serverSocket = NULL;
+  setHandle (-1);
 }
 
 /*!
@@ -176,9 +182,9 @@ int Socket::bind (MYSERVER_SOCKADDR* sa,int namelen)
     return -1;
 
 #ifdef WIN32
-  return ::bind ((SOCKET)socketHandle,(const struct sockaddr*)sa,namelen);
+  return ::bind (socketHandle, (const struct sockaddr*)sa, namelen);
 #else
-  return ::bind ((int)socketHandle,(const struct sockaddr*)sa,namelen);
+  return ::bind (socketHandle, (const struct sockaddr*)sa, namelen);
 #endif
 }
 
@@ -190,25 +196,25 @@ int Socket::listen (int max)
 #ifdef WIN32
   return ::listen (socketHandle, max);
 #else
-  return ::listen ((int)socketHandle, max);
+  return ::listen (socketHandle, max);
 #endif
 }
 
 /*!
  *Accept a new connection.
  */
-Socket Socket::accept (MYSERVER_SOCKADDR* sa, socklen_t* sockaddrlen)
+Socket* Socket::accept (MYSERVER_SOCKADDR* sa, socklen_t* sockaddrlen)
 {
-  Socket s;
-
   socklen_t connectSize;
   connectSize = (socklen_t) *sockaddrlen;
 
-  SocketHandle acceptHandle = ::accept ((int)socketHandle, (struct sockaddr 
*)sa,
-                                       (socklen_t*)&connectSize);
-  s.setHandle (acceptHandle);
+  SocketHandle acceptedHandle = ::accept (socketHandle, (struct sockaddr *)sa,
+                                          (socklen_t*)&connectSize);
 
-  return s;
+  if (acceptedHandle >= 0)
+    return new Socket (acceptedHandle);
+  else
+    return NULL;
 }
 
 /*!
@@ -216,25 +222,17 @@ Socket Socket::accept (MYSERVER_SOCKADDR* sa, socklen_t* 
sockaddrlen)
  */
 int Socket::close ()
 {
+  int ret = -1;
+  if (socketHandle >= 0)
+    {
 #ifdef WIN32
-  if (socketHandle)
-  {
-    int ret = ::closesocket (socketHandle);
-    socketHandle = 0;
-    return ret;
-  }
-  else
-    return 0;
+      ret = ::closesocket (socketHandle);
 #else
-  if (socketHandle)
-  {
-    int ret = ::close ((int)socketHandle);
-    socketHandle = 0;
-    return ret;
-  }
-  else
-    return 0;
+      ret = ::close (socketHandle);
+    }
 #endif
+  socketHandle = -1;
+  return ret;
 }
 
 /*!
@@ -264,9 +262,9 @@ MYSERVER_HOSTENT *Socket::gethostbyname (const char 
*hostname)
 int Socket::shutdown (int how)
 {
 #ifdef WIN32
-  return ::shutdown (socketHandle,how);
+  return ::shutdown (socketHandle, how);
 #else
-  return ::shutdown ((int)socketHandle,how);
+  return ::shutdown (socketHandle, how);
 #endif
 }
 
@@ -384,7 +382,7 @@ int Socket::rawSend (const char* buffer, int len, int flags)
   }
   return ret;
 #else
-  return ::send ((int)socketHandle, buffer, len, flags);
+  return ::send (socketHandle, buffer, len, flags);
 #endif
 }
 
@@ -442,7 +440,7 @@ int Socket::ioctlsocket (long cmd,unsigned long* argp)
   return ::ioctlsocket (socketHandle, cmd, argp);
 #else
   int int_argp = 0;
-  int ret = ::ioctl ((int)socketHandle, cmd, &int_argp);
+  int ret = ::ioctl (socketHandle, cmd, &int_argp);
   *argp = int_argp;
   return ret;
 #endif
@@ -601,9 +599,9 @@ int Socket::connect (MYSERVER_SOCKADDR* sa, int na)
     return -1;
 
 #ifdef WIN32
-  return ::connect ((SOCKET)socketHandle,(const sockaddr *)sa, na);
+  return ::connect (socketHandle,(const sockaddr *)sa, na);
 #else
-  return ::connect ((int)socketHandle,(const sockaddr *)sa,na);
+  return ::connect (socketHandle,(const sockaddr *)sa,na);
 #endif
 }
 
@@ -637,7 +635,7 @@ int Socket::recv (char* buffer,int len,int flags)
   else
     return err;
 #else
-  err = ::recv ((int)socketHandle, buffer, len, flags);
+  err = ::recv (socketHandle, buffer, len, flags);
 
   if ( err < 0 && errno == EAGAIN && isNonBlocking)
     return 0;
@@ -685,7 +683,7 @@ int Socket::setNonBlocking (int nonBlocking)
 #else
 
   int flags;
-  flags = fcntl ((int)socketHandle, F_GETFL, 0);
+  flags = fcntl (socketHandle, F_GETFL, 0);
   if (flags < 0)
     return -1;
 
@@ -694,7 +692,7 @@ int Socket::setNonBlocking (int nonBlocking)
   else
     flags &= ~O_NONBLOCK;
 
-  ret = fcntl ((int)socketHandle, F_SETFL, flags);
+  ret = fcntl (socketHandle, F_SETFL, flags);
 
 #endif
   isNonBlocking = nonBlocking ? true : false;
@@ -718,7 +716,7 @@ int Socket::getsockname (MYSERVER_SOCKADDR *ad, int 
*namelen)
   return ::getsockname (socketHandle,(sockaddr *)ad,namelen);
 #else
   socklen_t len =(socklen_t) *namelen;
-  int ret = ::getsockname ((int)socketHandle, (struct sockaddr *)ad, &len);
+  int ret = ::getsockname (socketHandle, (struct sockaddr *)ad, &len);
   *namelen = (int)len;
   return ret;
 #endif
@@ -753,7 +751,7 @@ int Socket::dataOnRead (int sec, int usec)
 
   FD_ZERO (&readfds);
 #ifdef WIN32
-  FD_SET ((SOCKET)socketHandle, &readfds);
+  FD_SET (socketHandle, &readfds);
 #else
   FD_SET (socketHandle, &readfds);
 #endif
diff --git a/myserver/src/base/socket_pair/socket_pair.cpp 
b/myserver/src/base/socket_pair/socket_pair.cpp
index 7df3a59..b4220df 100644
--- a/myserver/src/base/socket_pair/socket_pair.cpp
+++ b/myserver/src/base/socket_pair/socket_pair.cpp
@@ -21,7 +21,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <include/base/socket_pair/socket_pair.h>
 
 #ifndef WIN32
-extern "C" {
+extern "C"
+{
 # include <fcntl.h>
 # include <unistd.h>
 # include <sys/types.h>
@@ -71,12 +72,10 @@ int SocketPair::create ()
 
 #ifndef WIN32
   int ret = socketpair (af, type, protocol, (int*)handles);
-
   if (ret == 0)
     socketHandle = handles[0];
 
   return ret;
-
 #else
   struct sockaddr_in addr;
   SOCKET listener;
@@ -205,11 +204,15 @@ void SocketPair::closeSecondHandle ()
  */
 void SocketPair::setNonBlocking (bool notBlocking)
 {
+  /* FIXME: avoid this trick to set the handle to -1 to avoid
+   a close on the real descriptor by the d'tor.  */
   Socket sock0 (handles[0]);
-   sock0.setNonBlocking (notBlocking);
+  sock0.setNonBlocking (notBlocking);
+  sock0.setHandle (-1);
 
-   Socket sock1 (handles[1]);
-   sock1.setNonBlocking (notBlocking);
+  Socket sock1 (handles[1]);
+  sock1.setNonBlocking (notBlocking);
+  sock1.setHandle (-1);
 }
 
 /*!
diff --git a/myserver/src/base/unix_socket/unix_socket.cpp 
b/myserver/src/base/unix_socket/unix_socket.cpp
index 948d5c3..16558b6 100644
--- a/myserver/src/base/unix_socket/unix_socket.cpp
+++ b/myserver/src/base/unix_socket/unix_socket.cpp
@@ -25,6 +25,11 @@ UnixSocket::UnixSocket ()
 
 }
 
+UnixSocket::~UnixSocket ()
+{
+
+}
+
 /*!
  *Bind the socket to a file.  If the file exists it is removed.
  *\param path Path to the file bound by the socket.
@@ -108,7 +113,7 @@ int UnixSocket::connect (const char* path)
 /*!
  *Accept a new connection.
  */
-Socket UnixSocket::accept ()
+Socket* UnixSocket::accept ()
 {
 
 #ifdef AF_UNIX
@@ -117,7 +122,7 @@ Socket UnixSocket::accept ()
   return Socket::accept ((MYSERVER_SOCKADDR*)&addr, &len);
 #else
   Socket s;
-  s.setHandle (0);
+  s.setHandle (-1);
   return s;
 #endif
 }
diff --git a/myserver/src/connection/connection.cpp 
b/myserver/src/connection/connection.cpp
index 6ebc8fb..3879ba6 100644
--- a/myserver/src/connection/connection.cpp
+++ b/myserver/src/connection/connection.cpp
@@ -37,7 +37,7 @@ void Connection::init ()
   toRemove = 0;
   forceControl = 0;
   protocolBuffer = NULL;
-  socket = 0;
+  socket = NULL;
   priority = -1;
   continuation = NULL;
        connectionBuffer = new MemBuf ();
diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index db9f4a8..bd3784d 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -95,8 +95,6 @@ static void eventLoopHandler (int fd, short event, void *arg)
   u_long nbr;
   if (event == EV_READ || event == EV_TIMEOUT)
   {
-    Socket sock (da->socketPair.getFirstHandle ());
-
     while (da->socketPair.bytesToRead ())
     {
       char cmd;
@@ -134,22 +132,17 @@ static void listenerHandler (int fd, short event, void 
*arg)
   static timeval tv = {5, 0};
   ConnectionsScheduler::ListenerArg* s = 
(ConnectionsScheduler::ListenerArg*)arg;
 
-  if (event == EV_TIMEOUT)
-    event_add (&(s->ev), &tv);
-  else if (event == EV_READ)
+  if (event == EV_READ)
     {
       MYSERVER_SOCKADDRIN asockIn;
-      socklen_t asockInLen = 0;
-      Socket clientSock;
-
-      asockInLen = sizeof (asockIn);
-      clientSock = s->serverSocket->accept (&asockIn, &asockInLen);
+      socklen_t asockInLen = sizeof (asockIn);
+      Socket *clientSock = s->serverSocket->accept (&asockIn, &asockInLen);
 
-      if (s->server && (SocketHandle)clientSock.getHandle () != INVALID_SOCKET)
+      if (s->server && clientSock)
         s->server->addConnection (clientSock, &asockIn);
-
-      event_add (&(s->ev), &tv);
     }
+ 
+  event_add (&(s->ev), &tv);
 }
 
 /*!
@@ -176,10 +169,9 @@ void ConnectionsScheduler::listener 
(ConnectionsScheduler::ListenerArg *la)
   event_add (&(arg->ev), &tv);
 
   u_long nbw;
-  Socket sock (dispatcherArg.socketPair.getSecondHandle ());
 
   eventsSocketMutex.lock ();
-  sock.write ("l", 1, &nbw);
+  dispatcherArg.socketPairWrite.write ("l", 1, &nbw);
   eventsSocketMutex.unlock ();
 }
 
@@ -279,8 +271,10 @@ void ConnectionsScheduler::initialize ()
       return;
     }
 
-  event_set (&(dispatcherArg.loopEvent), 
dispatcherArg.socketPair.getFirstHandle (), EV_READ | EV_TIMEOUT,
-             eventLoopHandler, &dispatcherArg);
+  dispatcherArg.socketPairWrite.setHandle 
(dispatcherArg.socketPair.getSecondHandle ());
+
+  event_set (&(dispatcherArg.loopEvent), 
dispatcherArg.socketPair.getFirstHandle (),
+             EV_READ | EV_TIMEOUT, eventLoopHandler, &dispatcherArg);
 
   event_add (&(dispatcherArg.loopEvent), NULL);
 
@@ -396,13 +390,16 @@ void ConnectionsScheduler::addWaitingConnectionImpl 
(ConnectionPtr c, int lock)
   if (lock)
     {
       u_long nbw;
-      Socket sock (dispatcherArg.socketPair.getSecondHandle ());
-
       eventsSocketMutex.lock ();
-      sock.write ("c", 1, &nbw);
-      sock.write ((char*)&handle, sizeof (SocketHandle), &nbw);
-      sock.write ((char*)&c, sizeof (ConnectionPtr), &nbw);
-      sock.write ((char*)&tv, sizeof (timeval), &nbw);
+
+      dispatcherArg.socketPairWrite.write ("c", 1, &nbw);
+      dispatcherArg.socketPairWrite.write ((const char*)&handle,
+                                           sizeof (SocketHandle), &nbw);
+      dispatcherArg.socketPairWrite.write ((const char*)&c,
+                                           sizeof (ConnectionPtr), &nbw);
+      dispatcherArg.socketPairWrite.write ((const char*)&tv,
+                                           sizeof (timeval), &nbw);
+
       eventsSocketMutex.unlock ();
     }
   else
@@ -464,15 +461,10 @@ void ConnectionsScheduler::release ()
     max = server->getNumThreads () * 2;
 
   for (u_long i = 0; i < max; i++)
-    {
-      readySemaphore->unlock ();
-    }
-
-  Socket sockR (dispatcherArg.socketPair.getFirstHandle ());
-  Socket sockW (dispatcherArg.socketPair.getSecondHandle ());
+    readySemaphore->unlock ();
 
   eventsSocketMutex.lock ();
-  sockW.write ("r", 1, &nbw);
+  dispatcherArg.socketPairWrite.write ("r", 1, &nbw);
   eventsSocketMutex.unlock ();
 
   if (dispatchedThreadId)
@@ -585,7 +577,6 @@ int ConnectionsScheduler::accept 
(ConnectionsSchedulerVisitor* visitor, void* ar
 
   try
     {
-
       for (HashMap<SocketHandle, ConnectionPtr>::Iterator it =
              connections.begin (); it != connections.end ()  && !ret; it++)
         visitor->visitConnection (*it, args);
diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index cc57ee9..a5f105d 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -225,7 +225,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
    */
   bool useGzip = false;
   u_long filesize = 0;
-  File *file = 0;
+  File *file = NULL;
   u_long bytesToSend;
   u_long firstByte = td->request.rangeByteBegin;
   u_long lastByte = td->request.rangeByteEnd;
@@ -271,7 +271,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
       return td->http->sendHTTPNonModified ();
 
     file = Server::getInstance ()->getCachedFiles ()->open (filenamePath);
-    if (file == 0)
+    if (!file)
       return td->http->raiseHTTPError (500);
 
     /*
diff --git a/myserver/src/protocol/ftp/ftp.cpp 
b/myserver/src/protocol/ftp/ftp.cpp
index ec0a7b7..217b137 100644
--- a/myserver/src/protocol/ftp/ftp.cpp
+++ b/myserver/src/protocol/ftp/ftp.cpp
@@ -564,20 +564,20 @@ void Ftp::pasv ()
 #endif
   MYSERVER_SOCKADDRIN asockIn;
   socklen_t asockInLen = 0;
-  Socket asock;
+  Socket *asock;
   if (pFtpuserData->m_pDataConnection->socket->dataOnRead (timeoutvalue, 0)
       == 1)
     {
       asockInLen = sizeof (sockaddr_in);
-      asock =pFtpuserData->m_pDataConnection->socket->accept (&asockIn,
-                                                           &asockInLen);
-      if (asock.getHandle () == (Handle) INVALID_SOCKET)
+      asock = pFtpuserData->m_pDataConnection->socket->accept (&asockIn,
+                                                               &asockInLen);
+      if (asock->getHandle () == (Handle) INVALID_SOCKET)
         return;
 
       pFtpuserData->m_pDataConnection->socket->shutdown (SD_BOTH);
       pFtpuserData->m_pDataConnection->socket->close ();
       delete pFtpuserData->m_pDataConnection->socket;
-      pFtpuserData->m_pDataConnection->socket = new Socket (asock);
+      pFtpuserData->m_pDataConnection->socket = asock;
     }
 
   pFtpuserData->m_bPassiveSrv = false;
@@ -1577,9 +1577,8 @@ Ftp::openDataPassive ()
 #endif // WIN32
   ((sockaddr_in *) (&storage))->sin_port =
     htons (getPortNo (pFtpuserData->m_cdh));
-  if (pSocket->
-      setsockopt (SOL_SOCKET, SO_REUSEADDR, (const char *) &nReuseAddr,
-                  sizeof (nReuseAddr)) < 0)
+  if (pSocket->setsockopt (SOL_SOCKET, SO_REUSEADDR, (const char *) 
&nReuseAddr,
+                           sizeof (nReuseAddr)) < 0)
     return 0;
 
   if (pSocket->bind (&storage, sizeof (sockaddr_in)) != 0
@@ -1602,13 +1601,16 @@ Ftp::openDataActive ()
   FtpuserData *pFtpuserData =
     static_cast < FtpuserData * >(td.pConnection->protocolBuffer);
 
-  Socket dataSocket;
-  dataSocket.socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
+  Socket *dataSocket = new Socket ();
+  dataSocket->socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
   char szIpAddr[16];
   memset (szIpAddr, 0, 16);
   getIpAddr (pFtpuserData->m_cdh, szIpAddr, 16);
-  if (dataSocket.connect (szIpAddr, getPortNo (pFtpuserData->m_cdh)) < 0)
-    return 0;
+  if (dataSocket->connect (szIpAddr, getPortNo (pFtpuserData->m_cdh)) < 0)
+    {
+      delete dataSocket;
+      return 0;
+    }
 
   pFtpuserData->m_pDataConnection->setPort (getPortNo (pFtpuserData->m_cdh));
   pFtpuserData->m_pDataConnection->setLocalPort 
(pFtpuserData->m_nLocalDataport);
@@ -1616,7 +1618,7 @@ Ftp::openDataActive ()
   pFtpuserData->m_pDataConnection->setLocalIpAddr (td.pConnection->
                                                    getLocalIpAddr ());
   pFtpuserData->m_pDataConnection->host = td.pConnection->host;
-  pFtpuserData->m_pDataConnection->socket = new Socket (dataSocket);
+  pFtpuserData->m_pDataConnection->socket = dataSocket;
   pFtpuserData->m_pDataConnection->setScheduled (1);
 
   return 1;
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index c8c9fe4..ac54c39 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -955,7 +955,7 @@ u_long Server::getTimeout ()
 /*!
  * This function add a new connection to the list.
  */
-int Server::addConnection (Socket s, MYSERVER_SOCKADDRIN *asockIn)
+int Server::addConnection (Socket *s, MYSERVER_SOCKADDRIN *asockIn)
 {
 
   int ret = 0;
@@ -977,13 +977,19 @@ int Server::addConnection (Socket s, MYSERVER_SOCKADDRIN 
*asockIn)
    */
   if ( asockIn == NULL ||
        (asockIn->ss_family != AF_INET && asockIn->ss_family != AF_INET6))
-    return 0;
+    {
+      delete s;
+      return 0;
+    }
 
   memset (ip, 0, MAX_IP_STRING_LEN);
   memset (localIp, 0, MAX_IP_STRING_LEN);
 
-  if ( s.getHandle () == 0 )
-    return 0;
+  if (s->getHandle () < 0)
+    {
+      delete s;
+      return 0;
+    }
 
   /*
    * Do not accept this connection if a MAX_CONNECTIONS_TO_ACCEPT limit is
@@ -992,7 +998,10 @@ int Server::addConnection (Socket s, MYSERVER_SOCKADDRIN 
*asockIn)
   if (maxConnectionsToAccept
       && ((u_long)connectionsScheduler.getConnectionsNumber ()
           >= maxConnectionsToAccept))
-    return 0;
+    {
+      delete s;
+      return 0;
+    }
 
 #if ( HAVE_IPV6 )
   if ( asockIn->ss_family == AF_INET )
@@ -1004,13 +1013,16 @@ int Server::addConnection (Socket s, 
MYSERVER_SOCKADDRIN *asockIn)
                        sizeof (sockaddr_in6),  ip, MAX_IP_STRING_LEN,
                        NULL, 0, NI_NUMERICHOST);
   if (ret)
-    return 0;
+    {
+      delete s;
+      return 0;
+    }
 
   if ( asockIn->ss_family == AF_INET )
     dim = sizeof (sockaddr_in);
   else
     dim = sizeof (sockaddr_in6);
-  s.getsockname ((MYSERVER_SOCKADDR*)&localSockIn, &dim);
+  s->getsockname ((MYSERVER_SOCKADDR*)&localSockIn, &dim);
 
   if ( asockIn->ss_family == AF_INET )
     ret = getnameinfo (reinterpret_cast<const sockaddr *>(&localSockIn),
@@ -1024,7 +1036,7 @@ int Server::addConnection (Socket s, MYSERVER_SOCKADDRIN 
*asockIn)
     return 0;
 #else// !HAVE_IPV6
   dim = sizeof (localSockIn);
-  s.getsockname ((MYSERVER_SOCKADDR*)&localSockIn, &dim);
+  s->getsockname ((MYSERVER_SOCKADDR*)&localSockIn, &dim);
   strncpy (ip,  inet_ntoa (((sockaddr_in *)asockIn)->sin_addr),
            MAX_IP_STRING_LEN);
   strncpy (localIp,  inet_ntoa (((sockaddr_in *)&localSockIn)->sin_addr),
@@ -1047,16 +1059,18 @@ int Server::addConnection (Socket s, 
MYSERVER_SOCKADDRIN *asockIn)
     myPort = ntohs (((sockaddr_in6 *)(&localSockIn))->sin6_port);
 #endif
 
-  if (!addConnectionToList (&s, asockIn, &ip[0], &localIp[0], port, myPort, 1))
+  if (!addConnectionToList (s, asockIn, &ip[0], &localIp[0], port, myPort, 1))
     {
       /* If we report error to add the connection to the thread.  */
       ret = 0;
 
       /* Shutdown the socket both on receive that on send.  */
-      s.shutdown (2);
+      s->shutdown (2);
 
       /* Then close it.  */
-      s.close ();
+      s->close ();
+
+      delete s;
     }
   return ret;
 }
@@ -1114,7 +1128,6 @@ ConnectionPtr Server::addConnectionToList (Socket* s,
     }
 
   protocol = getProtocol (newConnection->host->getProtocolName ());
-
   if (protocol)
     opts = protocol->getProtocolOptions ();
 
@@ -1124,12 +1137,9 @@ ConnectionPtr Server::addConnectionToList (Socket* s,
   if (opts & PROTOCOL_FAST_CHECK)
     doFastCheck = 1;
 
-
-
   string msg ("new-connection");
 
   handlers = getHandlers (msg);
-
   if (handlers)
     {
       for (size_t i = 0; i < handlers->size (); i++)
@@ -1163,7 +1173,7 @@ ConnectionPtr Server::addConnectionToList (Socket* s,
       newConnection->socket = sslSocket;
     }
   else
-    newConnection->socket = new Socket (s);
+    newConnection->socket = s;
 
   if (doFastCheck)
     {

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

Summary of changes:
 myserver/include/base/file/file.h                  |    2 +
 myserver/include/base/pipe/pipe.h                  |   21 ++--
 myserver/include/base/socket/socket.h              |   11 +-
 myserver/include/base/socket/ssl_socket.h          |    2 +-
 myserver/include/base/unix_socket/unix_socket.h    |    3 +-
 .../connections_scheduler/connections_scheduler.h  |    3 +-
 myserver/include/server/server.h                   |    2 +-
 myserver/src/base/file/file.cpp                    |   17 +++-
 myserver/src/base/pipe/pipe.cpp                    |   37 +++++---
 .../src/base/read_directory/read_directory.cpp     |   11 ++-
 myserver/src/base/socket/socket.cpp                |  100 ++++++++++----------
 myserver/src/base/socket_pair/socket_pair.cpp      |   15 ++-
 myserver/src/base/unix_socket/unix_socket.cpp      |    9 ++-
 myserver/src/connection/connection.cpp             |    2 +-
 .../connections_scheduler.cpp                      |   53 +++++------
 myserver/src/http_handler/http_dir/http_dir.cpp    |    2 +-
 myserver/src/http_handler/http_file/http_file.cpp  |    4 +-
 myserver/src/http_handler/mscgi/mscgi_manager.cpp  |    2 +-
 myserver/src/protocol/ftp/ftp.cpp                  |   28 +++---
 myserver/src/protocol/http/http.cpp                |    4 +-
 myserver/src/server/server.cpp                     |   42 +++++---
 21 files changed, 202 insertions(+), 168 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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