Permalink
Browse files

SO_FAMILY (wip, needs change in stream_socket_server)

  • Loading branch information...
1 parent 22d4205 commit 19ec660ad4238a1f6739d5cc60b633b696046230 @cataphract committed Oct 23, 2012
Showing with 29 additions and 0 deletions.
  1. +12 −0 ext/sockets/sockets.c
  2. +17 −0 ext/sockets/tests/socket_import_stream-6.phpt
View
@@ -800,6 +800,9 @@ PHP_MINIT_FUNCTION(sockets)
REGISTER_LONG_CONSTANT("SO_SNDTIMEO", SO_SNDTIMEO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SO_RCVTIMEO", SO_RCVTIMEO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SO_TYPE", SO_TYPE, CONST_CS | CONST_PERSISTENT);
+#ifdef SO_FAMILY
+ REGISTER_LONG_CONSTANT("SO_FAMILY", SO_FAMILY, CONST_CS | CONST_PERSISTENT);
+#endif
REGISTER_LONG_CONSTANT("SO_ERROR", SO_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SOL_SOCKET", SOL_SOCKET, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SOMAXCONN", SOMAXCONN, CONST_CS | CONST_PERSISTENT);
@@ -2481,6 +2484,10 @@ PHP_FUNCTION(socket_import_stream)
#ifndef PHP_WIN32
int t;
#endif
+#ifdef SO_DOMAIN
+ int type;
+ socklen_t type_len = sizeof(type);
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) {
return;
@@ -2497,6 +2504,11 @@ PHP_FUNCTION(socket_import_stream)
retsock->bsd_socket = socket;
/* determine family */
+#ifdef SO_DOMAIN
+ if (getsockopt(socket, SOL_SOCKET, SO_DOMAIN, &type, &type_len) == 0) {
+ retsock->type = type;
+ } else
+#endif
if (getsockname(socket, (struct sockaddr*)&addr, &addr_len) == 0) {
retsock->type = addr.ss_family;
} else {
@@ -0,0 +1,17 @@
+--TEST--
+socket_import_stream: call on unbound stream
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+ die('SKIP sockets extension not available.');
+}
+--FILE--
+<?php
+
+$stream0 = stream_socket_server("udp://0.0.0.0:58380", $errno, $errstr, 0);
+var_dump(socket_import_stream($stream0));
+
+echo "Done.\n";
+--EXPECT--
+XXXXXXXXXX
+Done.

0 comments on commit 19ec660

Please sign in to comment.