Skip to content

Socket.prototype.onread fired incorrectly #76

@cookiengineer

Description

@cookiengineer

Currently, if you start a server, it will always receive data via onread() because of JSSocket.h#L79.

This is a bit confusing, is this a wanted API? It will eventually lead to users having to create a cache for both their wrappers and the nidium sockets, just to answer to the corresponding socket correctly.

Example 1 (current behaviour)

let server = new Socket('127.0.0.1', 1234).listen('tcp');

server.onaccept = socket => console.log(socket.ip, socket.port);
server.onread = (socket, data) => console.log('server.onread always fired', data);

Example 2 (expected behaviour)

let server = new Socket('127.0.0.1', 1234).listen('tcp');

server.onaccept = function(socket) {

    socket.onread = function(data) {
        // XXX: Never actually fired
        console.log('this is a much better API, per-client onread', data);
    };

};

server.onread = (socket, data) => console.log('server.onread always fired', data);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions