php-src/ext/sockets/php_sockets.h

127 lines
3.3 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
+----------------------------------------------------------------------+
2015-01-15 15:27:30 +00:00
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
2006-01-01 12:51:34 +00:00
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
| Sterling Hughes <sterling@php.net> |
| |
| WinSock: Daniel Beulshausen <daniel@php4win.de> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SOCKETS_H
#define PHP_SOCKETS_H
/* $Id$ */
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_SOCKETS
2013-01-31 13:01:31 +00:00
#include <php.h>
#ifdef PHP_WIN32
# include "windows_common.h"
#endif
2013-01-31 13:01:31 +00:00
extern zend_module_entry sockets_module_entry;
#define phpext_sockets_ptr &sockets_module_entry
#ifdef PHP_WIN32
2013-01-31 13:01:31 +00:00
#include <Winsock2.h>
#else
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
#ifndef PHP_WIN32
typedef int PHP_SOCKET;
2009-09-04 19:53:39 +00:00
# define PHP_SOCKETS_API PHPAPI
#else
2009-09-04 19:53:39 +00:00
# define PHP_SOCKETS_API __declspec(dllexport)
typedef SOCKET PHP_SOCKET;
#endif
typedef struct {
PHP_SOCKET bsd_socket;
int type;
int error;
int blocking;
zval zstream;
} php_socket;
#ifdef PHP_WIN32
struct sockaddr_un {
short sun_family;
char sun_path[108];
};
#endif
2009-09-04 19:53:39 +00:00
PHP_SOCKETS_API int php_sockets_le_socket(void);
PHP_SOCKETS_API php_socket *php_create_socket(void);
2014-12-13 22:06:14 +00:00
PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc);
2009-08-31 08:41:03 +00:00
#define php_sockets_le_socket_name "Socket"
2013-02-01 13:39:56 +00:00
#define PHP_SOCKET_ERROR(socket, msg, errn) \
do { \
int _err = (errn); /* save value to avoid repeated calls to WSAGetLastError() on Windows */ \
(socket)->error = _err; \
SOCKETS_G(last_error) = _err; \
if (_err != EAGAIN && _err != EWOULDBLOCK && _err != EINPROGRESS) { \
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err)); \
} \
2013-02-01 13:39:56 +00:00
} while (0)
2001-11-01 22:40:43 +00:00
ZEND_BEGIN_MODULE_GLOBALS(sockets)
2002-09-30 02:09:42 +00:00
int last_error;
char *strerror_buf;
ZEND_END_MODULE_GLOBALS(sockets)
#ifdef ZTS
#define SOCKETS_G(v) ZEND_TSRMG(sockets_globals_id, zend_sockets_globals *, v)
#else
#define SOCKETS_G(v) (sockets_globals.v)
#endif
ZEND_EXTERN_MODULE_GLOBALS(sockets);
enum sockopt_return {
SOCKOPT_ERROR,
SOCKOPT_CONTINUE,
SOCKOPT_SUCCESS
};
2014-12-13 22:06:14 +00:00
char *sockets_strerror(int error);
php_socket *socket_import_file_descriptor(PHP_SOCKET sock);
#else
#define phpext_sockets_ptr NULL
#endif
#if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY)
# define ss_family __ss_family
#endif
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
2001-05-21 19:36:22 +00:00
*/