root/ext/sockets/php_sockets.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 7                                                        |
   4    +----------------------------------------------------------------------+
   5    | Copyright (c) 1997-2016 The PHP Group                                |
   6    +----------------------------------------------------------------------+
   7    | This source file is subject to version 3.01 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_01.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: Chris Vandomelen <chrisv@b0rked.dhs.org>                    |
  16    |          Sterling Hughes  <sterling@php.net>                         |
  17    |                                                                      |
  18    | WinSock: Daniel Beulshausen <daniel@php4win.de>                      |
  19    +----------------------------------------------------------------------+
  20  */
  21 
  22 #ifndef PHP_SOCKETS_H
  23 #define PHP_SOCKETS_H
  24 
  25 /* $Id$ */
  26 
  27 #if HAVE_CONFIG_H
  28 # include "config.h"
  29 #endif
  30 
  31 #if HAVE_SOCKETS
  32 
  33 #include <php.h>
  34 #ifdef PHP_WIN32
  35 # include "windows_common.h"
  36 #endif
  37 
  38 #define PHP_SOCKETS_VERSION PHP_VERSION
  39 
  40 extern zend_module_entry sockets_module_entry;
  41 #define phpext_sockets_ptr &sockets_module_entry
  42 
  43 #ifdef PHP_WIN32
  44 #include <Winsock2.h>
  45 #else
  46 #if HAVE_SYS_SOCKET_H
  47 #include <sys/socket.h>
  48 #endif
  49 #endif
  50 
  51 #ifndef PHP_WIN32
  52 typedef int PHP_SOCKET;
  53 # define PHP_SOCKETS_API PHPAPI
  54 #else
  55 # define PHP_SOCKETS_API __declspec(dllexport)
  56 typedef SOCKET PHP_SOCKET;
  57 #endif
  58 
  59 typedef struct {
  60         PHP_SOCKET      bsd_socket;
  61         int                     type;
  62         int                     error;
  63         int                     blocking;
  64         zval            zstream;
  65 } php_socket;
  66 
  67 #ifdef PHP_WIN32
  68 struct  sockaddr_un {
  69         short   sun_family;
  70         char    sun_path[108];
  71 };
  72 #endif
  73 
  74 PHP_SOCKETS_API int php_sockets_le_socket(void);
  75 PHP_SOCKETS_API php_socket *php_create_socket(void);
  76 PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc);
  77 
  78 #define php_sockets_le_socket_name "Socket"
  79 
  80 #define PHP_SOCKET_ERROR(socket, msg, errn) \
  81                 do { \
  82                         int _err = (errn); /* save value to avoid repeated calls to WSAGetLastError() on Windows */ \
  83                         (socket)->error = _err; \
  84                         SOCKETS_G(last_error) = _err; \
  85                         if (_err != EAGAIN && _err != EWOULDBLOCK && _err != EINPROGRESS) { \
  86                                 php_error_docref(NULL, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err)); \
  87                         } \
  88                 } while (0)
  89 
  90 ZEND_BEGIN_MODULE_GLOBALS(sockets)
  91         int last_error;
  92         char *strerror_buf;
  93 ZEND_END_MODULE_GLOBALS(sockets)
  94 
  95 ZEND_EXTERN_MODULE_GLOBALS(sockets)
  96 #define SOCKETS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sockets, v)
  97 
  98 enum sockopt_return {
  99         SOCKOPT_ERROR,
 100         SOCKOPT_CONTINUE,
 101         SOCKOPT_SUCCESS
 102 };
 103 
 104 char *sockets_strerror(int error);
 105 php_socket *socket_import_file_descriptor(PHP_SOCKET sock);
 106 
 107 #else
 108 #define phpext_sockets_ptr NULL
 109 #endif
 110 
 111 #if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY)
 112 # define ss_family __ss_family
 113 #endif
 114 
 115 #endif
 116 
 117 /*
 118  * Local variables:
 119  * tab-width: 4
 120  * c-basic-offset: 4
 121  * End:
 122  */
 123 

/* [<][>][^][v][top][bottom][index][help] */