Back to index

php5  5.3.10
Functions
fsock.c File Reference
#include "php.h"
#include "php_globals.h"
#include <stdlib.h>
#include <stddef.h>
#include "php_network.h"
#include "file.h"

Go to the source code of this file.

Functions

static void php_fsockopen_stream (INTERNAL_FUNCTION_PARAMETERS, int persistent)
 PHP_FUNCTION (fsockopen)
 PHP_FUNCTION (pfsockopen)

Function Documentation

static void php_fsockopen_stream ( INTERNAL_FUNCTION_PARAMETERS  ,
int  persistent 
) [static]

Definition at line 32 of file fsock.c.

{
       char *host;
       int host_len;
       long port = -1;
       zval *zerrno = NULL, *zerrstr = NULL;
       double timeout = FG(default_socket_timeout);
       unsigned long conv;
       struct timeval tv;
       char *hashkey = NULL;
       php_stream *stream = NULL;
       int err;
       char *hostname = NULL;
       long hostname_len;
       char *errstr = NULL;

       RETVAL_FALSE;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lzzd", &host, &host_len, &port, &zerrno, &zerrstr, &timeout) == FAILURE) {
              RETURN_FALSE;
       }

       if (persistent) {
              spprintf(&hashkey, 0, "pfsockopen__%s:%ld", host, port);
       }

       if (port > 0) {
              hostname_len = spprintf(&hostname, 0, "%s:%ld", host, port);
       } else {
              hostname_len = host_len;
              hostname = host;
       }
       
       /* prepare the timeout value for use */
       conv = (unsigned long) (timeout * 1000000.0);
       tv.tv_sec = conv / 1000000;
       tv.tv_usec = conv % 1000000;

       if (zerrno)   {
              zval_dtor(zerrno);
              ZVAL_LONG(zerrno, 0);
       }
       if (zerrstr) {
              zval_dtor(zerrstr);
              ZVAL_STRING(zerrstr, "", 1);
       }

       stream = php_stream_xport_create(hostname, hostname_len, ENFORCE_SAFE_MODE | REPORT_ERRORS,
                     STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err);

       if (port > 0) {
              efree(hostname);
       }
       if (stream == NULL) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%ld (%s)", host, port, errstr == NULL ? "Unknown error" : errstr);
       }

       if (hashkey) {
              efree(hashkey);
       }
       
       if (stream == NULL)  {
              if (zerrno) {
                     zval_dtor(zerrno);
                     ZVAL_LONG(zerrno, err);
              }
              if (zerrstr && errstr) {
                     /* no need to dup; we need to efree buf anyway */
                     zval_dtor(zerrstr);
                     ZVAL_STRING(zerrstr, errstr, 0);
              }
              else if (!zerrstr && errstr) {
                     efree(errstr);
              } 

              RETURN_FALSE;
       }

       if (errstr) {
              efree(errstr);
       }
              
       php_stream_to_zval(stream, return_value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( fsockopen  )

Definition at line 121 of file fsock.c.

Here is the call graph for this function:

PHP_FUNCTION ( pfsockopen  )

Definition at line 128 of file fsock.c.

Here is the call graph for this function: