Socket timeout hardcoded

Seems to me that socket_connect method should have timeout as parameter instead of hard codded

/hal/src/photon/socket_hal.cpp
sock_result_t socket_connect(sock_handle_t sd, const sockaddr_t *addr, long addrlen)
{
    wiced_result_t result = WICED_INVALID_SOCKET;
    socket_t* socket = from_handle(sd);
    tcp_socket_t* tcp_socket = tcp(socket);
    if (tcp_socket) {
        result = wiced_tcp_bind(tcp_socket, WICED_ANY_PORT);
        if (result==WICED_SUCCESS) {
            // WICED callbacks are broken
            //wiced_tcp_register_callbacks(tcp(socket), socket_t::notify_connected, socket_t::notify_received, socket_t::notify_disconnected, (void*)socket);
            SOCKADDR_TO_PORT_AND_IPADDR(addr, addr_data, port, ip_addr);
==========> unsigned timeout = 5*1000; <====    5 SECONDS TIMEOUT
            result = wiced_tcp_connect(tcp_socket, &ip_addr, port, timeout);
            if (result==WICED_SUCCESS) {
                tcp_socket->connected();
            } else {
              // Work around WICED bug that doesn't set connection handler to NULL after deleting
              // it, leading to deleting the same memory twice and a crash
              // WICED/network/LwIP/WICED/tcpip.c:920
              tcp_socket->conn_handler = NULL;
            }
        }
    }
    return as_sock_result(result);
}

Im getting problems with photon, i could not create my own socket class or even a new class extended from TCPClient to overload this, compiler cant include wiced.h

Anyone know how make this socket non-blocking and also change this timeout?

Ping @BDub, @mdma

What problems is the fixed timeout causing you?

Nothing seems.

Im not sure where problem is.

I through was this timeout frezing program since photon stop answer ping.

Im using this code:

SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

#include "I2Cdev.h"
#include "ITG3200.h"
#include "ADXL345.h"
#include "HMC5843.h"
ITG3200 gyroDev;
ADXL345 accelDev;
HMC5843 magDev;
char wifiName[ ] = "XXXX";
char wifiPassword[ ] = "XXXX";
IPAddress myAddress(192, 168, 0, 99);
IPAddress netmask(255, 255, 255, 0);
IPAddress gateway(192, 168, 0, 1);
IPAddress dns(192, 168, 0, 1);
TCPClient client;
byte server[] = {192, 168, 0, 5};
int port = 8087;
#define STATUS_LED_PIN D7
String buffer;
bool wifiConnected(bool reconnect, int limit) {
    if (! WiFi.ready()) {
        if (reconnect) {
            if (! WiFi.connecting()) {
                RGB.control(true);
                RGB.color(255, 255, 255);
                WiFi.setCredentials(wifiName, wifiPassword, WPA2, WLAN_CIPHER_AES);
                WiFi.setStaticIP(myAddress, netmask, gateway, dns);
                WiFi.useStaticIP();
                WiFi.connect(WIFI_CONNECT_SKIP_LISTEN);
                RGB.control(false);
            }
            Particle.process();
            if (limit > 0) {
                if (waitFor(WiFi.ready, limit)) {
                    Particle.process();
                    return true;
                }
            } else if (WiFi.ready()) {
                return true;
            }
        }
        Particle.process();
        return false;
    }
    Particle.process();
    return true;
}
bool clientIsConnected() {
    Particle.process();
    if (wifiConnected(false, 0)) {
        Particle.process();
        if (client.connected()) {
            return true;
        }
    }
    Particle.process();
    return false;
}
void setup() {
    WiFi.on();
    if (wifiConnected(true, 10000)) {
        Particle.disconnect();        
        Serial.begin(9600);        
        pinMode(STATUS_LED_PIN, OUTPUT);
        digitalWrite(STATUS_LED_PIN, HIGH);        
        buffer = "";       
        while(! Serial.available()) {
            Particle.process();
            delay(500);
        }        
        delay(1000);
        digitalWrite(STATUS_LED_PIN, LOW);
    } else {
        RGB.control(true);
        RGB.color(255, 255, 0);
        RGB.brightness(255);
        delay(5000);
        RGB.control(false);        
        System.reset();
    }
}

