Skip to content

Commit f51efd0

Browse files
committed
Remove unnecessary code related to select IO multiplexing.
1 parent 9cd7200 commit f51efd0

File tree

2 files changed

+0
-126
lines changed

2 files changed

+0
-126
lines changed

ext-src/php_swoole_private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ BEGIN_EXTERN_C()
4444
#include <ext/standard/php_http.h>
4545

4646
#define PHP_SWOOLE_VERSION SWOOLE_VERSION
47-
#define PHP_SWOOLE_CLIENT_USE_POLL
4847

4948
extern PHPAPI int php_array_merge(zend_array *dest, zend_array *src);
5049

ext-src/swoole_client.cc

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,8 @@ static PHP_METHOD(swoole_client, getSocket);
101101
#endif
102102
SW_EXTERN_C_END
103103

104-
#ifdef PHP_SWOOLE_CLIENT_USE_POLL
105104
static uint32_t client_poll_add(zval *sock_array, uint32_t index, struct pollfd *fds, int maxevents, int event);
106105
static int client_poll_wait(zval *sock_array, struct pollfd *fds, int maxevents, int n_event, int revent);
107-
#else
108-
static int client_select_add(zval *sock_array, fd_set *fds, int *max_fd);
109-
static int client_select_wait(zval *sock_array, fd_set *fds);
110-
#endif
111106

112107
Client *php_swoole_client_get_cli_safe(zval *zobject) {
113108
Client *cli = php_swoole_client_get_cli(zobject);
@@ -1211,7 +1206,6 @@ static PHP_METHOD(swoole_client, shutdown) {
12111206
}
12121207

12131208
PHP_FUNCTION(swoole_client_select) {
1214-
#ifdef PHP_SWOOLE_CLIENT_USE_POLL
12151209
zval *r_array, *w_array, *e_array;
12161210
int retval;
12171211
uint32_t index = 0;
@@ -1265,58 +1259,8 @@ PHP_FUNCTION(swoole_client_select) {
12651259
}
12661260
efree(fds);
12671261
RETURN_LONG(retval);
1268-
#else
1269-
zval *r_array, *w_array, *e_array;
1270-
fd_set rfds, wfds, efds;
1271-
1272-
int max_fd = 0;
1273-
int retval, sets = 0;
1274-
double timeout = SW_CLIENT_CONNECT_TIMEOUT;
1275-
struct timeval timeo;
1276-
1277-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a!a!a!|d", &r_array, &w_array, &e_array, &timeout) == FAILURE) {
1278-
RETURN_FALSE;
1279-
}
1280-
1281-
FD_ZERO(&rfds);
1282-
FD_ZERO(&wfds);
1283-
FD_ZERO(&efds);
1284-
1285-
if (r_array != nullptr) sets += client_select_add(r_array, &rfds, &max_fd);
1286-
if (w_array != nullptr) sets += client_select_add(w_array, &wfds, &max_fd);
1287-
if (e_array != nullptr) sets += client_select_add(e_array, &efds, &max_fd);
1288-
1289-
if (!sets) {
1290-
php_swoole_fatal_error(E_WARNING, "no resource arrays were passed to select");
1291-
RETURN_FALSE;
1292-
}
1293-
1294-
if (max_fd >= FD_SETSIZE) {
1295-
php_swoole_fatal_error(E_WARNING, "select max_fd > FD_SETSIZE[%d]", FD_SETSIZE);
1296-
RETURN_FALSE;
1297-
}
1298-
timeo.tv_sec = (int) timeout;
1299-
timeo.tv_usec = (int) ((timeout - timeo.tv_sec) * 1000 * 1000);
1300-
1301-
retval = select(max_fd + 1, &rfds, &wfds, &efds, &timeo);
1302-
if (retval == -1) {
1303-
php_swoole_sys_error(E_WARNING, "unable to select");
1304-
RETURN_FALSE;
1305-
}
1306-
if (r_array != nullptr) {
1307-
client_select_wait(r_array, &rfds);
1308-
}
1309-
if (w_array != nullptr) {
1310-
client_select_wait(w_array, &wfds);
1311-
}
1312-
if (e_array != nullptr) {
1313-
client_select_wait(e_array, &efds);
1314-
}
1315-
RETURN_LONG(retval);
1316-
#endif
13171262
}
13181263

1319-
#ifdef PHP_SWOOLE_CLIENT_USE_POLL
13201264
static inline int client_poll_get(struct pollfd *fds, int maxevents, int fd) {
13211265
int i;
13221266
for (i = 0; i < maxevents; i++) {
@@ -1402,72 +1346,3 @@ static uint32_t client_poll_add(zval *sock_array, uint32_t index, struct pollfd
14021346

14031347
return index;
14041348
}
1405-
#else
1406-
static int client_select_wait(zval *sock_array, fd_set *fds) {
1407-
zval *element = nullptr;
1408-
int sock;
1409-
1410-
ulong_t num = 0;
1411-
if (!ZVAL_IS_ARRAY(sock_array)) {
1412-
return 0;
1413-
}
1414-
1415-
zval new_array;
1416-
array_init(&new_array);
1417-
zend_ulong num_key;
1418-
zend_string *key;
1419-
zval *dest_element;
1420-
1421-
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(sock_array), num_key, key, element) {
1422-
sock = php_swoole_convert_to_fd(element);
1423-
if (sock < 0) {
1424-
continue;
1425-
}
1426-
if ((sock < FD_SETSIZE) && FD_ISSET(sock, fds)) {
1427-
if (key) {
1428-
dest_element = zend_hash_add(Z_ARRVAL(new_array), key, element);
1429-
} else {
1430-
dest_element = zend_hash_index_update(Z_ARRVAL(new_array), num_key, element);
1431-
}
1432-
if (dest_element) {
1433-
Z_ADDREF_P(dest_element);
1434-
}
1435-
}
1436-
num++;
1437-
}
1438-
ZEND_HASH_FOREACH_END();
1439-
1440-
zval_ptr_dtor(sock_array);
1441-
ZVAL_COPY_VALUE(sock_array, &new_array);
1442-
return num ? 1 : 0;
1443-
}
1444-
1445-
static int client_select_add(zval *sock_array, fd_set *fds, int *max_fd) {
1446-
zval *element = nullptr;
1447-
if (!ZVAL_IS_ARRAY(sock_array)) {
1448-
return 0;
1449-
}
1450-
1451-
int sock;
1452-
int num = 0;
1453-
1454-
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(sock_array), element)
1455-
sock = php_swoole_convert_to_fd(element);
1456-
if (sock < 0) {
1457-
continue;
1458-
}
1459-
if (sock < FD_SETSIZE) {
1460-
FD_SET(sock, fds);
1461-
} else {
1462-
php_swoole_fatal_error(E_WARNING, "socket[%d] > FD_SETSIZE[%d]", sock, FD_SETSIZE);
1463-
continue;
1464-
}
1465-
if (sock > *max_fd) {
1466-
*max_fd = sock;
1467-
}
1468-
num++;
1469-
SW_HASHTABLE_FOREACH_END();
1470-
1471-
return num ? 1 : 0;
1472-
}
1473-
#endif

0 commit comments

Comments
 (0)