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-105-


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-105-gbd9d319
Date: Wed, 07 Apr 2010 23:10:05 +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  bd9d319c5d2fb1314cf89184dc91d416523aa26e (commit)
       via  49a6ab8cf8e1d68f09c0fe883d087208d5fe3c9d (commit)
      from  a9728d229b5c46dd2b654325dd4dba011dd4e7cd (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 bd9d319c5d2fb1314cf89184dc91d416523aa26e
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Apr 8 01:08:31 2010 +0200

    Use an union to compound messages for `sendmsg' and `recvmsg'.
    
    Add a test to exercise `readFileHandle' and `writeFileHandle'.

diff --git a/myserver/src/base/utility.cpp b/myserver/src/base/utility.cpp
index 06ea7ff..4b8464e 100644
--- a/myserver/src/base/utility.cpp
+++ b/myserver/src/base/utility.cpp
@@ -223,25 +223,29 @@ int readFileHandle (SocketHandle s, Handle* fd)
   return -1;
 #else
   struct msghdr mh;
-  struct cmsghdr cmh[2];
+  union
+  {
+    struct cmsghdr cmh;
+    char buffer[CMSG_SPACE (sizeof (int))];
+  } cmh;
+  char tbuf[4];
   struct iovec iov;
   int ret;
-  char tbuf[4];
   mh.msg_name = 0;
   mh.msg_namelen = 0;
   mh.msg_iov = &iov;
   mh.msg_iovlen = 1;
-  mh.msg_control = (caddr_t)&cmh[0];
-  mh.msg_controllen = sizeof (cmh[0]) * 2;
+  mh.msg_control = (caddr_t) &cmh;
+  mh.msg_controllen = sizeof (cmh);
   iov.iov_base = tbuf;
   iov.iov_len = 4;
-  cmh[0].cmsg_len = sizeof (cmh[0]) + sizeof (int);
-  ret = recvmsg (s, &mh, 0);
+  cmh.cmh.cmsg_len = sizeof (cmh);
 
+  ret = recvmsg (s, &mh, 0);
   if (ret < 0)
     return ret;
 
-  *fd = *(FileHandle *)&cmh[1];
+  *fd = *((int *) CMSG_DATA (CMSG_FIRSTHDR (&mh)));
 
   return 0;
 #endif
@@ -259,23 +263,28 @@ int writeFileHandle (SocketHandle s, Handle fd)
   return -1;
 #else
   struct msghdr mh;
-  struct cmsghdr cmh[2];
-  struct iovec iov;
+  union
+  {
+    struct cmsghdr cmh;
+    char buffer[CMSG_SPACE (sizeof (int))];
+  } cmh;
   char tbuf[4];
-  memset (&mh,0,sizeof (mh));
+  struct iovec iov;
+  memset (&mh, 0, sizeof (mh));
   mh.msg_name = 0;
   mh.msg_namelen = 0;
   mh.msg_iov = &iov;
   mh.msg_iovlen = 1;
-  mh.msg_control = (caddr_t)&cmh[0];
-  mh.msg_controllen = sizeof (cmh[0]) + sizeof (int);
+  mh.msg_control = (caddr_t) &cmh;
+  mh.msg_controllen = sizeof (cmh);
   mh.msg_flags = 0;
   iov.iov_base = tbuf;
   iov.iov_len = 4;
-  cmh[0].cmsg_level = SOL_SOCKET;
-  cmh[0].cmsg_type = SCM_RIGHTS;
-  cmh[0].cmsg_len = sizeof (cmh[0]) + sizeof (int);
-  *(int *)&cmh[1] = fd;
+  cmh.cmh.cmsg_level = SOL_SOCKET;
+  cmh.cmh.cmsg_type = SCM_RIGHTS;
+  cmh.cmh.cmsg_len = sizeof (cmh);
+  *((int *) CMSG_DATA (&cmh.cmh)) = fd;
+
   return sendmsg (s, &mh, 0);
 #endif
 }
diff --git a/myserver/tests/test_unix_socket.cpp 
b/myserver/tests/test_unix_socket.cpp
index b6ea1c9..b4e073e 100644
--- a/myserver/tests/test_unix_socket.cpp
+++ b/myserver/tests/test_unix_socket.cpp
@@ -27,6 +27,7 @@
 #include <include/base/file/files_utility.h>
 #include <include/base/unix_socket/unix_socket.h>
 #include <include/base/thread/thread.h>
+#include <include/base/pipe/pipe.h>
 #include <string.h>
 
 #ifdef AF_UNIX
@@ -70,6 +71,7 @@ class TestUnixSocket : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE ( TestUnixSocket );
   CPPUNIT_TEST ( testBind );
   CPPUNIT_TEST ( testClient );
+  CPPUNIT_TEST ( testReadWriteHandle );
   CPPUNIT_TEST_SUITE_END ();
 
   UnixSocket *sock;
@@ -136,6 +138,45 @@ public:
 
     CPPUNIT_ASSERT_EQUAL (data.result, true);
   }
+
+
+  void testReadWriteHandle ()
+  {
+# ifndef WIN32
+    const char *msg = "hello world";
+    ThreadID tid;
+    Pipe pipe;
+    u_long nbw;
+    char buffer[64];
+    string path;
+    FilesUtility::temporaryFileName (0, path);
+    sock->socket ();
+    sock->bind (path.c_str ());
+    CPPUNIT_ASSERT_EQUAL (sock->listen (1), 0);
+
+    pipe.create ();
+    CPPUNIT_ASSERT (! pipe.write (msg, strlen (msg), &nbw));
+
+    UnixSocket client;
+    client.socket ();
+    CPPUNIT_ASSERT_EQUAL (client.connect (path.c_str ()), 0);
+
+    Socket clientRecv = sock->accept ();
+    Handle fd;
+
+    CPPUNIT_ASSERT (writeFileHandle (client.getHandle (), pipe.getReadHandle 
()) >= 0);
+    CPPUNIT_ASSERT (readFileHandle (clientRecv.getHandle (), &fd) >= 0);
+
+    CPPUNIT_ASSERT (read (fd, buffer, 64) > 0);
+
+    CPPUNIT_ASSERT_EQUAL (strcmp (buffer, msg), 0);
+
+    clientRecv.close ();
+    client.shutdown ();
+    client.close ();
+# endif
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION ( TestUnixSocket );



commit 49a6ab8cf8e1d68f09c0fe883d087208d5fe3c9d
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Apr 8 00:43:10 2010 +0200

    Amend to the last commit

diff --git a/myserver/tests/test_safetime.cpp b/myserver/tests/test_safetime.cpp
index e6c8af7..3b458fd 100644
--- a/myserver/tests/test_safetime.cpp
+++ b/myserver/tests/test_safetime.cpp
@@ -50,7 +50,7 @@ public:
   void testLocalTime ()
   {
     tm res;
-    time_t timep = 60 * 60 *4 + 10;
+    time_t timep = 60 * 60 * 24 + 10;
     tm *outRes = myserver_localtime (&timep, &res);
 
     CPPUNIT_ASSERT (outRes);

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

Summary of changes:
 myserver/src/base/utility.cpp       |   41 +++++++++++++++++++++-------------
 myserver/tests/test_safetime.cpp    |    2 +-
 myserver/tests/test_unix_socket.cpp |   41 +++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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