Skip to content

Commit 1bb6605

Browse files
committed
fix(windows): link sockets and share affinity helpers --filter=[win-unit]
1 parent 4ba262f commit 1bb6605

3 files changed

Lines changed: 42 additions & 36 deletions

File tree

config.w32

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ if (PHP_SWOOLE != "no") {
350350
ADD_EXTENSION_DEP("swoole", "curl");
351351
}
352352

353+
if (PHP_PHP_SOCKETS == "yes") {
354+
ADD_EXTENSION_DEP("swoole", "sockets");
355+
}
356+
353357
if (PHP_SWOOLE_SQLITE == "yes") {
354358
ADD_EXTENSION_DEP("swoole", "pdo");
355359
}

ext-src/php_swoole_cxx.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,44 @@ zend_refcounted *sw_get_refcount_ptr(zval *value) {
1616
return (sw_refcount_ptr = value->value.counted);
1717
}
1818

19+
#ifdef HAVE_CPU_AFFINITY
20+
bool php_swoole_array_to_cpu_set(const zval *array, cpu_set_t *cpu_set) {
21+
if (php_swoole_array_length(array) == 0) {
22+
return false;
23+
}
24+
25+
const zend_long cpu_num = SW_MIN((zend_long) SW_CPU_NUM, (zend_long) CPU_SETSIZE);
26+
if ((zend_long) php_swoole_array_length(array) > cpu_num) {
27+
php_swoole_fatal_error(E_WARNING, "More than the number of CPU");
28+
return false;
29+
}
30+
31+
zval *value = nullptr;
32+
CPU_ZERO(cpu_set);
33+
34+
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(array), value)
35+
if (zval_get_long(value) < 0 || zval_get_long(value) >= cpu_num) {
36+
php_swoole_fatal_error(E_WARNING, "invalid cpu id [%d]", (int) Z_LVAL_P(value));
37+
return false;
38+
}
39+
CPU_SET(Z_LVAL_P(value), cpu_set);
40+
SW_HASHTABLE_FOREACH_END();
41+
42+
return true;
43+
}
44+
45+
void php_swoole_cpu_set_to_array(zval *array, cpu_set_t *cpu_set) {
46+
array_init(array);
47+
48+
int cpu_n = SW_MIN(SW_CPU_NUM, CPU_SETSIZE);
49+
SW_LOOP_N(cpu_n) {
50+
if (CPU_ISSET(i, cpu_set)) {
51+
add_next_index_long(array, i);
52+
}
53+
}
54+
}
55+
#endif
56+
1957
//----------------------------------known string------------------------------------
2058
namespace zend {
2159
void known_strings_init() {

ext-src/swoole_process.cc

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -989,42 +989,6 @@ static PHP_METHOD(swoole_process, daemon) {
989989
}
990990

991991
#ifdef HAVE_CPU_AFFINITY
992-
bool php_swoole_array_to_cpu_set(const zval *array, cpu_set_t *cpu_set) {
993-
if (php_swoole_array_length(array) == 0) {
994-
return false;
995-
}
996-
997-
const zend_long cpu_num = SW_MIN((zend_long) SW_CPU_NUM, (zend_long) CPU_SETSIZE);
998-
if ((zend_long) php_swoole_array_length(array) > cpu_num) {
999-
php_swoole_fatal_error(E_WARNING, "More than the number of CPU");
1000-
return false;
1001-
}
1002-
1003-
zval *value = nullptr;
1004-
CPU_ZERO(cpu_set);
1005-
1006-
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(array), value)
1007-
if (zval_get_long(value) < 0 || zval_get_long(value) >= cpu_num) {
1008-
php_swoole_fatal_error(E_WARNING, "invalid cpu id [%d]", (int) Z_LVAL_P(value));
1009-
return false;
1010-
}
1011-
CPU_SET(Z_LVAL_P(value), cpu_set);
1012-
SW_HASHTABLE_FOREACH_END();
1013-
1014-
return true;
1015-
}
1016-
1017-
void php_swoole_cpu_set_to_array(zval *array, cpu_set_t *cpu_set) {
1018-
array_init(array);
1019-
1020-
int cpu_n = SW_MIN(SW_CPU_NUM, CPU_SETSIZE);
1021-
SW_LOOP_N(cpu_n) {
1022-
if (CPU_ISSET(i, cpu_set)) {
1023-
add_next_index_long(array, i);
1024-
}
1025-
}
1026-
}
1027-
1028992
static PHP_METHOD(swoole_process, setAffinity) {
1029993
zval *array;
1030994
ZEND_PARSE_PARAMETERS_START(1, 1)

0 commit comments

Comments
 (0)