gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash/libbase network.cpp network.h


From: Rob Savoye
Subject: [Gnash-commit] gnash/libbase network.cpp network.h
Date: Sat, 15 Sep 2007 04:03:14 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    07/09/15 04:03:14

Modified files:
        libbase        : network.cpp network.h 

Log message:
                * libbase/network.cpp, network.h: Add connectSocket() for 
talking
                to named pipes. 

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/network.cpp?cvsroot=gnash&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/network.h?cvsroot=gnash&r1=1.20&r2=1.21

Patches:
Index: network.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/network.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- network.cpp 16 Aug 2007 18:10:08 -0000      1.30
+++ network.cpp 15 Sep 2007 04:03:13 -0000      1.31
@@ -43,6 +43,7 @@
 # include <netinet/in.h>
 # include <arpa/inet.h>
 # include <sys/socket.h>
+# include <sys/un.h>
 # include <netdb.h>
 # include <sys/param.h>
 # include <sys/select.h>
@@ -299,6 +300,98 @@
     return true;
 }
 
+// Connect to a named pipe
+bool
+Network::connectSocket(const char *sockname)
+{
+    GNASH_REPORT_FUNCTION;
+
+    struct sockaddr_un  addr;
+    fd_set              fdset;
+    struct timeval      tval;
+    int                 ret;
+    int                 retries;
+
+    addr.sun_family = AF_UNIX;
+    // socket names must be 108 bytes or less as specifiec in sys/un.h.
+    strncpy(addr.sun_path, sockname, 100);
+
+    _sockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
+    if (_sockfd < 0)
+        {
+            log_error(_("unable to create socket: %s"), strerror(errno));
+            _sockfd = -1;
+            return false;
+        }
+
+    retries = 2;
+    while (retries-- > 0) {
+        // We use select to wait for the read file descriptor to be
+        // active, which means there is a client waiting to connect.
+        FD_ZERO(&fdset);
+        FD_SET(_sockfd, &fdset);
+
+        // Reset the timeout value, since select modifies it on return. To
+        // block, set the timeout to zero.
+        tval.tv_sec = 5;
+        tval.tv_usec = 0;
+
+        ret = ::select(_sockfd+1, &fdset, NULL, NULL, &tval);
+
+        // If interupted by a system call, try again
+        if (ret == -1 && errno == EINTR)
+            {
+                log_msg(_("The connect() socket for fd %d was interupted by a 
system call"),
+                        _sockfd);
+                continue;
+            }
+
+        if (ret == -1)
+            {
+                log_msg(_("The connect() socket for fd %d never was available 
for writing"),
+                        _sockfd);
+#ifdef HAVE_WINSOCK_H
+                ::shutdown(_sockfd, 0); // FIXME: was SHUT_BOTH
+#else
+                ::shutdown(_sockfd, SHUT_RDWR);
+#endif
+                _sockfd = -1;
+                return false;
+            }
+        if (ret == 0) {
+            log_error(_("The connect() socket for fd %d timed out waiting to 
write"),
+                      _sockfd);
+            continue;
+        }
+
+        if (ret > 0) {
+            ret = ::connect(_sockfd, reinterpret_cast<struct sockaddr 
*>(&addr), sizeof(addr));
+            if (ret == 0) {
+                log_msg(_("\tsocket name %s for fd %d"), sockname, _sockfd);
+                _connected = true;
+                assert(_sockfd > 0);
+                return true;
+            }
+            if (ret == -1) {
+                log_error(_("The connect() socket for fd %d never was 
available for writing"),
+                        _sockfd);
+                _sockfd = -1;
+                assert(!_connected);
+                return false;
+            }
+        }
+    }
+    
+
+#ifndef HAVE_WINSOCK_H
+    fcntl(_sockfd, F_SETFL, O_NONBLOCK);
+#endif
+
+    _connected = true;
+    assert(_sockfd > 0);
+    return true;    
+}
+
 // Create a client connection to a tcp/ip based service
 bool
 Network::createClient(void)

Index: network.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/network.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- network.h   10 Aug 2007 14:06:35 -0000      1.20
+++ network.h   15 Sep 2007 04:03:13 -0000      1.21
@@ -71,6 +71,9 @@
     bool newConnection(void);
     bool newConnection(bool block);
     
+    // Connect to a named pipe
+    bool connectSocket(const char *sock);
+
     // Create a client connection to a tcp/ip server
     bool createClient(void);
     bool createClient(short port);




reply via email to

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