Documentation

ResourceSocket
in package
implements Socket, ResourceStream, IteratorAggregate uses ForbidCloning, ForbidSerialization, ReadableStreamIteratorAggregate

FinalYes
Tags
implements

Table of Contents

Interfaces

Socket
A `ReadableStream` allows reading byte streams in chunks.
ResourceStream
IteratorAggregate

Constants

DEFAULT_CHUNK_SIZE  = \Amp\ByteStream\ReadableResourceStream::DEFAULT_CHUNK_SIZE

Properties

$localAddress  : SocketAddress
$reader  : ReadableResourceStream
$remoteAddress  : SocketAddress
$streamContext  : array<string|int, mixed>|null
$tlsContext  : ClientTlsContext|null
$tlsInfo  : TlsInfo|null
$tlsState  : TlsState
$writer  : WritableResourceStream

Methods

__serialize()  : never
__unserialize()  : never
close()  : void
Closes the resource, marking it as unusable.
end()  : void
Marks the stream as no longer writable.
fromClientSocket()  : self
fromServerSocket()  : self
getIterator()  : Traversable<int, string>
getLocalAddress()  : SocketAddress
getRemoteAddress()  : SocketAddress
getResource()  : resource|object|null
getTlsInfo()  : TlsInfo|null
getTlsState()  : TlsState
isClosed()  : bool
Returns whether this resource has been closed.
isReadable()  : bool
isTlsConfigurationAvailable()  : bool
isWritable()  : bool
onClose()  : void
Registers a callback that is invoked when this resource is closed.
read()  : string|null
Reads data from the stream.
reference()  : void
References the underlying watcher, so the loop keeps running in case there's an active stream operation.
setChunkSize()  : void
setupTls()  : void
shutdownTls()  : void
unreference()  : void
Unreferences the underlying watcher, so the loop doesn't keep running even if there are active stream operations.
write()  : void
Writes data to the stream.
__clone()  : mixed
__construct()  : mixed
getStreamContext()  : array<string|int, mixed>|null

Constants

DEFAULT_CHUNK_SIZE

public mixed DEFAULT_CHUNK_SIZE = \Amp\ByteStream\ReadableResourceStream::DEFAULT_CHUNK_SIZE

Properties

$streamContext

private array<string|int, mixed>|null $streamContext = null

Methods

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : never
Parameters
$data : array<string|int, mixed>
Return values
never

close()

Closes the resource, marking it as unusable.

public close() : void

Whether pending operations are aborted or not is implementation dependent.

end()

Marks the stream as no longer writable.

public end() : void

Note that this is not the same as forcefully closing the stream. This method waits for all pending writes to complete before closing the stream. Socket streams implementing this interface should only close the writable side of the stream.

fromClientSocket()

public static fromClientSocket(resource $resource[, ClientTlsContext|null $tlsContext = null ][, positive-int $chunkSize = self::DEFAULT_CHUNK_SIZE ]) : self
Parameters
$resource : resource

Stream resource.

$tlsContext : ClientTlsContext|null = null
$chunkSize : positive-int = self::DEFAULT_CHUNK_SIZE

Read and write chunk size.

Return values
self

fromServerSocket()

public static fromServerSocket(resource $resource[, positive-int $chunkSize = self::DEFAULT_CHUNK_SIZE ]) : self
Parameters
$resource : resource

Stream resource.

$chunkSize : positive-int = self::DEFAULT_CHUNK_SIZE

Read and write chunk size.

Return values
self

getResource()

public getResource() : resource|object|null
Return values
resource|object|null

getTlsInfo()

public getTlsInfo() : TlsInfo|null
Return values
TlsInfo|null

The TLS (crypto) context info if TLS is enabled on the socket or null otherwise.

isClosed()

Returns whether this resource has been closed.

public isClosed() : bool
Return values
bool

true if closed, otherwise false.

isReadable()

public isReadable() : bool
Return values
bool

A stream may become unreadable if the underlying source is closed or lost.

isTlsConfigurationAvailable()

public isTlsConfigurationAvailable() : bool
Return values
bool

isWritable()

public isWritable() : bool
Return values
bool

A stream may no longer be writable if it is closed or ended using end().

onClose()

Registers a callback that is invoked when this resource is closed.

public onClose(Closure $onClose) : void
Parameters
$onClose : Closure

read()

Reads data from the stream.

public read([Cancellation|null $cancellation = null ][, int|null $limit = null ]) : string|null
Parameters
$cancellation : Cancellation|null = null

Cancel the read operation. The state in which the stream will be after a cancelled operation is implementation dependent.

$limit : int|null = null

Read at most $limit bytes from the socket. null uses an implementation defined limit.

Return values
string|null

Returns a string when new data is available or null if the stream has closed.

reference()

References the underlying watcher, so the loop keeps running in case there's an active stream operation.

public reference() : void

setChunkSize()

public setChunkSize(positive-int $chunkSize) : void
Parameters
$chunkSize : positive-int

New default chunk size for reading and writing.

setupTls()

public setupTls([Cancellation|null $cancellation = null ]) : void
Parameters
$cancellation : Cancellation|null = null
Return values
void

Returns when TLS is successfully set up on the socket.

shutdownTls()

public shutdownTls([Cancellation|null $cancellation = null ]) : void
Parameters
$cancellation : Cancellation|null = null
Return values
void

Returns when TLS is successfully shutdown.

unreference()

Unreferences the underlying watcher, so the loop doesn't keep running even if there are active stream operations.

public unreference() : void

write()

Writes data to the stream.

public write(string $bytes) : void
Parameters
$bytes : string

Bytes to write.

__construct()

private __construct(resource $resource[, ClientTlsContext|null $tlsContext = null ][, positive-int $chunkSize = self::DEFAULT_CHUNK_SIZE ]) : mixed
Parameters
$resource : resource

Stream resource.

$tlsContext : ClientTlsContext|null = null
$chunkSize : positive-int = self::DEFAULT_CHUNK_SIZE

Read and write chunk size.

getStreamContext()

private getStreamContext() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

        
On this page

Search results