mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
fixing recently regressed client socket code
This commit is contained in:
parent
e175945397
commit
af8879c72c
@ -369,7 +369,7 @@ JsVar *jswrap_net_createServer(JsVar *callback) {
|
||||
"generate_full" : "jswrap_net_connect(options, callback, ST_NORMAL)",
|
||||
"params" : [
|
||||
["options","JsVar","An object containing host,port fields"],
|
||||
["callback","JsVar","A function(res) that will be called when a connection is made. You can then call `res.on('data', function(data) { ... })` and `res.on('close', function() { ... })` to deal with the response."]
|
||||
["callback","JsVar","A `function(socket)` that will be called when a connection is made. You can then call `res.on('data', function(data) { ... })` and `res.on('close', function() { ... })` to deal with the response."]
|
||||
],
|
||||
"return" : ["JsVar","Returns a new net.Socket object"],
|
||||
"return_object" : "Socket"
|
||||
@ -397,17 +397,11 @@ JsVar *jswrap_net_connect(JsVar *options, JsVar *callback, SocketType socketType
|
||||
#endif
|
||||
|
||||
// Make sure we have a function as callback, or nothing (which is OK too)
|
||||
JsVar *skippedCallback = jsvSkipName(callback);
|
||||
if (!jsvIsUndefined(skippedCallback)) {
|
||||
if (!jsvIsFunction(skippedCallback)) {
|
||||
jsError("Expecting Callback Function but got %t", skippedCallback);
|
||||
jsvUnLock(skippedCallback);
|
||||
return 0;
|
||||
}
|
||||
jsvUnLock(skippedCallback);
|
||||
} else {
|
||||
callback = NULL;
|
||||
if (!jsvIsUndefined(callback) && !jsvIsFunction(callback)) {
|
||||
jsError("Expecting Callback Function but got %t", callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
JsVar *rq = clientRequestNew(socketType, options, callback);
|
||||
if (unlockOptions) jsvUnLock(options);
|
||||
|
||||
|
||||
@ -468,7 +468,7 @@ bool socketClientConnectionsIdle(JsNetwork *net) {
|
||||
if (error == 0) num = socketSendData(net, connection, sckt, &sendData);
|
||||
//if (num != 0) printf("send returned %d\r\n", num);
|
||||
if (num > 0 && !alreadyConnected && !isHttp) { // whoa, we sent something, must be connected!
|
||||
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_CONNECT, NULL, 0);
|
||||
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_CONNECT, &connection, 1);
|
||||
jsvObjectSetChildAndUnLock(connection, HTTP_NAME_CONNECTED, jsvNewFromBool(true));
|
||||
alreadyConnected = true;
|
||||
}
|
||||
@ -496,7 +496,7 @@ bool socketClientConnectionsIdle(JsNetwork *net) {
|
||||
} else {
|
||||
// did we just get connected?
|
||||
if (!alreadyConnected && !isHttp) {
|
||||
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_CONNECT, NULL, 0);
|
||||
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_CONNECT, &connection, 1);
|
||||
jsvObjectSetChildAndUnLock(connection, HTTP_NAME_CONNECTED, jsvNewFromBool(true));
|
||||
alreadyConnected = true;
|
||||
// if we do not have any data to send, issue a drain event
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user