Skip to content

Commit a20894d

Browse files
committed
[RFC?] Add curl websocket bindings
This adds bindings to Curl's websocket support that was added in Curl 7.86.0. Instead of just pass-through C bindings, the API added here is a little more high-level from a type-safety perspective. I.e. this introduces an enum CurlWsMessageType and a DTO class CurlWsFrame for nicer and safer API handling. Still WIP.
1 parent d80682e commit a20894d

File tree

6 files changed

+374
-1
lines changed

6 files changed

+374
-1
lines changed

Zend/Optimizer/zend_func_infos.h

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ static const func_info_t func_infos[] = {
4949
F1("curl_share_init_persistent", MAY_BE_OBJECT),
5050
F1("curl_strerror", MAY_BE_STRING|MAY_BE_NULL),
5151
F1("curl_version", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),
52+
#if LIBCURL_VERSION_NUM >= 0x075600 /* Available since 7.86.0 */
53+
F1("curl_ws_meta", MAY_BE_OBJECT),
54+
F1("curl_ws_recv", MAY_BE_STRING|MAY_BE_FALSE),
55+
#endif
5256
F1("date", MAY_BE_STRING),
5357
F1("gmdate", MAY_BE_STRING),
5458
F1("strftime", MAY_BE_STRING|MAY_BE_FALSE),

ext/curl/curl.stub.php

+45
Original file line numberDiff line numberDiff line change
@@ -3634,6 +3634,16 @@
36343634
* @cvalue CURLWS_RAW_MODE
36353635
*/
36363636
const CURLWS_RAW_MODE = UNKNOWN;
3637+
/**
3638+
* @var int
3639+
* @cvalue CURLWS_CONT
3640+
*/
3641+
const CURLWS_CONT = UNKNOWN;
3642+
/**
3643+
* @var int
3644+
* @cvalue CURLWS_OFFSET
3645+
*/
3646+
const CURLWS_OFFSET = UNKNOWN;
36373647
#endif
36383648

36393649
#if LIBCURL_VERSION_NUM >= 0x075700 /* Available since 7.87.0 */
@@ -3696,6 +3706,28 @@ final class CurlSharePersistentHandle
36963706
public readonly array $options;
36973707
}
36983708

3709+
enum CurlWsMessageType
3710+
{
3711+
case Binary;
3712+
case Text;
3713+
case Close;
3714+
case Ping;
3715+
case Pong;
3716+
}
3717+
3718+
/**
3719+
* @strict-properties
3720+
* @not-serializable
3721+
*/
3722+
final readonly class CurlWsFrame
3723+
{
3724+
public CurlWsMessageType $type;
3725+
public bool $continued;
3726+
public int $offset;
3727+
public int $bytesLeft;
3728+
public int $length;
3729+
}
3730+
36993731
function curl_close(CurlHandle $handle): void {}
37003732

37013733
/** @refcount 1 */
@@ -3789,3 +3821,16 @@ function curl_strerror(int $error_code): ?string {}
37893821
* @refcount 1
37903822
*/
37913823
function curl_version(): array|false {}
3824+
3825+
#if LIBCURL_VERSION_NUM >= 0x075600 /* Available since 7.86.0 */
3826+
/** @refcount 1 */
3827+
function curl_ws_meta(CurlHandle $handle): CurlWsFrame {}
3828+
3829+
/**
3830+
* @param CurlWsFrame $meta
3831+
* @refcount 1
3832+
*/
3833+
function curl_ws_recv(CurlHandle $handle, int $length, &$meta = null): string|false {}
3834+
3835+
function curl_ws_send(CurlHandle $handle, string $buffer, CurlWsMessageType $type = CurlWsMessageType::Text, int $frag_size = 0, int $flags = 0): int {}
3836+
#endif

ext/curl/curl_arginfo.h

+93-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)