Skip to content

Socket onread described on wrong function #53792

Closed
@lights0123

Description

@lights0123

Affected URL(s)

https://nodejs.org/api/net.html#new-netsocketoptions

Description of the problem

socket.connect() is described as accepting the following option:

  • onread {Object} If specified, incoming data is stored in a single buffer
    and passed to the supplied callback when data arrives on the socket.
    This will cause the streaming functionality to not provide any data.
    The socket will emit events like 'error', 'end', and 'close'
    as usual. Methods like pause() and resume() will also behave as
    expected.
    • buffer {Buffer|Uint8Array|Function} Either a reusable chunk of memory to
      use for storing incoming data or a function that returns such.
    • callback {Function} This function is called for every chunk of incoming
      data. Two arguments are passed to it: the number of bytes written to
      buffer and a reference to buffer. Return false from this function to
      implicitly pause() the socket. This function will be executed in the
      global context.

However, this is not correct, and is actually accepted only in the Socket() constructor:

node/lib/net.js

Line 454 in b4e8f1b

if (onread !== null && typeof onread === 'object' &&

The example given using net.connect() is still correct because the options "Will be passed to both the new net.Socket([options]) call and the socket.connect(options[, connectListener]) method."

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions