control socket added to receive socket-related data
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Thu, 28 Jun 2012 05:34:49 +0000 (07:34 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Thu, 28 Jun 2012 05:34:49 +0000 (07:34 +0200)
php-ancillary.c

index 115221a..4907812 100644 (file)
@@ -3,6 +3,10 @@
 #endif
 #include "php.h"
 #include <ancillary.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
  
 #define PHP_ANCILLARY_VERSION "1.0"
 #define PHP_ANCILLARY_EXTNAME "ancillary"
@@ -45,7 +49,12 @@ PHP_FUNCTION(ancillary_getstream)
 {
     zval *zstream;
     php_stream *stream;
-    int fd_in, fd_out;
+    int fd_in, fd_out[2];
+    char *headers;
+
+    if ((headers = calloc(8*1024, 1)) == NULL) {
+        return;
+    }
 
     if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream))
         return;
@@ -56,11 +65,25 @@ PHP_FUNCTION(ancillary_getstream)
         RETURN_FALSE;
     }
 
-    if(ancil_recv_fd(fd_in, &fd_out)) {
+    if(ancil_recv_fds(fd_in, fd_out, 2) == 0) {
         RETURN_FALSE;
     }
+    {
+        char bf[2048];
+
+        sprintf(bf, "zero: [%d]    uno: [%d]\n", fd_out[0], fd_out[1]);
+        write(1, bf, strlen(bf));
+    }
+    {
+        int fh;
+
+        if ((fh = open("/tmp/out_php-anc.txt", O_WRONLY | O_CREAT | O_APPEND)) > -1) {
+            // write(fh, headers, 8*1024);
+            close(fh);
+        }
+    }
 
-    if ((stream = php_stream_fopen_from_fd(fd_out, "r+b", NULL)) == NULL) {
+    if ((stream = php_stream_fopen_from_fd(fd_out[0], "r+b", NULL)) == NULL) {
         RETURN_FALSE;
     }