Skip to content

[Need help]how to call Request.prototype.read outside callback #178

Description

@horihiro

I found a commit message 'allow read to be called outside of callback' for modules/network/socket/lwip/modSocket.c.

It seems that the message means Request.prototype.read can be called outside of its callback.

But I got the following error message when I tried.
/PATH/TO/main.js (19) # Break: (host): cannot coerce undefined to object!

Could you please provide me an example for calling Request.prototype.read outside of request's callback if it can be?

The code and manifest I tried is following:

main.js

import {Request} from "http"
import SecureSocket from "securesocket";
import Timer from 'timer';

const request = new Request({
  host: 'translate.google.com',
  port: 443,
  method: 'GET',
  Socket: SecureSocket,
  secure: {protocolVersion: 0x303}

});
request.callback = function(message, value, etc) {
  trace(`${message}:${value||''}\n`);
};

Timer.repeat((id) => {
  if (request.state < 4) return;
  // call Request.prototype.read outsize of a callback of the request
  trace(`${request.read(String)}\n`);
}, 1);

manifest.json

{
  "include": [
    "$(MODDABLE)/examples/manifest_base.json",
    "$(MODDABLE)/examples/manifest_net.json",
    "$(MODDABLE)/modules/crypt/tls.json",
  ],
  "resources": {
    "*": [
      "$(MODULES)/crypt/data/ca23",
    ]
  },
  "modules": {
    "*": [
      "./main",
      "$(MODULES)/network/http/*",
    ]
  },
  "preload": [
    "http",
  ],
}

Best Regards,

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions