2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 of the PHP license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.php.net/license/3_0.txt. |
11
| If you did not receive a copy of the PHP license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@php.net so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Authors: Paul Panotzki - Bunyip Information Systems |
16
| Jim Winstead <jimw@php.net> |
17
| Sascha Schumann <sascha@schumann.cx> |
18
+----------------------------------------------------------------------+
21
/* $Id: fsock.c,v 1.120 2004/06/16 23:57:25 abies Exp $ */
24
#include "php_globals.h"
27
#include "php_network.h"
30
/* {{{ php_fsockopen() */
32
static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
37
zval *zerrno = NULL, *zerrstr = NULL;
38
double timeout = FG(default_socket_timeout);
42
php_stream *stream = NULL;
44
char *hostname = NULL;
50
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lzzd", &host, &host_len, &port, &zerrno, &zerrstr, &timeout) == FAILURE) {
55
spprintf(&hashkey, 0, "pfsockopen__%s:%ld", host, port);
59
hostname_len = spprintf(&hostname, 0, "%s:%ld", host, port);
61
hostname_len = host_len;
65
/* prepare the timeout value for use */
66
conv = (unsigned long) (timeout * 1000000.0);
67
tv.tv_sec = conv / 1000000;
68
tv.tv_usec = conv % 1000000;
76
ZVAL_STRING(zerrstr, "", 1);
79
stream = php_stream_xport_create(hostname, hostname_len, ENFORCE_SAFE_MODE | REPORT_ERRORS,
80
STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err);
86
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%ld (%s)", host, port, errstr == NULL ? "Unknown error" : errstr);
96
ZVAL_LONG(zerrno, err);
98
if (zerrstr && errstr) {
99
/* no need to dup; we need to efree buf anyway */
101
ZVAL_STRING(zerrstr, errstr, 0);
103
else if (!zerrstr && errstr) {
114
php_stream_to_zval(stream, return_value);
119
/* {{{ proto resource fsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]])
120
Open Internet or Unix domain socket connection */
121
PHP_FUNCTION(fsockopen)
123
php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
126
/* {{{ proto resource pfsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]])
127
Open persistent Internet or Unix domain socket connection */
128
PHP_FUNCTION(pfsockopen)
130
php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
139
* vim600: sw=4 ts=4 fdm=marker