Skip to content

Commit a2f3554

Browse files
committed
ext/sockets update the sock_filter usage for the CPBF filter.
disapatching now (modulo) number of available cores.
1 parent e49777f commit a2f3554

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ext/sockets/sockets.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,13 +1973,23 @@ PHP_FUNCTION(socket_set_option)
19731973
static struct sock_filter cbpf[8] = {0};
19741974
static struct sock_fprog bpfprog;
19751975

1976+
// TODO: might be a good enough approximation, more native api could be used potentially tough
1977+
long onln = sysconf(_SC_NPROCESSORS_ONLN);
1978+
1979+
if (onln == -1) {
1980+
php_error_docref(NULL, E_WARNING, "Online cores fetching failed");
1981+
RETURN_FALSE;
1982+
}
1983+
19761984
switch (k) {
19771985
case SKF_AD_CPU:
19781986
case SKF_AD_QUEUE:
19791987
cbpf[0].code = (BPF_LD|BPF_W|BPF_ABS);
19801988
cbpf[0].k = (uint32_t)(SKF_AD_OFF + k);
1981-
cbpf[1].code = (BPF_RET|BPF_A);
1982-
bpfprog.len = 2;
1989+
cbpf[1].code = (BPF_ALU | BPF_MOD);
1990+
cbpf[1].k = (uint32_t)(onln);
1991+
cbpf[2].code = (BPF_RET|BPF_A);
1992+
bpfprog.len = 3;
19831993
break;
19841994
default:
19851995
php_error_docref(NULL, E_WARNING, "Unsupported CBPF filter");

0 commit comments

Comments
 (0)