Skip to content

Commit fd811b2

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 ad65698 commit fd811b2

File tree

5 files changed

+365
-1
lines changed

5 files changed

+365
-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

+53
Original file line numberDiff line numberDiff line change
@@ -3657,6 +3657,16 @@
36573657
* @cvalue CURLWS_RAW_MODE
36583658
*/
36593659
const CURLWS_RAW_MODE = UNKNOWN;
3660+
/**
3661+
* @var int
3662+
* @cvalue CURLWS_CONT
3663+
*/
3664+
const CURLWS_CONT = UNKNOWN;
3665+
/**
3666+
* @var int
3667+
* @cvalue CURLWS_OFFSET
3668+
*/
3669+
const CURLWS_OFFSET = UNKNOWN;
36603670
#endif
36613671

36623672
#if LIBCURL_VERSION_NUM >= 0x075700 /* Available since 7.87.0 */
@@ -3686,6 +3696,14 @@
36863696
*/
36873697
const CURLOPT_SAFE_UPLOAD = UNKNOWN;
36883698

3699+
#if LIBCURL_VERSION_NUM >= 0x080e00 /* Available since 8.14.0 */
3700+
/**
3701+
* @var int
3702+
* @cvalue CURLWS_NOAUTOPONG
3703+
*/
3704+
const CURLWS_NOAUTOPONG = UNKNOWN;
3705+
#endif
3706+
36893707
/**
36903708
* @strict-properties
36913709
* @not-serializable
@@ -3719,6 +3737,28 @@ final class CurlSharePersistentHandle
37193737
public readonly array $options;
37203738
}
37213739

3740+
enum CurlWsMessageType
3741+
{
3742+
case Binary;
3743+
case Text;
3744+
case Close;
3745+
case Ping;
3746+
case Pong;
3747+
}
3748+
3749+
/**
3750+
* @strict-properties
3751+
* @not-serializable
3752+
*/
3753+
final readonly class CurlWsFrame
3754+
{
3755+
public CurlWsMessageType $type;
3756+
public bool $continued;
3757+
public int $offset;
3758+
public int $bytesLeft;
3759+
public int $length;
3760+
}
3761+
37223762
function curl_close(CurlHandle $handle): void {}
37233763

37243764
/** @refcount 1 */
@@ -3812,3 +3852,16 @@ function curl_strerror(int $error_code): ?string {}
38123852
* @refcount 1
38133853
*/
38143854
function curl_version(): array|false {}
3855+
3856+
#if LIBCURL_VERSION_NUM >= 0x075600 /* Available since 7.86.0 */
3857+
/** @refcount 1 */
3858+
function curl_ws_meta(CurlHandle $handle): CurlWsFrame {}
3859+
3860+
/**
3861+
* @param CurlWsFrame $meta
3862+
* @refcount 1
3863+
*/
3864+
function curl_ws_recv(CurlHandle $handle, int $length, &$meta = null): string|false {}
3865+
3866+
function curl_ws_send(CurlHandle $handle, string $buffer, CurlWsMessageType $type = CurlWsMessageType::Text, int $frag_size = 0, int $flags = 0): int {}
3867+
#endif

ext/curl/curl_arginfo.h

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

0 commit comments

Comments
 (0)