void loop() {
    Serial.println("LOOP");
    if (wifiConnected(false, 0)) {
        Serial.println("WIFI ON");
        Serial.println(System.freeMemory());
        if (! clientIsConnected()) {
            RGB.control(true);
            RGB.color(0, 0, 255);                        
            buffer.remove(0);
            buffer = "";
            digitalWrite(STATUS_LED_PIN, LOW);
            client.flush();
            client.connect(server, port);            
            RGB.color(255, 255, 255);
            if (client.connected()) {
                RGB.color(255, 0, 0);    
                delay(1000);
            }
            delay(1000);            
            RGB.color(111, 111, 111);            
            delay(1000);            
            RGB.control(false);            
        } else {           
            Serial.print("Client connected ");
            Serial.println(client.available());                
            if (clientIsConnected()) {
                client.println("Initializing I2C devices...");
            }            
            RGB.control(true);
            RGB.color(255, 255, 255);            
            if (clientIsConnected()) {
                RGB.control(true);
                RGB.color(255, 255, 0);                
                client.println("Testing device connections...");
            }            
            RGB.control(false);
            bool retry = false;
            do {
                Serial.println("while");                
                Serial.print("Ready: ");
                Serial.println(WiFi.ready());
                Serial.print("Connecting: ");
                Serial.println(WiFi.connecting());                                
                Serial.print("Ping: ");
                Serial.println(WiFi.ping(dns));                
                digitalWrite(STATUS_LED_PIN, HIGH);
                Wire.begin();
                gyroDev.initialize();
                if (! gyroDev.testConnection()) {
                    retry = true;
                    Wire.end();
                    if (clientIsConnected()) {
                        client.println("ITG3200 connection failed, retrying...");
                    }
                    delay(1000);
                } else {
                    if (clientIsConnected()) {
                        client.println("ITG3200 connection successful");
                    }
                }                
                if (! retry) {
                    accelDev.initialize();
                    if (! accelDev.testConnection()) {
                        retry = true;
                        Wire.end();
                        if (clientIsConnected()) {
                            client.println("ADXL345 connection failed, retrying...");
                        }
                        delay(1000);
                    } else {
                        if (clientIsConnected()) {
                            client.println("ADXL345 connection successful");
                        }
                    }            
                }                
                if (! retry) {
                    magDev.initialize();
                    magDev.setMode(HMC5843_MODE_CONTINUOUS);
                    magDev.setDataRate(HMC5843_RATE_50);
                    if (! magDev.testConnection()) {
                        retry = true;
                        Wire.end();
                        if (clientIsConnected()) {
                            client.println("HMC5843 connection failed, retrying...");
                        }
                        delay(1000);
                    } else {
                        if (clientIsConnected()) {
                            client.println("HMC5843 connection successful");
                        }
                    }               
                }
                //Works with this                
                /*while (client.available() > 0) {
                    char a = client.read();
                } */              
                //Freeze photon after some ~5 seconds, photon stop answer pings, and server reports tcpclient connection dropped
                client.flush();
            } while (retry && clientIsConnected());           
            digitalWrite(STATUS_LED_PIN, LOW);
        }
    } else {
            RGB.control(true);
            RGB.color(255, 255, 0);
            RGB.brightness(255);
        digitalWrite(STATUS_LED_PIN, LOW);
        delay(5000);
        RGB.control(false);        
        System.reset();
    }
}

Nodejs server code running at pc for test

var net = require('net');
var server = net.createServer(function(socket) {
     console.log('con');	
     setInterval(function() {
         socket.write('#D01!');
    }, 1000);	
    socket.on('data', function(data) {        
        console.log('DATA ' + socket.remoteAddress + ':' +  socket.remotePort + ': ' + data);        
    });
    socket.on('close', function(data) {
        console.log('CLOSED: ' + socket.remoteAddress +':'+ socket.remotePort);
    });	
});

server.listen(8087, '192.168.0.5');

Not sure what causing photon to stop answering pings, seems wifi connection went down, but works if I use client.read() to empty tcp client buffer. I though timeout was making this