2000-07-03 04:35:57 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2014-09-19 16:33:14 +00:00
|
|
|
| PHP Version 7 |
|
2000-07-03 04:35:57 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2015-01-15 15:27:30 +00:00
|
|
|
| Copyright (c) 1997-2015 The PHP Group |
|
2000-07-03 04:35:57 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2000-07-03 04:35:57 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| 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 |
|
2000-07-03 04:35:57 +00:00
|
|
|
| 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. |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-08-20 10:31:27 +00:00
|
|
|
| Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
|
2001-05-17 17:02:37 +00:00
|
|
|
| Sterling Hughes <sterling@php.net> |
|
|
|
|
| |
|
|
|
|
| WinSock: Daniel Beulshausen <daniel@php4win.de> |
|
2000-07-03 04:35:57 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2000-07-03 06:45:07 +00:00
|
|
|
#ifndef PHP_SOCKETS_H
|
|
|
|
#define PHP_SOCKETS_H
|
2000-07-03 04:35:57 +00:00
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2013-02-23 23:47:44 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-07-03 04:35:57 +00:00
|
|
|
#if HAVE_SOCKETS
|
|
|
|
|
2013-01-31 13:01:31 +00:00
|
|
|
#include <php.h>
|
Fix bug and hopefully build on WinSDK 6.1
There build was failing on rmtools on the sockets extension for two reasons:
1. IPV6_TCLASS and IPV6_RECVTCLASS not being defined. These are probably
recent additions to SDK. Windows 7 doesn't event seem to have complete
support for IPV6_TCLASS, not accepting in WSASendMsg(). The parts that
needed this constant were not guarded by #ifdefs. They are now.
2. The constants EWOULDBLOCK and EINPROGRESS not being defined. These
were only defined in php_network.h, outside of the extension, and not
all source files included this header. Nevertheless, a macro defined in
php_sockets.h needed these constants. When this macro was used in files
that did not include php_network.h, the compilation would fail.
Surprisingly, the build did not fail when using the 7.1 Windows SDK
(more likely, the CRT headers used in VC10), as somehow errno.h was
being included through some other standard header. This would make the
constant EWOULDBLOCK defined; however, it would be defined to the wrong
value. In the winsock context, WSAEWOULDBLOCK should be used instead.
Because we have difficulty using Windows-only constants in the code, we
(re)define EWOULDBLOCK to WSAEWOULDBLOCK. This has the obvious
disavantage we may miss problems like this again in the future.
2013-02-03 00:22:44 +00:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
# include "windows_common.h"
|
|
|
|
#endif
|
2013-01-31 13:01:31 +00:00
|
|
|
|
2000-07-03 04:35:57 +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>
|
2000-07-03 04:35:57 +00:00
|
|
|
#else
|
2001-11-06 14:35:26 +00:00
|
|
|
#if HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2000-07-03 04:35:57 +00:00
|
|
|
#endif
|
|
|
|
|
2001-07-25 22:03:55 +00:00
|
|
|
#ifndef PHP_WIN32
|
2003-06-17 04:44:30 +00:00
|
|
|
typedef int PHP_SOCKET;
|
2009-09-04 19:53:39 +00:00
|
|
|
# define PHP_SOCKETS_API PHPAPI
|
2003-06-17 04:44:30 +00:00
|
|
|
#else
|
2009-09-04 19:53:39 +00:00
|
|
|
# define PHP_SOCKETS_API __declspec(dllexport)
|
2003-06-17 04:44:30 +00:00
|
|
|
typedef SOCKET PHP_SOCKET;
|
2001-05-17 17:02:37 +00:00
|
|
|
#endif
|
2001-07-25 22:03:55 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2011-03-22 00:44:23 +00:00
|
|
|
PHP_SOCKET bsd_socket;
|
|
|
|
int type;
|
|
|
|
int error;
|
|
|
|
int blocking;
|
2014-05-17 02:23:46 +00:00
|
|
|
zval zstream;
|
2001-05-17 17:02:37 +00:00
|
|
|
} php_socket;
|
|
|
|
|
2009-01-23 15:49:49 +00:00
|
|
|
#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);
|
2014-11-10 11:31:21 +00:00
|
|
|
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
|
|
|
|
2009-12-27 01:00:50 +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; \
|
2013-02-02 14:43:05 +00:00
|
|
|
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-02 14:43:05 +00:00
|
|
|
} \
|
2013-02-01 13:39:56 +00:00
|
|
|
} while (0)
|
2001-11-01 22:40:43 +00:00
|
|
|
|
2002-04-29 14:52:29 +00:00
|
|
|
ZEND_BEGIN_MODULE_GLOBALS(sockets)
|
2002-09-30 02:09:42 +00:00
|
|
|
int last_error;
|
|
|
|
char *strerror_buf;
|
2002-04-29 14:52:29 +00:00
|
|
|
ZEND_END_MODULE_GLOBALS(sockets)
|
|
|
|
|
2000-07-03 04:35:57 +00:00
|
|
|
#ifdef ZTS
|
2014-10-05 18:48:32 +00:00
|
|
|
#define SOCKETS_G(v) ZEND_TSRMG(sockets_globals_id, zend_sockets_globals *, v)
|
2000-07-03 04:35:57 +00:00
|
|
|
#else
|
2002-04-29 14:52:29 +00:00
|
|
|
#define SOCKETS_G(v) (sockets_globals.v)
|
2000-07-03 04:35:57 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-01 19:38:42 +00:00
|
|
|
ZEND_EXTERN_MODULE_GLOBALS(sockets);
|
|
|
|
|
2012-11-06 11:48:47 +00:00
|
|
|
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);
|
2012-11-01 19:38:42 +00:00
|
|
|
|
2000-07-03 04:35:57 +00:00
|
|
|
#else
|
|
|
|
#define phpext_sockets_ptr NULL
|
|
|
|
#endif
|
|
|
|
|
2014-01-01 11:55:14 +00:00
|
|
|
#if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY)
|
|
|
|
# define ss_family __ss_family
|
|
|
|
#endif
|
|
|
|
|
2001-05-17 17:02:37 +00:00
|
|
|
#endif
|
2000-07-03 04:35:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-05-21 19:36:22 +00:00
|
|
|
*/
|
|
|
|
|